1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-10-12 07:24:31 +02:00

[ticket/17554] Mock Extensions Catalog cache in tests

PHPBB-17554
This commit is contained in:
Derky
2025-09-27 17:27:36 +02:00
parent ec681adb77
commit 4b71f0323a
2 changed files with 55 additions and 1 deletions

View File

@@ -79,6 +79,18 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case
$this->add_lang(['acp/common', 'acp/extensions']); $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() public function test_list()
{ {
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $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() public function test_extensions_catalog()
{ {
// Access extensions catalog main page // 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); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&sid=' . $this->sid);
$this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); $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()); $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text());
// Revisit extensions catalog main page after configuration change // 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); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&sid=' . $this->sid);
$this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); $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() public function test_extensions_catalog_installing_extension()
{ {
// Let's check the overview, multiple packages should be listed // 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); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&sid=' . $this->sid);
$this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); $this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content());
$this->assertGreaterThan(1, $crawler->filter('tr')->count()); $this->assertGreaterThan(1, $crawler->filter('tr')->count());
$this->assertGreaterThan(1, $crawler->selectLink($this->lang('INSTALL'))->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 // Get Install links for both extensions
$extension_filter = function($crawler, $extension_name, &$install_link) $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) 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); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&start=' . $i * 20 . '&mode=catalog&sid=' . $this->sid);
} }

View File

@@ -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"
}
]
}
]