diff --git a/tests/functional/mcp/mcp_main_test.php b/tests/functional/mcp/mcp_main_test.php index 9e6314aed2..a440972058 100644 --- a/tests/functional/mcp/mcp_main_test.php +++ b/tests/functional/mcp/mcp_main_test.php @@ -18,11 +18,11 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case { public function test_create_topics() { - $this->add_lang(['acp/common', 'common']); + $this->add_lang(['acp/common', 'acp/forums', 'common']); $this->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}"); $form = $crawler->selectButton($this->lang('SUBMIT'))->form([ 'config[flood_interval]' => 0, @@ -30,6 +30,20 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case $crawler = self::submit($form); $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 $post = []; $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) $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::request('GET', $mcp_link); + $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link()); // Test forum moderation page has a list of topics to select $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(); $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::request('GET', $mcp_link); + $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link()); // Test actions $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') { // 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) { 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(); if (in_array($action, ['fork', 'move'])) { - // Fork or move the topic to the forum id=3 'Download #1' - $form->setValues(['to_forum_id' => 3]); + // Fork or move the topic to the 'MCP Test #1' + $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); @@ -142,10 +160,10 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case $this->add_lang(['common', 'mcp']); $this->login(); - // Get to the forum id=3 'Download #1' where the topic has been moved to in previous test - $crawler = self::request('GET', "viewforum.php?f=3&sid={$this->sid}"); - $mcp_link = substr_replace($crawler->selectLink($this->lang('MCP_SHORT'))->attr('href'), '', 0, 2); // Remove leading ./ - $crawler = self::request('GET', $mcp_link); + // Get to the forum 'MCP Test #1' where the topic has been moved to in previous test + $crawler = self::request('GET', "index.php?sid={$this->sid}"); + $crawler = self::$client->click($crawler->selectLink('MCP Test #1')->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) $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(); $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::request('GET', $mcp_link); + $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link()); $this->assertLessThanOrEqual(count($post), $crawler->filter('input[type=checkbox]')->count()); // Test actions @@ -264,22 +281,22 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case { // Merge posts into '[Split] Topic 1' // Get topics list to select from - $select_topic = substr_replace($crawler->selectLink($this->lang('SELECT_TOPIC'))->attr('href'), '', 0, 2); // Remove leading ./ - $crawler = self::request('GET', $select_topic); + $crawler = self::$client->click($crawler->selectLink($this->lang('SELECT_TOPIC'))->link()); // Get '[Split] Topic 1' topic_id $to_topic_link = $crawler->selectLink('[Split] Topic 1')->attr('href'); $to_topic_id = (int) $this->get_parameter_from_link($to_topic_link, 't'); // 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) { 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')); // Reselect post ids to move diff --git a/tests/functional/mcp/mcp_quickmod_tools_test.php b/tests/functional/mcp/mcp_quickmod_tools_test.php index ec0041b38e..ef44f31efb 100644 --- a/tests/functional/mcp/mcp_quickmod_tools_test.php +++ b/tests/functional/mcp/mcp_quickmod_tools_test.php @@ -46,7 +46,7 @@ class phpbb_functional_mcp_quickmod_tools_test extends phpbb_functional_test_cas public function test_move_post_to_topic($crawler) { $this->login(); - $this->add_lang('common'); + $this->add_lang(['common', 'mcp']); // Select the post in MCP $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(); $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; - } - - /** - * @depends test_move_post_to_topic - */ - public function test_confirm_result($crawler) - { - $this->login(); - $this->add_lang('mcp'); - $form = $crawler->selectButton('Yes')->form(); + $form = $crawler->selectButton($this->lang('YES'))->form(); $crawler = self::submit($form); $this->assertStringContainsString($this->lang('POSTS_MERGED_SUCCESS'), $crawler->text()); - - return $crawler; } } diff --git a/tests/functional/mcp/mcp_test.php b/tests/functional/mcp/mcp_test.php index 03d856de23..ff8dff4564 100644 --- a/tests/functional/mcp/mcp_test.php +++ b/tests/functional/mcp/mcp_test.php @@ -23,14 +23,13 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case // Browse MCP main page $crawler = self::request('GET', 'index.php'); - $mcp_link = substr_replace($crawler->selectLink($this->lang('MCP_SHORT'))->attr('href'), '', 0, 2); // Remove leading ./ - $crawler = self::request('GET', $mcp_link); + $crawler = self::$client->click($crawler->selectLink($this->lang('MCP_SHORT'))->link()); // Get all MCP module URLs array $mcp_modules = $crawler->filter('.tabs a')->each( 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 = []; 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( function ($node, $i) { - return substr_replace($node->attr('href'), '', 0, 2); // Remove leading ./ + return $node->link(); } )); } // Browse all MCP submodules' modes - $mcp_submodule_modes = []; foreach ($mcp_submodules as $mcp_submodule) { - $crawler = self::request('GET', $mcp_submodule); + self::$client->click($mcp_submodule); } } }