[ticket/16904] Adjust tests

PHPBB3-16904
This commit is contained in:
rxu 2021-11-07 18:11:37 +07:00
parent c6640a8b1e
commit 428828a93d
No known key found for this signature in database
GPG key ID: 14C89C9F50DA21E6
3 changed files with 47 additions and 44 deletions

View file

@ -18,11 +18,11 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
{ {
public function test_create_topics() public function test_create_topics()
{ {
$this->add_lang(['acp/common', 'common']); $this->add_lang(['acp/common', 'acp/forums', 'common']);
$this->login(); $this->login();
$this->admin_login(); $this->admin_login();
// Disable flood intervar to post >1 of topics // Disable flood interval to post >1 of topics
$crawler = self::request('GET', "adm/index.php?i=acp_board&mode=post&sid={$this->sid}"); $crawler = self::request('GET', "adm/index.php?i=acp_board&mode=post&sid={$this->sid}");
$form = $crawler->selectButton($this->lang('SUBMIT'))->form([ $form = $crawler->selectButton($this->lang('SUBMIT'))->form([
'config[flood_interval]' => 0, 'config[flood_interval]' => 0,
@ -30,6 +30,20 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
$crawler = self::submit($form); $crawler = self::submit($form);
$this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); $this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
// Create a forum to move topics around
$forum_name = 'MCP Test #1';
$crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
$form = $crawler->selectButton($this->lang('CREATE_FORUM'))->form([
'forum_name' => $forum_name,
]);
$crawler = self::submit($form);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form([
'forum_parent_id' => 1,
'forum_perm_from' => 2,
]);
$crawler = self::submit($form);
$this->assertContainsLang('FORUM_CREATED', $crawler->text());
// Create topics to test with // Create topics to test with
$post = []; $post = [];
$post[] = $this->create_topic(2, 'Test Topic 3', 'Testing forum moderation actions from MCP/View forum page.'); $post[] = $this->create_topic(2, 'Test Topic 3', 'Testing forum moderation actions from MCP/View forum page.');
@ -54,8 +68,7 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
// Browse MCP main page from forum view (gives &f=2) // Browse MCP main page from forum view (gives &f=2)
$crawler = self::request('GET', "viewforum.php?f=2&sid={$this->sid}"); $crawler = self::request('GET', "viewforum.php?f=2&sid={$this->sid}");
$mcp_link = substr_replace($crawler->selectLink($this->lang('MCP_SHORT'))->attr('href'), '', 0, 2); // Remove leading ./ $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link());
$crawler = self::request('GET', $mcp_link);
// Test forum moderation page has a list of topics to select // Test forum moderation page has a list of topics to select
$this->assertGreaterThanOrEqual(3, $crawler->filter('input[type=checkbox]')->count()); $this->assertGreaterThanOrEqual(3, $crawler->filter('input[type=checkbox]')->count());
@ -95,8 +108,7 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
$this->login(); $this->login();
$crawler = self::request('GET', "viewforum.php?f=2&sid={$this->sid}"); $crawler = self::request('GET', "viewforum.php?f=2&sid={$this->sid}");
$mcp_link = substr_replace($crawler->selectLink($this->lang('MCP_SHORT'))->attr('href'), '', 0, 2); // Remove leading ./ $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link());
$crawler = self::request('GET', $mcp_link);
// Test actions // Test actions
$form = $crawler->selectButton($this->lang('SUBMIT'))->form()->disableValidation()->setValues([ $form = $crawler->selectButton($this->lang('SUBMIT'))->form()->disableValidation()->setValues([
@ -110,22 +122,28 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
if ($action == 'merge_topics') if ($action == 'merge_topics')
{ {
// Merge topic_id_1 into topic_id_2 // Merge topic_id_1 into topic_id_2
$select_for_merge_link = substr_replace($crawler->filter('.row a')->reduce( $select_for_merge_link = $crawler->selectLink($this->lang('SELECT_MERGE'))->reduce(
function ($node, $i) use ($topic_id_2) function ($node, $i) use ($topic_id_2)
{ {
return (bool) strpos($node->attr('href'), "to_topic_id=$topic_id_2"); return (bool) strpos($node->attr('href'), "to_topic_id=$topic_id_2");
} }
)->attr('href'), '', 0, 2); // Remove leading ./ )->link();
$crawler = self::request('GET', $select_for_merge_link); $crawler = self::$client->click($select_for_merge_link);
} }
$form = $crawler->selectButton($this->lang('YES'))->form(); $form = $crawler->selectButton($this->lang('YES'))->form();
if (in_array($action, ['fork', 'move'])) if (in_array($action, ['fork', 'move']))
{ {
// Fork or move the topic to the forum id=3 'Download #1' // Fork or move the topic to the 'MCP Test #1'
$form->setValues(['to_forum_id' => 3]); $forum_id = $crawler->filter('select > option')->reduce(
function ($node, $i)
{
return (bool) strpos($node->text(), 'MCP Test #1');
}
)->attr('value');
$form['to_forum_id']->select($forum_id);
} }
$crawler = self::submit($form); $crawler = self::submit($form);
@ -142,10 +160,10 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
$this->add_lang(['common', 'mcp']); $this->add_lang(['common', 'mcp']);
$this->login(); $this->login();
// Get to the forum id=3 'Download #1' where the topic has been moved to in previous test // Get to the forum 'MCP Test #1' where the topic has been moved to in previous test
$crawler = self::request('GET', "viewforum.php?f=3&sid={$this->sid}"); $crawler = self::request('GET', "index.php?sid={$this->sid}");
$mcp_link = substr_replace($crawler->selectLink($this->lang('MCP_SHORT'))->attr('href'), '', 0, 2); // Remove leading ./ $crawler = self::$client->click($crawler->selectLink('MCP Test #1')->link());
$crawler = self::request('GET', $mcp_link); $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link());
// Get topic ids to delete (forked and moved topics in the previous test) // Get topic ids to delete (forked and moved topics in the previous test)
$topic_link_1 = $crawler->selectLink('Test Topic 3')->attr('href'); $topic_link_1 = $crawler->selectLink('Test Topic 3')->attr('href');
@ -214,8 +232,7 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
$this->login(); $this->login();
$crawler = self::request('GET', "viewtopic.php?t={$post[0]['topic_id']}&sid={$this->sid}"); $crawler = self::request('GET', "viewtopic.php?t={$post[0]['topic_id']}&sid={$this->sid}");
$mcp_link = substr_replace($crawler->selectLink($this->lang('MCP_SHORT'))->attr('href'), '', 0, 2); // Remove leading ./ $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link());
$crawler = self::request('GET', $mcp_link);
$this->assertLessThanOrEqual(count($post), $crawler->filter('input[type=checkbox]')->count()); $this->assertLessThanOrEqual(count($post), $crawler->filter('input[type=checkbox]')->count());
// Test actions // Test actions
@ -264,22 +281,22 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
{ {
// Merge posts into '[Split] Topic 1' // Merge posts into '[Split] Topic 1'
// Get topics list to select from // Get topics list to select from
$select_topic = substr_replace($crawler->selectLink($this->lang('SELECT_TOPIC'))->attr('href'), '', 0, 2); // Remove leading ./ $crawler = self::$client->click($crawler->selectLink($this->lang('SELECT_TOPIC'))->link());
$crawler = self::request('GET', $select_topic);
// Get '[Split] Topic 1' topic_id // Get '[Split] Topic 1' topic_id
$to_topic_link = $crawler->selectLink('[Split] Topic 1')->attr('href'); $to_topic_link = $crawler->selectLink('[Split] Topic 1')->attr('href');
$to_topic_id = (int) $this->get_parameter_from_link($to_topic_link, 't'); $to_topic_id = (int) $this->get_parameter_from_link($to_topic_link, 't');
// Select '[Split] Topic 1' // Select '[Split] Topic 1'
$select_for_merge_link = substr_replace($crawler->filter('.row a')->reduce( $select_for_merge_link = $crawler->selectLink($this->lang('SELECT_MERGE'))->reduce(
function ($node, $i) use ($to_topic_id) function ($node, $i) use ($to_topic_id)
{ {
return (bool) strpos($node->attr('href'), "to_topic_id=$to_topic_id"); return (bool) strpos($node->attr('href'), "to_topic_id=$to_topic_id");
} }
)->attr('href'), '', 0, 2); // Remove leading ./ )->link();
$crawler = self::$client->click($select_for_merge_link);
$crawler = self::request('GET', $select_for_merge_link);
$this->assertEquals($to_topic_id, (int) $crawler->filter('#to_topic_id')->attr('value')); $this->assertEquals($to_topic_id, (int) $crawler->filter('#to_topic_id')->attr('value'));
// Reselect post ids to move // Reselect post ids to move

View file

@ -46,7 +46,7 @@ class phpbb_functional_mcp_quickmod_tools_test extends phpbb_functional_test_cas
public function test_move_post_to_topic($crawler) public function test_move_post_to_topic($crawler)
{ {
$this->login(); $this->login();
$this->add_lang('common'); $this->add_lang(['common', 'mcp']);
// Select the post in MCP // Select the post in MCP
$form = $crawler->selectButton($this->lang('SUBMIT'))->form(array( $form = $crawler->selectButton($this->lang('SUBMIT'))->form(array(
@ -54,22 +54,10 @@ class phpbb_functional_mcp_quickmod_tools_test extends phpbb_functional_test_cas
)); ));
$form['post_id_list'][0]->tick(); $form['post_id_list'][0]->tick();
$crawler = self::submit($form); $crawler = self::submit($form);
$this->assertStringContainsString($this->lang('MERGE_POSTS'), $crawler->filter('html')->text()); $this->assertStringContainsString($this->lang('MERGE_POSTS_CONFIRM'), $crawler->filter('html')->text());
return $crawler; $form = $crawler->selectButton($this->lang('YES'))->form();
}
/**
* @depends test_move_post_to_topic
*/
public function test_confirm_result($crawler)
{
$this->login();
$this->add_lang('mcp');
$form = $crawler->selectButton('Yes')->form();
$crawler = self::submit($form); $crawler = self::submit($form);
$this->assertStringContainsString($this->lang('POSTS_MERGED_SUCCESS'), $crawler->text()); $this->assertStringContainsString($this->lang('POSTS_MERGED_SUCCESS'), $crawler->text());
return $crawler;
} }
} }

View file

@ -23,14 +23,13 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case
// Browse MCP main page // Browse MCP main page
$crawler = self::request('GET', 'index.php'); $crawler = self::request('GET', 'index.php');
$mcp_link = substr_replace($crawler->selectLink($this->lang('MCP_SHORT'))->attr('href'), '', 0, 2); // Remove leading ./ $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link());
$crawler = self::request('GET', $mcp_link);
// Get all MCP module URLs array // Get all MCP module URLs array
$mcp_modules = $crawler->filter('.tabs a')->each( $mcp_modules = $crawler->filter('.tabs a')->each(
function ($node, $i) function ($node, $i)
{ {
return substr_replace($node->attr('href'), '', 0, 2); // Remove leading ./ return $node->link();
} }
); );
@ -38,20 +37,19 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case
$mcp_submodules = []; $mcp_submodules = [];
foreach ($mcp_modules as $module) foreach ($mcp_modules as $module)
{ {
$crawler = self::request('GET', $module); $crawler = self::$client->click($module);
$mcp_submodules = array_merge($mcp_submodules, $crawler->filter('.cp-menu a')->each( $mcp_submodules = array_merge($mcp_submodules, $crawler->filter('.cp-menu a')->each(
function ($node, $i) function ($node, $i)
{ {
return substr_replace($node->attr('href'), '', 0, 2); // Remove leading ./ return $node->link();
} }
)); ));
} }
// Browse all MCP submodules' modes // Browse all MCP submodules' modes
$mcp_submodule_modes = [];
foreach ($mcp_submodules as $mcp_submodule) foreach ($mcp_submodules as $mcp_submodule)
{ {
$crawler = self::request('GET', $mcp_submodule); self::$client->click($mcp_submodule);
} }
} }
} }