From 4b71f0323afbd4ae436d9052b35ff231cd215393 Mon Sep 17 00:00:00 2001 From: Derky Date: Sat, 27 Sep 2025 17:27:36 +0200 Subject: [PATCH 1/3] [ticket/17554] Mock Extensions Catalog cache in tests PHPBB-17554 --- tests/functional/extension_acp_test.php | 22 +++++++++++- .../fixtures/files/extensions_catalog.json | 34 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/functional/fixtures/files/extensions_catalog.json diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 8f76a91b95..94106e0872 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -79,6 +79,18 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $this->add_lang(['acp/common', 'acp/extensions']); } + /** + * Mocks the extensions catalog cache used in phpBB/phpbb/composer/manager.php + * with a predefined fixture so no external calls are made. + */ + protected function mock_extensions_catalog_cache():void { + $fixture_file = __DIR__ . '/fixtures/files/extensions_catalog.json'; + $package_type = 'phpbb-extension'; + + $available_extensions = json_decode(file_get_contents($fixture_file), true); + $this->cache->put('_composer_' . $package_type . '_available', $available_extensions, 24*60*60); + } + public function test_list() { $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); @@ -247,6 +259,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case public function test_extensions_catalog() { // Access extensions catalog main page + $this->mock_extensions_catalog_cache(); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&sid=' . $this->sid); $this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); @@ -260,6 +273,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text()); // Revisit extensions catalog main page after configuration change + $this->mock_extensions_catalog_cache(); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&sid=' . $this->sid); $this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); @@ -270,12 +284,17 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case public function test_extensions_catalog_installing_extension() { // Let's check the overview, multiple packages should be listed + $this->mock_extensions_catalog_cache(); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&sid=' . $this->sid); $this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); $this->assertGreaterThan(1, $crawler->filter('tr')->count()); $this->assertGreaterThan(1, $crawler->selectLink($this->lang('INSTALL'))->count()); - $pages = (int) $crawler->filter('div.pagination li:nth-last-child(2) a')->first()->text(); + $pages = 1; + $pagination = $crawler->filter('div.pagination li:nth-last-child(2) a'); + if ($pagination->count() > 0) { + $pages = (int) $pagination->first()->text(); + } // Get Install links for both extensions $extension_filter = function($crawler, $extension_name, &$install_link) @@ -297,6 +316,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case { if ($i != 0) { + $this->mock_extensions_catalog_cache(); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&start=' . $i * 20 . '&mode=catalog&sid=' . $this->sid); } diff --git a/tests/functional/fixtures/files/extensions_catalog.json b/tests/functional/fixtures/files/extensions_catalog.json new file mode 100644 index 0000000000..f2683e7709 --- /dev/null +++ b/tests/functional/fixtures/files/extensions_catalog.json @@ -0,0 +1,34 @@ +[ + { + "name": "extension1\/vendor", + "display_name": "Extension 1", + "composer_name": "extension1\/vendor", + "version": "1.0.0", + "description": "Dummy extension 1 for testing.", + "url": "https:\/\/example.com\/extension1", + "authors": [ + { + "name": "Author One", + "email": "author1@example.com", + "homepage": "https:\/\/author1.example.com", + "role": "Developer" + } + ] + }, + { + "name": "phpbb\/viglink", + "display_name": "VigLink", + "composer_name": "phpbb\/viglink", + "version": "dev-master", + "description": "The VigLink extension for phpBB makes it possible to earn revenue, without any change to the user experience, when users post and follow links to commercial sites.", + "url": "https:\/\/www.phpbb.com\/", + "authors": [ + { + "name": "Author Two", + "email": "author2@example.com", + "homepage": "https:\/\/author2.example.com", + "role": "Developer" + } + ] + } +] From 0eab040b971047770af7d9d98c56a6ae65fc1b21 Mon Sep 17 00:00:00 2001 From: Derky Date: Sun, 28 Sep 2025 13:28:18 +0200 Subject: [PATCH 2/3] [ticket/17554] Prevent opening Extension Catalog in test_all_acp_module_links PHPBB-17554 --- tests/functional/acp_test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/functional/acp_test.php b/tests/functional/acp_test.php index bf37fc7203..d390d3158b 100644 --- a/tests/functional/acp_test.php +++ b/tests/functional/acp_test.php @@ -58,6 +58,12 @@ class phpbb_functional_acp_test extends phpbb_functional_test_case // Browse all ACP submodules' modes foreach ($acp_submodules as $acp_submodule) { + // Don't click the ACP Extensions Catalog to prevent calling an external HTTP service in the test suite + if ($acp_submodule->getNode()->textContent === $this->lang('ACP_EXTENSIONS_CATALOG')) + { + continue; + } + self::$client->click($acp_submodule); self::assert_response_html(); } From 8e6096fb14e8f5908281d19b780a6840dae03bdb Mon Sep 17 00:00:00 2001 From: Derky Date: Sun, 5 Oct 2025 11:40:41 +0200 Subject: [PATCH 3/3] [ticket/17554] Remove escaping in json PHPBB-17554 --- .../fixtures/files/extensions_catalog.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/functional/fixtures/files/extensions_catalog.json b/tests/functional/fixtures/files/extensions_catalog.json index f2683e7709..1ab64d98df 100644 --- a/tests/functional/fixtures/files/extensions_catalog.json +++ b/tests/functional/fixtures/files/extensions_catalog.json @@ -1,32 +1,32 @@ [ { - "name": "extension1\/vendor", + "name": "extension1/vendor", "display_name": "Extension 1", - "composer_name": "extension1\/vendor", + "composer_name": "extension1/vendor", "version": "1.0.0", "description": "Dummy extension 1 for testing.", - "url": "https:\/\/example.com\/extension1", + "url": "https://example.com/extension1", "authors": [ { "name": "Author One", "email": "author1@example.com", - "homepage": "https:\/\/author1.example.com", + "homepage": "https://author1.example.com", "role": "Developer" } ] }, { - "name": "phpbb\/viglink", + "name": "phpbb/viglink", "display_name": "VigLink", - "composer_name": "phpbb\/viglink", + "composer_name": "phpbb/viglink", "version": "dev-master", "description": "The VigLink extension for phpBB makes it possible to earn revenue, without any change to the user experience, when users post and follow links to commercial sites.", - "url": "https:\/\/www.phpbb.com\/", + "url": "https://www.phpbb.com/", "authors": [ { "name": "Author Two", "email": "author2@example.com", - "homepage": "https:\/\/author2.example.com", + "homepage": "https://author2.example.com", "role": "Developer" } ]