aboutsummaryrefslogtreecommitdiff
path: root/vendors/simpletest/test/web_tester_test.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-02 18:40:04 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-02 18:40:04 +0000
commit322bb9cd2be9e51422cb2b82684692e825c2bfb7 (patch)
tree1e8e75c1ff0c47d6eda9db114a13dfa2b83adf72 /vendors/simpletest/test/web_tester_test.php
parent4ffb02ad9c1b95013a0fbf97cefde827600ecc3f (diff)
downloadelgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.gz
elgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.bz2
Added simpletest and start of unit tests.
git-svn-id: http://code.elgg.org/elgg/trunk@3503 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'vendors/simpletest/test/web_tester_test.php')
-rwxr-xr-xvendors/simpletest/test/web_tester_test.php156
1 files changed, 156 insertions, 0 deletions
diff --git a/vendors/simpletest/test/web_tester_test.php b/vendors/simpletest/test/web_tester_test.php
new file mode 100755
index 000000000..01f7d3c8c
--- /dev/null
+++ b/vendors/simpletest/test/web_tester_test.php
@@ -0,0 +1,156 @@
+<?php
+// $Id: web_tester_test.php 1509 2007-05-08 22:11:49Z lastcraft $
+require_once(dirname(__FILE__) . '/../autorun.php');
+require_once(dirname(__FILE__) . '/../web_tester.php');
+
+class TestOfFieldExpectation extends UnitTestCase {
+
+ function testStringMatchingIsCaseSensitive() {
+ $expectation = new FieldExpectation('a');
+ $this->assertTrue($expectation->test('a'));
+ $this->assertTrue($expectation->test(array('a')));
+ $this->assertFalse($expectation->test('A'));
+ }
+
+ function testMatchesInteger() {
+ $expectation = new FieldExpectation('1');
+ $this->assertTrue($expectation->test('1'));
+ $this->assertTrue($expectation->test(1));
+ $this->assertTrue($expectation->test(array('1')));
+ $this->assertTrue($expectation->test(array(1)));
+ }
+
+ function testNonStringFailsExpectation() {
+ $expectation = new FieldExpectation('a');
+ $this->assertFalse($expectation->test(null));
+ }
+
+ function testUnsetFieldCanBeTestedFor() {
+ $expectation = new FieldExpectation(false);
+ $this->assertTrue($expectation->test(false));
+ }
+
+ function testMultipleValuesCanBeInAnyOrder() {
+ $expectation = new FieldExpectation(array('a', 'b'));
+ $this->assertTrue($expectation->test(array('a', 'b')));
+ $this->assertTrue($expectation->test(array('b', 'a')));
+ $this->assertFalse($expectation->test(array('a', 'a')));
+ $this->assertFalse($expectation->test('a'));
+ }
+
+ function testSingleItemCanBeArrayOrString() {
+ $expectation = new FieldExpectation(array('a'));
+ $this->assertTrue($expectation->test(array('a')));
+ $this->assertTrue($expectation->test('a'));
+ }
+}
+
+class TestOfHeaderExpectations extends UnitTestCase {
+
+ function testExpectingOnlyTheHeaderName() {
+ $expectation = new HttpHeaderExpectation('a');
+ $this->assertIdentical($expectation->test(false), false);
+ $this->assertIdentical($expectation->test('a: A'), true);
+ $this->assertIdentical($expectation->test('A: A'), true);
+ $this->assertIdentical($expectation->test('a: B'), true);
+ $this->assertIdentical($expectation->test(' a : A '), true);
+ }
+
+ function testHeaderValueAsWell() {
+ $expectation = new HttpHeaderExpectation('a', 'A');
+ $this->assertIdentical($expectation->test(false), false);
+ $this->assertIdentical($expectation->test('a: A'), true);
+ $this->assertIdentical($expectation->test('A: A'), true);
+ $this->assertIdentical($expectation->test('A: a'), false);
+ $this->assertIdentical($expectation->test('a: B'), false);
+ $this->assertIdentical($expectation->test(' a : A '), true);
+ $this->assertIdentical($expectation->test(' a : AB '), false);
+ }
+
+ function testHeaderValueWithColons() {
+ $expectation = new HttpHeaderExpectation('a', 'A:B:C');
+ $this->assertIdentical($expectation->test('a: A'), false);
+ $this->assertIdentical($expectation->test('a: A:B'), false);
+ $this->assertIdentical($expectation->test('a: A:B:C'), true);
+ $this->assertIdentical($expectation->test('a: A:B:C:D'), false);
+ }
+
+ function testMultilineSearch() {
+ $expectation = new HttpHeaderExpectation('a', 'A');
+ $this->assertIdentical($expectation->test("aa: A\r\nb: B\r\nc: C"), false);
+ $this->assertIdentical($expectation->test("aa: A\r\na: A\r\nb: B"), true);
+ }
+
+ function testMultilineSearchWithPadding() {
+ $expectation = new HttpHeaderExpectation('a', ' A ');
+ $this->assertIdentical($expectation->test("aa:A\r\nb:B\r\nc:C"), false);
+ $this->assertIdentical($expectation->test("aa:A\r\na:A\r\nb:B"), true);
+ }
+
+ function testPatternMatching() {
+ $expectation = new HttpHeaderExpectation('a', new PatternExpectation('/A/'));
+ $this->assertIdentical($expectation->test('a: A'), true);
+ $this->assertIdentical($expectation->test('A: A'), true);
+ $this->assertIdentical($expectation->test('A: a'), false);
+ $this->assertIdentical($expectation->test('a: B'), false);
+ $this->assertIdentical($expectation->test(' a : A '), true);
+ $this->assertIdentical($expectation->test(' a : AB '), true);
+ }
+
+ function testCaseInsensitivePatternMatching() {
+ $expectation = new HttpHeaderExpectation('a', new PatternExpectation('/A/i'));
+ $this->assertIdentical($expectation->test('a: a'), true);
+ $this->assertIdentical($expectation->test('a: B'), false);
+ $this->assertIdentical($expectation->test(' a : A '), true);
+ $this->assertIdentical($expectation->test(' a : BAB '), true);
+ $this->assertIdentical($expectation->test(' a : bab '), true);
+ }
+
+ function testUnwantedHeader() {
+ $expectation = new NoHttpHeaderExpectation('a');
+ $this->assertIdentical($expectation->test(''), true);
+ $this->assertIdentical($expectation->test('stuff'), true);
+ $this->assertIdentical($expectation->test('b: B'), true);
+ $this->assertIdentical($expectation->test('a: A'), false);
+ $this->assertIdentical($expectation->test('A: A'), false);
+ }
+
+ function testMultilineUnwantedSearch() {
+ $expectation = new NoHttpHeaderExpectation('a');
+ $this->assertIdentical($expectation->test("aa:A\r\nb:B\r\nc:C"), true);
+ $this->assertIdentical($expectation->test("aa:A\r\na:A\r\nb:B"), false);
+ }
+
+ function testLocationHeaderSplitsCorrectly() {
+ $expectation = new HttpHeaderExpectation('Location', 'http://here/');
+ $this->assertIdentical($expectation->test('Location: http://here/'), true);
+ }
+}
+
+class TestOfTextExpectations extends UnitTestCase {
+
+ function testMatchingSubString() {
+ $expectation = new TextExpectation('wanted');
+ $this->assertIdentical($expectation->test(''), false);
+ $this->assertIdentical($expectation->test('Wanted'), false);
+ $this->assertIdentical($expectation->test('wanted'), true);
+ $this->assertIdentical($expectation->test('the wanted text is here'), true);
+ }
+
+ function testNotMatchingSubString() {
+ $expectation = new NoTextExpectation('wanted');
+ $this->assertIdentical($expectation->test(''), true);
+ $this->assertIdentical($expectation->test('Wanted'), true);
+ $this->assertIdentical($expectation->test('wanted'), false);
+ $this->assertIdentical($expectation->test('the wanted text is here'), false);
+ }
+}
+
+class TestOfGenericAssertionsInWebTester extends WebTestCase {
+
+ function testEquality() {
+ $this->assertEqual('a', 'a');
+ $this->assertNotEqual('a', 'A');
+ }
+}
+?> \ No newline at end of file