1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-18 13:30:08 +02:00

[ticket/11460] Add methods for checkbox handling to phpbb_functional_test_case.

PHPBB3-11460
This commit is contained in:
Andreas Fischer 2013-03-21 03:07:50 +01:00
parent 1ac94699e4
commit 15aec0bbb2

View File

@ -463,4 +463,68 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->assertGreaterThan(0, count($nodes), $msg);
return $nodes;
}
/**
* Asserts that exactly one checkbox with name $name exists within the scope
* of $crawler and that the checkbox is checked.
*
* @param Symfony\Component\DomCrawler\Crawler $crawler
* @param string $name
* @param string $message
*
* @return null
*/
public function assert_checkbox_is_checked($crawler, $name, $message = '')
{
$this->assertSame(
'checked',
$this->assert_find_one_checkbox($crawler, $name)->attr('checked'),
$message ?: "Failed asserting that checkbox $name is checked."
);
}
/**
* Asserts that exactly one checkbox with name $name exists within the scope
* of $crawler and that the checkbox is unchecked.
*
* @param Symfony\Component\DomCrawler\Crawler $crawler
* @param string $name
* @param string $message
*
* @return null
*/
public function assert_checkbox_is_unchecked($crawler, $name, $message = '')
{
$this->assertSame(
'',
$this->assert_find_one_checkbox($crawler, $name)->attr('checked'),
$message ?: "Failed asserting that checkbox $name is unchecked."
);
}
/**
* Searches for an input element of type checkbox with the name $name using
* $crawler. Contains an assertion that only one such checkbox exists within
* the scope of $crawler.
*
* @param Symfony\Component\DomCrawler\Crawler $crawler
* @param string $name
* @param string $message
*
* @return Symfony\Component\DomCrawler\Crawler
*/
public function assert_find_one_checkbox($crawler, $name, $message = '')
{
$query = sprintf('//input[@type="checkbox" and @name="%s"]', $name);
$result = $crawler->filterXPath($query);
$this->assertEquals(
1,
sizeof($result),
$message ?: 'Failed asserting that exactly one checkbox with name' .
" $name exists in crawler scope."
);
return $result;
}
}