From 322bb9cd2be9e51422cb2b82684692e825c2bfb7 Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 2 Oct 2009 18:40:04 +0000 Subject: Added simpletest and start of unit tests. git-svn-id: http://code.elgg.org/elgg/trunk@3503 36083f99-b078-4883-b0ff-0f9b5a30f544 --- vendors/simpletest/test/xml_test.php | 187 +++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100755 vendors/simpletest/test/xml_test.php (limited to 'vendors/simpletest/test/xml_test.php') diff --git a/vendors/simpletest/test/xml_test.php b/vendors/simpletest/test/xml_test.php new file mode 100755 index 000000000..91985b5d5 --- /dev/null +++ b/vendors/simpletest/test/xml_test.php @@ -0,0 +1,187 @@ + 2)); + $this->assertEqual($nesting->getSize(), 2); + } +} + +class TestOfXmlStructureParsing extends UnitTestCase { + function testValidXml() { + $listener = &new MockSimpleScorer(); + $listener->expectNever('paintGroupStart'); + $listener->expectNever('paintGroupEnd'); + $listener->expectNever('paintCaseStart'); + $listener->expectNever('paintCaseEnd'); + $parser = &new SimpleTestXmlParser($listener); + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("\n")); + } + + function testEmptyGroup() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintGroupStart', array('a_group', 7)); + $listener->expectOnce('paintGroupEnd', array('a_group')); + $parser = &new SimpleTestXmlParser($listener); + $parser->parse("\n"); + $parser->parse("\n"); + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("a_group\n")); + $this->assertTrue($parser->parse("\n")); + $parser->parse("\n"); + } + + function testEmptyCase() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintCaseStart', array('a_case')); + $listener->expectOnce('paintCaseEnd', array('a_case')); + $parser = &new SimpleTestXmlParser($listener); + $parser->parse("\n"); + $parser->parse("\n"); + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("a_case\n")); + $this->assertTrue($parser->parse("\n")); + $parser->parse("\n"); + } + + function testEmptyMethod() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintCaseStart', array('a_case')); + $listener->expectOnce('paintCaseEnd', array('a_case')); + $listener->expectOnce('paintMethodStart', array('a_method')); + $listener->expectOnce('paintMethodEnd', array('a_method')); + $parser = &new SimpleTestXmlParser($listener); + $parser->parse("\n"); + $parser->parse("\n"); + $parser->parse("\n"); + $parser->parse("a_case\n"); + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("a_method\n")); + $this->assertTrue($parser->parse("\n")); + $parser->parse("\n"); + $parser->parse("\n"); + } + + function testNestedGroup() { + $listener = &new MockSimpleScorer(); + $listener->expectArgumentsAt(0, 'paintGroupStart', array('a_group', 7)); + $listener->expectArgumentsAt(1, 'paintGroupStart', array('b_group', 3)); + $listener->expectCallCount('paintGroupStart', 2); + $listener->expectArgumentsAt(0, 'paintGroupEnd', array('b_group')); + $listener->expectArgumentsAt(1, 'paintGroupEnd', array('a_group')); + $listener->expectCallCount('paintGroupEnd', 2); + + $parser = &new SimpleTestXmlParser($listener); + $parser->parse("\n"); + $parser->parse("\n"); + + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("a_group\n")); + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("b_group\n")); + $this->assertTrue($parser->parse("\n")); + $this->assertTrue($parser->parse("\n")); + $parser->parse("\n"); + } +} + +class AnyOldSignal { + var $stuff = true; +} + +class TestOfXmlResultsParsing extends UnitTestCase { + + function sendValidStart(&$parser) { + $parser->parse("\n"); + $parser->parse("\n"); + $parser->parse("\n"); + $parser->parse("a_case\n"); + $parser->parse("\n"); + $parser->parse("a_method\n"); + } + + function sendValidEnd(&$parser) { + $parser->parse("\n"); + $parser->parse("\n"); + $parser->parse("\n"); + } + + function testPass() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintPass', array('a_message')); + $parser = &new SimpleTestXmlParser($listener); + $this->sendValidStart($parser); + $this->assertTrue($parser->parse("a_message\n")); + $this->sendValidEnd($parser); + } + + function testFail() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintFail', array('a_message')); + $parser = &new SimpleTestXmlParser($listener); + $this->sendValidStart($parser); + $this->assertTrue($parser->parse("a_message\n")); + $this->sendValidEnd($parser); + } + + function testException() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintError', array('a_message')); + $parser = &new SimpleTestXmlParser($listener); + $this->sendValidStart($parser); + $this->assertTrue($parser->parse("a_message\n")); + $this->sendValidEnd($parser); + } + + function testSkip() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintSkip', array('a_message')); + $parser = &new SimpleTestXmlParser($listener); + $this->sendValidStart($parser); + $this->assertTrue($parser->parse("a_message\n")); + $this->sendValidEnd($parser); + } + + function testSignal() { + $signal = new AnyOldSignal(); + $signal->stuff = "Hello"; + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintSignal', array('a_signal', $signal)); + $parser = &new SimpleTestXmlParser($listener); + $this->sendValidStart($parser); + $this->assertTrue($parser->parse( + "\n")); + $this->sendValidEnd($parser); + } + + function testMessage() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintMessage', array('a_message')); + $parser = &new SimpleTestXmlParser($listener); + $this->sendValidStart($parser); + $this->assertTrue($parser->parse("a_message\n")); + $this->sendValidEnd($parser); + } + + function testFormattedMessage() { + $listener = &new MockSimpleScorer(); + $listener->expectOnce('paintFormattedMessage', array("\na\tmessage\n")); + $parser = &new SimpleTestXmlParser($listener); + $this->sendValidStart($parser); + $this->assertTrue($parser->parse("\n")); + $this->sendValidEnd($parser); + } +} +?> \ No newline at end of file -- cgit v1.2.3