mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/16904] Refactor MCP tests
PHPBB3-16904
This commit is contained in:
parent
3f65672d31
commit
da43c99fd6
4 changed files with 277 additions and 22 deletions
35
tests/functional/mcp/mcp_logs_test.php
Normal file
35
tests/functional/mcp/mcp_logs_test.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class phpbb_functional_mcp_logs_test extends phpbb_functional_test_case
|
||||||
|
{
|
||||||
|
public function test_delete_logs()
|
||||||
|
{
|
||||||
|
$this->add_lang(['mcp', 'common']);
|
||||||
|
|
||||||
|
$this->login();
|
||||||
|
$crawler = self::request('GET', "mcp.php?i=mcp_logs&mode=front&sid={$this->sid}");
|
||||||
|
$this->assertGreaterThanOrEqual(1, $crawler->filter('input[type=checkbox]')->count());
|
||||||
|
|
||||||
|
$form = $crawler->selectButton($this->lang('DELETE_ALL'))->form();
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
|
||||||
|
$form = $crawler->selectButton($this->lang('YES'))->form();
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
|
||||||
|
$this->assertCount(0, $crawler->filter('input[type=checkbox]'));
|
||||||
|
}
|
||||||
|
}
|
169
tests/functional/mcp/mcp_main_test.php
Normal file
169
tests/functional/mcp/mcp_main_test.php
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
|
||||||
|
{
|
||||||
|
public function test_create_topics()
|
||||||
|
{
|
||||||
|
$this->add_lang(['acp/common', 'common']);
|
||||||
|
$this->login();
|
||||||
|
$this->admin_login();
|
||||||
|
|
||||||
|
// Disable flood intervar 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,
|
||||||
|
]);
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
$this->assertContainsLang('CONFIG_UPDATED', $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.');
|
||||||
|
$crawler = self::request('GET', "viewtopic.php?t={$post[0]['topic_id']}&sid={$this->sid}");
|
||||||
|
$this->assertStringContainsString('Testing forum moderation actions from MCP/View forum page.', $crawler->filter('html')->text());
|
||||||
|
|
||||||
|
$post[] = $this->create_topic(2, 'Topic to merge with', 'Testing merge topics moderation actions from MCP/View forum page.');
|
||||||
|
$crawler = self::request('GET', "viewtopic.php?t={$post[1]['topic_id']}&sid={$this->sid}");
|
||||||
|
$this->assertStringContainsString('Testing merge topics moderation actions from MCP/View forum page.', $crawler->filter('html')->text());
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends test_create_topics
|
||||||
|
*/
|
||||||
|
public function test_mcp_view_forum($post)
|
||||||
|
{
|
||||||
|
$this->add_lang(['common']);
|
||||||
|
$this->login();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Test forum moderation page has a list of topics to select
|
||||||
|
$this->assertGreaterThanOrEqual(3, $crawler->filter('input[type=checkbox]')->count());
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mcp_view_forum_actions_data()
|
||||||
|
{
|
||||||
|
// action, success message, require_confirmation
|
||||||
|
return [
|
||||||
|
['delete_topic', 'TOPIC_DELETED_SUCCESS', true],
|
||||||
|
['restore_topic', 'TOPIC_RESTORED_SUCCESS', true],
|
||||||
|
['fork', 'TOPIC_FORKED_SUCCESS', true],
|
||||||
|
['lock', 'TOPIC_LOCKED_SUCCESS', true],
|
||||||
|
['unlock', 'TOPIC_UNLOCKED_SUCCESS', true],
|
||||||
|
['resync', 'TOPIC_RESYNC_SUCCESS', false],
|
||||||
|
['make_global', 'TOPIC_TYPE_CHANGED', true],
|
||||||
|
['make_announce', 'TOPIC_TYPE_CHANGED', true],
|
||||||
|
['make_sticky', 'TOPIC_TYPE_CHANGED', true],
|
||||||
|
['make_normal', 'TOPIC_TYPE_CHANGED', true],
|
||||||
|
['merge_topics', 'POSTS_MERGED_SUCCESS', true],
|
||||||
|
['move', 'TOPIC_MOVED_SUCCESS', true],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends test_mcp_view_forum
|
||||||
|
* @dataProvider mcp_view_forum_actions_data
|
||||||
|
*/
|
||||||
|
public function test_mcp_view_forum_actions($action, $message, $require_confirmation, $post)
|
||||||
|
{
|
||||||
|
$topic_id_1 = $post[0]['topic_id'];
|
||||||
|
$topic_id_2 = $post[1]['topic_id'];
|
||||||
|
|
||||||
|
$this->add_lang(['common', 'mcp']);
|
||||||
|
$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);
|
||||||
|
|
||||||
|
// Test actions
|
||||||
|
$form = $crawler->selectButton($this->lang('SUBMIT'))->form()->disableValidation()->setValues([
|
||||||
|
'action' => $action,
|
||||||
|
'topic_id_list' => [$action == 'move' ? $topic_id_2 : $topic_id_1], // while moving, topic_id_1 has been already merged into topic_id_2
|
||||||
|
]);
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
|
||||||
|
if ($require_confirmation)
|
||||||
|
{
|
||||||
|
if ($action == 'merge_topics')
|
||||||
|
{
|
||||||
|
// Merge topic_id_1 into topic_id_2
|
||||||
|
$select_for_merge_link = substr_replace($crawler->filter('.row a')->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 ./
|
||||||
|
|
||||||
|
$crawler = self::request('GET', $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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertStringContainsString($this->lang($message), $crawler->filter('#message p')->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends test_mcp_view_forum_actions
|
||||||
|
*/
|
||||||
|
public function test_mcp_view_forum_permanently_delete_topic()
|
||||||
|
{
|
||||||
|
$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 topic ids to delete (forked and moved topics in the previous test)
|
||||||
|
$topic_link_1 = $crawler->selectLink('Test Topic 3')->attr('href');
|
||||||
|
$topic_link_2 = $crawler->selectLink('Topic to merge with')->attr('href');
|
||||||
|
$topic_ids = [
|
||||||
|
(int) $this->get_parameter_from_link($topic_link_1, 't'),
|
||||||
|
(int) $this->get_parameter_from_link($topic_link_2, 't'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$form = $crawler->selectButton($this->lang('SUBMIT'))->form()->disableValidation()->setValues([
|
||||||
|
'action' => 'delete_topic',
|
||||||
|
'topic_id_list' => $topic_ids, // tick both topics in the list
|
||||||
|
]);
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
|
||||||
|
$form = $crawler->selectButton($this->lang('YES'))->form();
|
||||||
|
$form['delete_permanent']->tick();
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
$this->assertStringContainsString($this->lang('TOPICS_DELETED_SUCCESS'), $crawler->filter('#message p')->text());
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
/**
|
/**
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class phpbb_functional_mcp_test extends phpbb_functional_test_case
|
class phpbb_functional_mcp_quickmod_tools_test extends phpbb_functional_test_case
|
||||||
{
|
{
|
||||||
public function test_post_new_topic()
|
public function test_post_new_topic()
|
||||||
{
|
{
|
||||||
|
@ -30,8 +30,8 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends test_post_new_topic
|
* @depends test_post_new_topic
|
||||||
*/
|
*/
|
||||||
public function test_handle_quickmod($crawler)
|
public function test_handle_quickmod($crawler)
|
||||||
{
|
{
|
||||||
$this->login();
|
$this->login();
|
||||||
|
@ -41,12 +41,12 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends test_handle_quickmod
|
* @depends test_handle_quickmod
|
||||||
*/
|
*/
|
||||||
public function test_move_post_to_topic($crawler)
|
public function test_move_post_to_topic($crawler)
|
||||||
{
|
{
|
||||||
$this->login();
|
$this->login();
|
||||||
$this->add_lang('mcp');
|
$this->add_lang('common');
|
||||||
|
|
||||||
// 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(
|
||||||
|
@ -56,26 +56,20 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case
|
||||||
$crawler = self::submit($form);
|
$crawler = self::submit($form);
|
||||||
$this->assertStringContainsString($this->lang('MERGE_POSTS'), $crawler->filter('html')->text());
|
$this->assertStringContainsString($this->lang('MERGE_POSTS'), $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('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;
|
return $crawler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_delete_logs()
|
|
||||||
{
|
|
||||||
$this->login();
|
|
||||||
$crawler = self::request('GET', "mcp.php?i=mcp_logs&mode=front&sid={$this->sid}");
|
|
||||||
$this->assertGreaterThanOrEqual(1, $crawler->filter('input[type=checkbox]')->count());
|
|
||||||
|
|
||||||
$this->add_lang('mcp');
|
|
||||||
$form = $crawler->selectButton($this->lang('DELETE_ALL'))->form();
|
|
||||||
$crawler = self::submit($form);
|
|
||||||
|
|
||||||
$form = $crawler->selectButton('Yes')->form();
|
|
||||||
$crawler = self::submit($form);
|
|
||||||
|
|
||||||
$this->assertCount(0, $crawler->filter('input[type=checkbox]'));
|
|
||||||
}
|
|
||||||
}
|
}
|
57
tests/functional/mcp/mcp_test.php
Normal file
57
tests/functional/mcp/mcp_test.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class phpbb_functional_mcp_test extends phpbb_functional_test_case
|
||||||
|
{
|
||||||
|
public function test_all_mcp_module_links()
|
||||||
|
{
|
||||||
|
$this->login();
|
||||||
|
$this->add_lang(['common', 'mcp']);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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 ./
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Browse all MCP modules and get their mode URLs array
|
||||||
|
$mcp_submodules = [];
|
||||||
|
foreach ($mcp_modules as $module)
|
||||||
|
{
|
||||||
|
$crawler = self::request('GET', $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 ./
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Browse all MCP submodules' modes
|
||||||
|
$mcp_submodule_modes = [];
|
||||||
|
foreach ($mcp_submodules as $mcp_submodule)
|
||||||
|
{
|
||||||
|
$crawler = self::request('GET', $mcp_submodule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue