diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2013-10-02 10:11:18 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2013-10-02 10:11:18 +0200 |
commit | 8b08b1b455b474de3fa376dfafa3de63727364ea (patch) | |
tree | 536b2d4ba4f979d69f4f6e73755e06635345f78a /tests/lib/appframework/http/RequestTest.php | |
parent | 084f76fd14125023d5b7277c558eb86a20ea07d3 (diff) | |
parent | 535ed8369f701a184340a428e82cc8d7cc7588bb (diff) | |
download | nextcloud-server-8b08b1b455b474de3fa376dfafa3de63727364ea.tar.gz nextcloud-server-8b08b1b455b474de3fa376dfafa3de63727364ea.zip |
Merge branch 'master' into sharing_mail_notification_master
Conflicts:
lib/private/util.php
Diffstat (limited to 'tests/lib/appframework/http/RequestTest.php')
-rw-r--r-- | tests/lib/appframework/http/RequestTest.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/lib/appframework/http/RequestTest.php b/tests/lib/appframework/http/RequestTest.php new file mode 100644 index 00000000000..0371c870cf2 --- /dev/null +++ b/tests/lib/appframework/http/RequestTest.php @@ -0,0 +1,76 @@ +<?php +/** + * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net) + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\AppFramework\Http; + + +class RequestTest extends \PHPUnit_Framework_TestCase { + + public function testRequestAccessors() { + $vars = array( + 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'), + ); + + $request = new Request($vars); + + // Countable + $this->assertEquals(2, count($request)); + // Array access + $this->assertEquals('Joey', $request['nickname']); + // "Magic" accessors + $this->assertEquals('Joey', $request->{'nickname'}); + $this->assertTrue(isset($request['nickname'])); + $this->assertTrue(isset($request->{'nickname'})); + $this->assertEquals(false, isset($request->{'flickname'})); + // Only testing 'get', but same approach for post, files etc. + $this->assertEquals('Joey', $request->get['nickname']); + // Always returns null if variable not set. + $this->assertEquals(null, $request->{'flickname'}); + } + + // urlParams has precedence over POST which has precedence over GET + public function testPrecedence() { + $vars = array( + 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'), + 'post' => array('name' => 'Jane Doe', 'nickname' => 'Janey'), + 'urlParams' => array('user' => 'jw', 'name' => 'Johnny Weissmüller'), + ); + + $request = new Request($vars); + + $this->assertEquals(3, count($request)); + $this->assertEquals('Janey', $request->{'nickname'}); + $this->assertEquals('Johnny Weissmüller', $request->{'name'}); + } + + + /** + * @expectedException RuntimeException + */ + public function testImmutableArrayAccess() { + $vars = array( + 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'), + ); + + $request = new Request($vars); + $request['nickname'] = 'Janey'; + } + + /** + * @expectedException RuntimeException + */ + public function testImmutableMagicAccess() { + $vars = array( + 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'), + ); + + $request = new Request($vars); + $request->{'nickname'} = 'Janey'; + } + +} |