Skip to content

Commit

Permalink
[ticket/17151] Extend forms tests
Browse files Browse the repository at this point in the history
PHPBB3-17151
  • Loading branch information
rxu committed Oct 2, 2023
1 parent da04734 commit 126462f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
19 changes: 19 additions & 0 deletions tests/functional/extension_module_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,50 +65,67 @@ public function test_acp()
$this->assertStringContainsString('SETTING_0', $crawler->filter('dl')->eq(0)->filter('dt > label[for="setting_0"]')->text());
$this->assertStringContainsString('SETTING_0_EXPLAIN', $crawler->filter('dl')->eq(0)->filter('dt > span')->text());
$this->assertEquals(2, $crawler->filter('dl')->eq(0)->filter('dd > input[type="number"]')->count());
$this->assertEquals(1, $crawler->filter('dl')->eq(0)->filter('dd > input[type="number"]')->eq(0)->attr('value'));
$this->assertEquals(17, $crawler->filter('dl')->eq(0)->filter('dd > input[type="number"]')->eq(1)->attr('value'));

$this->assertStringContainsString('SETTING_1', $crawler->filter('dl')->eq(1)->filter('dt > label[for="setting_1"]')->text());
$this->assertStringContainsString('CUSTOM_LANG_EXPLAIN', $crawler->filter('dl')->eq(1)->filter('dt > span')->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(1)->filter('dd > input[type="submit"]')->count());
$this->assertEquals('Test submit button', $crawler->filter('dl')->eq(1)->filter('dd > input[type="submit"]')->attr('value'));

$this->assertStringContainsString('SETTING_2', $crawler->filter('dl')->eq(2)->filter('dt > label[for="setting_2"]')->text());
$this->assertEquals(0, $crawler->filter('dl')->eq(2)->filter('dt > span')->count());
$this->assertEquals(2, $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->count());
$this->assertContainsLang('YES', $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(0)->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value'));
$this->assertEquals('checked', $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(0)->attr('checked'));
$this->assertContainsLang('NO', $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(1)->text());
$this->assertEquals(0, $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value'));

$this->assertStringContainsString('SETTING_3', $crawler->filter('dl')->eq(3)->filter('dt > label[for="setting_3"]')->text());
$this->assertStringContainsString('SETTING_3_EXPLAIN', $crawler->filter('dl')->eq(3)->filter('dt > span')->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(3)->filter('dd > input[type="number"]')->count());
$this->assertEquals(15, $crawler->filter('dl')->eq(3)->filter('dd > input[type="number"]')->attr('value'));

$this->assertStringContainsString('SETTING_4', $crawler->filter('dl')->eq(4)->filter('dt > label[for="setting_4"]')->text());
$this->assertStringContainsString('SETTING_4_EXPLAIN', $crawler->filter('dl')->eq(4)->filter('dt > span')->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(4)->filter('dd > select[id="setting_4"]')->count());
$this->assertEquals(3, $crawler->filter('dl')->eq(4)->filter('dd > select > option')->count());
$this->assertEquals(2, $crawler->filter('dl')->eq(4)->filter('dd > select > option')->eq(1)->attr('value'));
$this->assertEquals('selected', $crawler->filter('dl')->eq(4)->filter('dd > select > option')->eq(1)->attr('selected'));

$this->assertStringContainsString('SETTING_5', $crawler->filter('dl')->eq(5)->filter('dt > label[for="setting_5"]')->text());
$this->assertStringContainsString('SETTING_5_EXPLAIN', $crawler->filter('dl')->eq(5)->filter('dt > span')->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(5)->filter('dd > input[type="text"]')->count());
$this->assertEquals('Setting 5', $crawler->filter('dl')->eq(5)->filter('dd > input[type="text"]')->attr('value'));

$this->assertStringContainsString('SETTING_6', $crawler->filter('dl')->eq(6)->filter('dt > label[for="setting_6"]')->text());
$this->assertStringContainsString('SETTING_6_EXPLAIN', $crawler->filter('dl')->eq(6)->filter('dt > span')->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(6)->filter('dd > input[type="password"]')->count());
$this->assertEquals('********', $crawler->filter('dl')->eq(6)->filter('dd > input[type="password"]')->attr('value'));

$this->assertStringContainsString('SETTING_7', $crawler->filter('dl')->eq(7)->filter('dt > label[for="setting_7"]')->text());
$this->assertStringContainsString('SETTING_7_EXPLAIN', $crawler->filter('dl')->eq(7)->filter('dt > span')->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(7)->filter('dd > input[type="email"]')->count());
$this->assertEquals('test@example.dom', $crawler->filter('dl')->eq(7)->filter('dd > input[type="email"]')->attr('value'));

$this->assertStringContainsString('SETTING_8', $crawler->filter('dl')->eq(8)->filter('dt > label[for="setting_8"]')->text());
$this->assertStringContainsString('SETTING_8_EXPLAIN', $crawler->filter('dl')->eq(8)->filter('dt > span')->text());
$this->assertEquals(1, $crawler->filter('dl')->eq(8)->filter('dd > textarea[name="config[setting_8]"]')->count());
$this->assertEquals('Textarea', $crawler->filter('dl')->eq(8)->filter('dd > textarea[name="config[setting_8]"]')->text());

$this->assertStringContainsString('SETTING_9', $crawler->filter('dl')->eq(9)->filter('dt > label[for="setting_9"]')->text());
$this->assertStringContainsString('SETTING_9_EXPLAIN', $crawler->filter('dl')->eq(9)->filter('dt > span')->text());
$this->assertEquals(2, $crawler->filter('dl')->eq(9)->filter('dd > label > input[type="radio"]')->count());
$this->assertEquals('checked', $crawler->filter('dl')->eq(9)->filter('dd > label > input[type="radio"]')->eq(0)->attr('checked'));

$this->assertStringContainsString('SETTING_10', $crawler->filter('dl')->eq(10)->filter('dt > label[for="setting_10"]')->text());
$this->assertStringContainsString('SETTING_10_EXPLAIN', $crawler->filter('dl')->eq(10)->filter('dt > span')->text());
$this->assertEquals(3, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->count());
$this->assertEquals(1, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value'));
$this->assertStringContainsString('LABEL_1', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(0)->text());
$this->assertEquals(3, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value'));
$this->assertEquals('checked', $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(1)->attr('checked'));
$this->assertStringContainsString('LABEL_3', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(1)->text());
$this->assertEquals(2, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(2)->attr('value'));
$this->assertStringContainsString('LABEL_2', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(2)->text());
Expand All @@ -117,6 +134,7 @@ public function test_acp()
$this->assertStringContainsString('SETTING_11_EXPLAIN', $crawler->filter('dl')->eq(11)->filter('dt > span')->text());
$this->assertEquals('1', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value'));
$this->assertEquals('0', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value'));
$this->assertEquals('checked', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(1)->attr('checked'));
$this->assertContainsLang('YES', $crawler->filter('dl')->eq(11)->filter('dd > label')->eq(0)->text());
$this->assertContainsLang('NO', $crawler->filter('dl')->eq(11)->filter('dd > label')->eq(1)->text());

Expand All @@ -126,6 +144,7 @@ public function test_acp()
$this->assertEquals(1, $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value'));
$this->assertContainsLang('DISABLED', $crawler->filter('dl')->eq(12)->filter('dd > label')->eq(1)->text());
$this->assertEquals(0, $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value'));
$this->assertEquals('checked', $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(1)->attr('checked'));
}

public function test_ucp()
Expand Down
48 changes: 27 additions & 21 deletions tests/functional/fixtures/ext/foo/bar/acp/main_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,31 @@ function main($id, $mode)
'setting_7' => ['lang' => 'SETTING_7', 'validate' => 'email', 'type' => 'email:0:100', 'explain' => true],
'setting_8' => ['lang' => 'SETTING_8', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true],
'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']], 'explain' => true],
'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'LABEL_1', 3 => 'LABEL_3', 2 => 'LABEL_2']], 'explain' => true],
'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'int', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'LABEL_1', 3 => 'LABEL_3', 2 => 'LABEL_2']], 'explain' => true],
'setting_11'=> ['lang' => 'SETTING_11', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'setting_12'=> ['lang' => 'SETTING_12', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true],
]
];

$this->new_config = $cfg_array = $error = [];
$config = new \phpbb\config\config([
'setting_0_width' => '1',
'setting_0_height' => '17',
'setting_0' => '10',
'setting_2' => '1',
'setting_3' => '15',
'setting_4' => '2',
'setting_5' => 'Setting 5',
'setting_6' => 'password',
'setting_7' => 'test@example.dom',
'setting_8' => 'Textarea',
'setting_9' => '1',
'setting_10' => '3',
'setting_11' => '0',
'setting_12' => '0',
]);
$this->new_config = clone $config;
$cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', ['' => ''], true) : $this->new_config;
$error = [];

validate_config_vars($display_vars['vars'], $cfg_array, $error);

Expand Down Expand Up @@ -126,27 +144,15 @@ function main($id, $mode)
}
}

function create_select()
function create_select($value)
{
return [
'options' => [
[
'value' => 1,
'selected' => true,
'label' => 'Option 1',
],
[
'value' => 2,
'selected' => false,
'label' => 'Option 2',
],
[
'value' => 3,
'selected' => false,
'label' => 'Option 3',
],
]
$options = [
1 => 'Option 1',
2 => 'Option 2',
3 => 'Option 3',
];

return ['options' => build_select($options, $value)];
}

function submit_button()
Expand Down

0 comments on commit 126462f

Please sign in to comment.