From 15aec0bbb24be10da850f78d85a3d10880c6f28a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 21 Mar 2013 03:07:50 +0100 Subject: [PATCH] [ticket/11460] Add methods for checkbox handling to phpbb_functional_test_case. PHPBB3-11460 --- .../phpbb_functional_test_case.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 887dfea3b5..a62f5341ca 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -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; + } }