From c7e9235db3c8b751dbc5bdffc0bece6e7660c14c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 4 Feb 2013 19:46:29 +0000 Subject: [PATCH] Added util unit tests --- tests/util/RedirectUriTest.php | 15 +++++++ tests/util/RequestTest.php | 73 ++++++++++++++++++++++++++++++++++ tests/util/SecureKeyTest.php | 15 +++++++ 3 files changed, 103 insertions(+) create mode 100644 tests/util/RedirectUriTest.php create mode 100644 tests/util/RequestTest.php create mode 100644 tests/util/SecureKeyTest.php diff --git a/tests/util/RedirectUriTest.php b/tests/util/RedirectUriTest.php new file mode 100644 index 00000000..6f7aaa1e --- /dev/null +++ b/tests/util/RedirectUriTest.php @@ -0,0 +1,15 @@ +'bar')); + $v2 = OAuth2\Util\RedirectUri::make('https://foobar/', array('foo'=>'bar'), '#'); + $v3 = OAuth2\Util\RedirectUri::make('https://foobar/', array('foo'=>'bar', 'bar' => 'foo')); + + $this->assertEquals('https://foobar/?foo=bar', $v1); + $this->assertEquals('https://foobar/#foo=bar', $v2); + $this->assertEquals('https://foobar/?foo=bar&bar=foo', $v3); + } +} \ No newline at end of file diff --git a/tests/util/RequestTest.php b/tests/util/RequestTest.php new file mode 100644 index 00000000..91413204 --- /dev/null +++ b/tests/util/RequestTest.php @@ -0,0 +1,73 @@ +request = new OAuth2\Request( + array('foo' => 'bar'), + array('foo' => 'bar'), + array('foo' => 'bar'), + array('foo' => 'bar'), + array('HTTP_HOST' => 'foobar.com') + ); + } + + function test_buildFromIndex() + { + $r = new OAuth2\Request(); + $r->buildFromGlobals(); + + $this->assertTrue($r instanceof OAuth2\Request); + } + + function test_get() + { + $this->assertEquals('bar', $this->request->get('foo')); + $this->assertEquals(array('foo' => 'bar'), $this->request->get()); + } + + function test_post() + { + $this->assertEquals('bar', $this->request->post('foo')); + $this->assertEquals(array('foo' => 'bar'), $this->request->post()); + } + + function test_file() + { + $this->assertEquals('bar', $this->request->file('foo')); + $this->assertEquals(array('foo' => 'bar'), $this->request->file()); + } + + function test_cookie() + { + $this->assertEquals('bar', $this->request->cookie('foo')); + $this->assertEquals(array('foo' => 'bar'), $this->request->cookie()); + } + + function test_server() + { + $this->assertEquals('foobar.com', $this->request->server('HTTP_HOST')); + $this->assertEquals(array('HTTP_HOST' => 'foobar.com'), $this->request->server()); + } + + function test_header() + { + $this->assertEquals('foobar.com', $this->request->header('host')); + $this->assertEquals(array('host' => 'foobar.com'), $this->request->header()); + } + + /** + * @expectedException InvalidArgumentException + */ + function test_unknownProperty() + { + $reflector = new ReflectionClass($this->request); + $method = $reflector->getMethod('getPropertyValue'); + $method->setAccessible(true); + + $result = $method->invoke($this->request, 'blah'); + } +} \ No newline at end of file diff --git a/tests/util/SecureKeyTest.php b/tests/util/SecureKeyTest.php new file mode 100644 index 00000000..6a46c6c9 --- /dev/null +++ b/tests/util/SecureKeyTest.php @@ -0,0 +1,15 @@ +assertEquals(40, strlen($v1)); + $this->assertTrue($v1 !== $v2); + $this->assertEquals(50, strlen($v3)); + } +} \ No newline at end of file