Author: chabotc Date: Thu Aug 14 15:49:17 2008 New Revision: 686073 URL: http://svn.apache.org/viewvc?rev=686073&view=rev Log: Lots of new social-api tests by Gonzalo Aune, increasing our code coverage there by quite a bit
Added: incubator/shindig/trunk/php/test/social-api/ActivitiesHandlerTest.php incubator/shindig/trunk/php/test/social-api/AppDataHandlerTest.php incubator/shindig/trunk/php/test/social-api/GroupIdTest.php incubator/shindig/trunk/php/test/social-api/MessagesHandlerTest.php incubator/shindig/trunk/php/test/social-api/PeopleHandlerTest.php incubator/shindig/trunk/php/test/social-api/RestFulCollectionTest.php incubator/shindig/trunk/php/test/social-api/RestRequestItemTest.php incubator/shindig/trunk/php/test/social-api/UserIdTest.php Modified: incubator/shindig/trunk/php/src/social-api/canonical/JsonDbOpensocialService.php Modified: incubator/shindig/trunk/php/src/social-api/canonical/JsonDbOpensocialService.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/canonical/JsonDbOpensocialService.php?rev=686073&r1=686072&r2=686073&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/social-api/canonical/JsonDbOpensocialService.php (original) +++ incubator/shindig/trunk/php/src/social-api/canonical/JsonDbOpensocialService.php Thu Aug 14 15:49:17 2008 @@ -128,40 +128,34 @@ private function getAllPeople() { - if (is_null($this->allPeople)) { - $db = $this->getDb(); - $peopleTable = $db[self::$PEOPLE_TABLE]; - foreach ($peopleTable as $people) { - $this->allPeople[$people['id']] = $people; - } - $db[self::$PEOPLE_TABLE] = $this->allPeople; + $db = $this->getDb(); + $peopleTable = $db[self::$PEOPLE_TABLE]; + foreach ($peopleTable as $people) { + $this->allPeople[$people['id']] = $people; } + $db[self::$PEOPLE_TABLE] = $this->allPeople; return $this->allPeople; } private function getAllData() { - if (is_null($this->allData)) { - $db = $this->getDb(); - $dataTable = $db[self::$DATA_TABLE]; - foreach ($dataTable as $key => $value) { - $this->allData[$key] = $value; - } - $db[self::$DATA_TABLE] = $this->allData; + $db = $this->getDb(); + $dataTable = $db[self::$DATA_TABLE]; + foreach ($dataTable as $key => $value) { + $this->allData[$key] = $value; } + $db[self::$DATA_TABLE] = $this->allData; return $this->allData; } private function getAllActivities() { - if (is_null($this->allActivities)) { - $db = $this->getDb(); - $activitiesTable = $db[self::$ACTIVITIES_TABLE]; - foreach ($activitiesTable as $key => $value) { - $this->allActivities[$key] = $value; - } - $db[self::$ACTIVITIES_TABLE] = $this->allActivities; + $db = $this->getDb(); + $activitiesTable = $db[self::$ACTIVITIES_TABLE]; + foreach ($activitiesTable as $key => $value) { + $this->allActivities[$key] = $value; } + $db[self::$ACTIVITIES_TABLE] = $this->allActivities; return $this->allActivities; } @@ -326,8 +320,8 @@ } switch ($groupId->getType()) { case 'self': - foreach ($fields as $key) { //TODO: Implement this! - } + foreach ($fields as $key) {//TODO: Implement this! +} break; default: return new ResponseItem(NOT_IMPLEMENTED, "We don't support deleting data in batches yet", null); Added: incubator/shindig/trunk/php/test/social-api/ActivitiesHandlerTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/ActivitiesHandlerTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/ActivitiesHandlerTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/ActivitiesHandlerTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,177 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * Implementation tests based on ActivitiesHandler + */ +class ActivitiesHandlerTest extends PHPUnit_Framework_TestCase { + + /** + * @var ActivitiesHandler + */ + private $ActivitiesHandler; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->clearFileCache(); + $this->ActivitiesHandler = new ActivitiesHandler(); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->ActivitiesHandler = null; + $this->clearFileCache(); + parent::tearDown(); + } + + /** + * Tests ActivitiesHandler->handleDelete() + */ + public function testHandleDelete() + { + $request = array(); + $request['url'] = '/activities/@viewer/@[EMAIL PROTECTED]&networkDistance='; + $request['method'] = 'GET'; + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->ActivitiesHandler->handleDelete($requestItem); + $this->assertEquals(BAD_REQUEST, $response->getError()); + $this->assertEquals('You can\'t delete activities. ', $response->getErrorMessage()); + } + + /** + * Tests ActivitiesHandler->handleGet() + */ + public function testHandleGet() + { + $request = array(); + $request['url'] = '/activities/@viewer/@[EMAIL PROTECTED]&networkDistance='; + $request['method'] = 'GET'; + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->ActivitiesHandler->handleGet($requestItem); + $response = $response->getResponse(); + $entry = $response->getEntry(); + $this->assertEquals('1', $response->getTotalResults()); + $this->assertEquals('1', $entry[0]['id']); + $this->assertEquals('john.doe', $entry[0]['userId']); + $this->assertEquals('yellow', $entry[0]['title']); + $this->assertEquals('what a color!', $entry[0]['body']); + } + + /** + * Tests ActivitiesHandler->handlePost() + */ + public function testHandlePost() + { + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + + //Create activity + $request = array(); + $request['url'] = '/activities/@viewer/@self/@app?networkDistance='; + $request['method'] = 'POST'; + $request['postData'] = array(); + $request['postData']['id'] = '2'; + $request['postData']['appId'] = '1'; + $request['postData']['userId'] = 'john.doe'; + $request['postData']['title'] = 'TestPost'; + $request['postData']['body'] = 'TestBody'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $this->ActivitiesHandler->handlePost($requestItem); + + //Validate generated activity + $request = array(); + $request['url'] = '/activities/@viewer/@self/@app'; + $request['method'] = 'GET'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->ActivitiesHandler->handleGet($requestItem); + $response = $response->getResponse(); + $entry = $response->getEntry(); + $this->assertEquals('2', $response->getTotalResults()); + //First Entry + $this->assertEquals('1', $entry[0]['id']); + $this->assertEquals('john.doe', $entry[0]['userId']); + $this->assertEquals('yellow', $entry[0]['title']); + $this->assertEquals('what a color!', $entry[0]['body']); + //Second Entry + $this->assertEquals('2', $entry[1]['id']); + $this->assertEquals('john.doe', $entry[1]['userId']); + $this->assertEquals('TestPost', $entry[1]['title']); + $this->assertEquals('TestBody', $entry[1]['body']); + } + + /** + * Tests ActivitiesHandler->handlePut() + */ + public function testHandlePut() + { + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + + //Create activity + $request = array(); + $request['url'] = '/activities/@viewer/@self/@app?networkDistance='; + $request['method'] = 'POST'; + $request['postData'] = array(); + $request['postData']['id'] = '3'; + $request['postData']['appId'] = '1'; + $request['postData']['userId'] = 'john.doe'; + $request['postData']['title'] = 'TestPost 3'; + $request['postData']['body'] = 'TestBody 3'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $this->ActivitiesHandler->handlePut($requestItem); + + //Validate generated activity + $request = array(); + $request['url'] = '/activities/@viewer/@self/@app'; + $request['method'] = 'GET'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->ActivitiesHandler->handleGet($requestItem); + $response = $response->getResponse(); + $entry = $response->getEntry(); + $this->assertEquals('2', $response->getTotalResults()); + //First Entry + $this->assertEquals('1', $entry[0]['id']); + $this->assertEquals('john.doe', $entry[0]['userId']); + $this->assertEquals('yellow', $entry[0]['title']); + $this->assertEquals('what a color!', $entry[0]['body']); + //Second Entry + $this->assertEquals('3', $entry[1]['id']); + $this->assertEquals('john.doe', $entry[1]['userId']); + $this->assertEquals('TestPost 3', $entry[1]['title']); + $this->assertEquals('TestBody 3', $entry[1]['body']); + } + + private function clearFileCache() + { + unlink(sys_get_temp_dir() . "ShindigDb.json"); + } +} Added: incubator/shindig/trunk/php/test/social-api/AppDataHandlerTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/AppDataHandlerTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/AppDataHandlerTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/AppDataHandlerTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,145 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * Implementation tests based on AppDataHandler + */ +class AppDataHandlerTest extends PHPUnit_Framework_TestCase { + + /** + * @var AppDataHandler + */ + private $AppDataHandler; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->clearFileCache(); + $this->AppDataHandler = new AppDataHandler(); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->AppDataHandler = null; + $this->clearFileCache(); + parent::tearDown(); + } + + /** + * Tests ActivitiesHandler->handleDelete() + */ + public function testHandleDelete() + { + $request = array(); + $request['url'] = '/appdata/@viewer/@app?fields=count'; + $request['method'] = 'POST'; + $request['postData'] = array(); + $request['postData']['data'] = 'TestHandleDelete'; + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->AppDataHandler->handleDelete($requestItem); + $this->assertEquals(NOT_IMPLEMENTED, $response->getError()); + $this->assertEquals("We don't support deleting data in batches yet", $response->getErrorMessage()); + } + + /** + * Tests ActivitiesHandler->handleGet() + */ + public function testHandleGet() + { + $request = array(); + $request['url'] = '/appdata/@viewer/@self/@app?networkDistance=&fields=count'; + $request['method'] = 'GET'; + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->AppDataHandler->handleGet($requestItem); + $response = $response->getResponse(); + $entry = $response->getEntry(); + $this->assertEquals('0', $entry['john.doe']['count']); + } + + /** + * Tests ActivitiesHandler->handlePost() + */ + public function testHandlePost() + { + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + //Create data + $request = array(); + $request['url'] = '/appdata/@viewer/@self/@app?fields=count'; + $request['method'] = 'POST'; + $request['postData'] = array(); + $request['postData']['count'] = 'TestHandlePost'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $this->AppDataHandler->handlePost($requestItem); + + //Validate generated data + $request = array(); + $request['url'] = '/appdata/@viewer/@self/@app?networkDistance=&fields=count'; + $request['method'] = 'GET'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->AppDataHandler->handleGet($requestItem); + $response = $response->getResponse(); + $entry = $response->getEntry(); + $this->assertEquals('TestHandlePost', $entry['john.doe']['count']); + } + + /** + * Tests ActivitiesHandler->handlePut() + */ + public function testHandlePut() + { + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + //Create data + $request = array(); + $request['url'] = '/appdata/@viewer/@self/@app?fields=count'; + $request['method'] = 'POST'; + $request['postData'] = array(); + $request['postData']['count'] = 'TestHandlePut'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $this->AppDataHandler->handlePut($requestItem); + + //Validate generated data + $request = array(); + $request['url'] = '/appdata/@viewer/@self/@app?networkDistance=&fields=count'; + $request['method'] = 'GET'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->AppDataHandler->handleGet($requestItem); + $response = $response->getResponse(); + $entry = $response->getEntry(); + $this->assertEquals('TestHandlePut', $entry['john.doe']['count']); + } + + private function clearFileCache() + { + unlink(sys_get_temp_dir() . "ShindigDb.json"); + } +} Added: incubator/shindig/trunk/php/test/social-api/GroupIdTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/GroupIdTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/GroupIdTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/GroupIdTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,90 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * GroupId test case. + */ +class GroupIdTest extends PHPUnit_Framework_TestCase { + + /** + * @var GroupId + */ + private $GroupId; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->GroupId = new GroupId('all', 1); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->GroupId = null; + parent::tearDown(); + } + + /** + * Constructs the test case. + */ + public function __construct() + { + } + + /** + * Tests GroupId->__construct() + */ + public function test__construct() + { + $this->GroupId->__construct('all', 1); + } + + /** + * Tests GroupId->getGroupId() + */ + public function testGetGroupId() + { + $this->assertEquals(1, $this->GroupId->getGroupId()); + } + + /** + * Tests GroupId->getType() + */ + public function testGetType() + { + $this->assertEquals('all', $this->GroupId->getType()); + } + + /** + * Tests GroupId->fromJson() + */ + public function testFromJson() + { + $json = 'jsonid'; + $fromJson = $this->GroupId->fromJson($json); + $this->assertEquals('groupId', $fromJson->getType()); + $this->assertEquals('jsonid', $fromJson->getGroupId()); + } + +} Added: incubator/shindig/trunk/php/test/social-api/MessagesHandlerTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/MessagesHandlerTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/MessagesHandlerTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/MessagesHandlerTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,96 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * Implementation tests based on MessagesHandler + */ +class MessagesHandlerTest extends PHPUnit_Framework_TestCase { + + /** + * @var MessagesHandler + */ + private $MessagesHandler; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->MessagesHandler = new MessagesHandler(); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->MessagesHandler = null; + parent::tearDown(); + } + + /** + * Tests MessagesHandler->handleDelete() + */ + public function testHandleDelete() + { + $response = $this->MessagesHandler->handleDelete(new RestRequestItem()); + $this->assertEquals(NOT_IMPLEMENTED, $response->getError()); + $this->assertEquals("You can't delete messages", $response->getErrorMessage()); + } + + /** + * Tests MessagesHandler->handleGet() + */ + public function testHandleGet() + { + $response = $this->MessagesHandler->handleGet(new RestRequestItem()); + $this->assertEquals(NOT_IMPLEMENTED, $response->getError()); + $this->assertEquals("You can't retrieve messages", $response->getErrorMessage()); + } + + /** + * Tests MessagesHandler->handlePost() + */ + public function testHandlePost() + { + $response = $this->MessagesHandler->handlePost(new RestRequestItem()); + $this->assertEquals(NOT_IMPLEMENTED, $response->getError()); + $this->assertEquals("You can't edit messages", $response->getErrorMessage()); + } + + /** + * Tests MessagesHandler->handlePut() + */ + public function testHandlePut() + { + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + //Create message + $request = array(); + $request['url'] = '/messages/@viewer/outbox/1'; + $request['postData'] = 'message 1'; + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->MessagesHandler->handlePut($requestItem); + $this->assertEquals(NOT_IMPLEMENTED, $response->getError()); + $this->assertEquals("Not implemented", $response->getErrorMessage()); + } + +} +?> \ No newline at end of file Added: incubator/shindig/trunk/php/test/social-api/PeopleHandlerTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/PeopleHandlerTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/PeopleHandlerTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/PeopleHandlerTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,98 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * Implementation tests based on PeopleHandler + */ +class PeopleHandlerTest extends PHPUnit_Framework_TestCase { + + /** + * @var PeopleHandler + */ + private $PeopleHandler; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->PeopleHandler = new PeopleHandler(); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->PeopleHandler = null; + parent::tearDown(); + } + + /** + * Tests PeopleHandler->handleDelete() + */ + public function testHandleDelete() + { + $response = $this->PeopleHandler->handleDelete(new RestRequestItem()); + $this->assertEquals(BAD_REQUEST, $response->getError()); + $this->assertEquals("You can't delete people.", $response->getErrorMessage()); + } + + /** + * Tests PeopleHandler->handleGet() + */ + public function testHandleGet() + { + $request = array(); + $request['url'] = '/people/@viewer/@self'; + $request['method'] = 'GET'; + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + $requestItem = new RestRequestItem(); + $requestItem->createRequestItemWithRequest($request, $token); + $response = $this->PeopleHandler->handleGet($requestItem); + $person = $response->getResponse(); + $this->assertEquals('john.doe', $person['id']); + $this->assertEquals('MALE', $person['gender']['key']); + $this->assertEquals('Male', $person['gender']['displayValue']); + $this->assertEquals('Doe', $person['name']['familyName']); + $this->assertEquals('John', $person['name']['givenName']); + $this->assertEquals('John Doe', $person['name']['unstructured']); + } + + /** + * Tests PeopleHandler->handlePost() + */ + public function testHandlePost() + { + $response = $this->PeopleHandler->handlePost(new RestRequestItem()); + $this->assertEquals(NOT_IMPLEMENTED, $response->getError()); + $this->assertEquals("You can't edit people right now.", $response->getErrorMessage()); + } + + /** + * Tests PeopleHandler->handlePut() + */ + public function testHandlePut() + { + $response = $this->PeopleHandler->handlePut(new RestRequestItem()); + $this->assertEquals(NOT_IMPLEMENTED, $response->getError()); + $this->assertEquals("You can't add people right now.", $response->getErrorMessage()); + } +} Added: incubator/shindig/trunk/php/test/social-api/RestFulCollectionTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/RestFulCollectionTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/RestFulCollectionTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/RestFulCollectionTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,106 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * RestFulCollection test case. + */ +class RestFulCollectionTest extends PHPUnit_Framework_TestCase { + + /** + * @var RestFulCollection + */ + private $RestFulCollection; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->RestFulCollection = new RestFulCollection($entry, 1, 1); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->RestFulCollection = null; + parent::tearDown(); + } + + /** + * Constructs the test case. + */ + public function __construct() + { + } + + /** + * Tests RestFulCollection->__construct() + */ + public function test__construct() + { + $entry = array(); + $entry[] = "Entry"; + $this->RestFulCollection->__construct($entry, 1, 1); + } + + /** + * Tests RestFulCollection->getEntry() + */ + public function testGetEntry() + { + $entry = array(); + $entry[] = "Entry"; + $this->RestFulCollection->setEntry($entry); + $this->assertEquals($entry, $this->RestFulCollection->getEntry()); + } + + /** + * Tests RestFulCollection->getStartIndex() + */ + public function testGetStartIndex() + { + $this->RestFulCollection->setStartIndex(1); + $this->assertEquals(1, $this->RestFulCollection->getStartIndex()); + } + + /** + * Tests RestFulCollection->getTotalResults() + */ + public function testGetTotalResults() + { + $this->RestFulCollection->setTotalResults(1); + $this->assertEquals(1, $this->RestFulCollection->getTotalResults()); + } + + /** + * Tests RestFulCollection->createFromEntry() + */ + public function testCreateFromEntry() + { + $entry = array(); + $entry[] = "Entry"; + $restFulCollection = RestFulCollection::createFromEntry($entry); + $this->assertEquals(1, $restFulCollection->getTotalResults()); + $this->assertEquals($entry, $restFulCollection->getEntry()); + $this->assertEquals(0, $restFulCollection->getStartIndex()); + } +} Added: incubator/shindig/trunk/php/test/social-api/RestRequestItemTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/RestRequestItemTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/RestRequestItemTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/RestRequestItemTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,228 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * RestRequestItem test case. + */ +class RestRequestItemTest extends PHPUnit_Framework_TestCase { + + /** + * @var RestRequestItem + */ + private $RestRequestItem; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->RestRequestItem = new RestRequestItem(); + $url = '/people/@viewer/@self?fields=age,name,gender,profileUrl,thumbnailUrl,' . 'status,id&startIndex=0&count=40&orderBy=name&filterBy=all&networkDistance=1'; + $request = array(); + $request['url'] = $url; + $request['method'] = 'GET'; + $request['postData'] = array(); + $request['postData']['data'] = 'DataTest'; + $this->RestRequestItem->createRequestItemWithRequest($request, $this->getToken()); + + //(the getters of the parsedTemplate will be tested on other methods) + $this->RestRequestItem->parseUrlWithTemplate("/people/{userId}/{groupId}/{personId}"); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->RestRequestItem = null; + parent::tearDown(); + } + + /** + * Constructs the test case. + */ + public function __construct() + { + } + + private $token; + + private function getToken() + { + if (is_null($this->token)) { + $this->token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + } + return $this->token; + } + + /** + * Tests RestRequestItem->createRequestItemWithRequest() + */ + public function testCreateRequestItemWithRequest() + { + $url = '/people/@viewer/@self?fields=age,name,gender,profileUrl,thumbnailUrl,' . 'status,id&startIndex=0&count=40&orderBy=name&filterBy=all&networkDistance=1'; + $request = array(); + $request['url'] = $url; + $request['method'] = 'GET'; + $request['postData'] = array(); + $request['postData']['data'] = 'DataTest'; + $this->RestRequestItem->createRequestItemWithRequest($request, $this->getToken()); + + //Without the parseTemplate + $this->assertEquals($url, $this->RestRequestItem->getUrl()); + $this->assertEquals('0', $this->RestRequestItem->getAppId()); + $this->assertEquals(false, $this->RestRequestItem->getUser()); + $this->assertEquals(false, $this->RestRequestItem->getGroup()); + $this->assertEquals('0', $this->RestRequestItem->getStartIndex()); + $this->assertEquals('20', $this->RestRequestItem->getCount()); + $this->assertEquals(PeopleOptions::$sortOrder, $this->RestRequestItem->getOrderBy()); + $this->assertEquals(PeopleOptions::$filterType, $this->RestRequestItem->getFilterBy()); + $this->assertEquals(false, $this->RestRequestItem->getNetworkDistance()); + } + + /** + * Tests RestRequestItem->createRequestItem() + */ + public function testCreateRequestItem() + { + $url = '/people/@viewer/@self'; + $method = 'GET'; + $postData = array(); + $postData['data'] = 'DataTest'; + $params = array(); + $params['param1'] = 'DataParam1'; + $this->RestRequestItem->createRequestItem($url, $this->getToken(), $method, $params, $postData); + $this->assertEquals($url, $this->RestRequestItem->getUrl()); + $this->assertEquals($this->token, $this->RestRequestItem->getToken()); + $this->assertEquals($method, $this->RestRequestItem->getMethod()); + $this->assertEquals($params, $this->RestRequestItem->getParameters()); + $this->assertEquals($postData, $this->RestRequestItem->getPostData()); + } + + /** + * Tests RestRequestItem->getParameters() + */ + public function testGetParameters() + { + $parameters = $this->RestRequestItem->getParameters(); + $this->assertEquals('people', $parameters[0]); + $this->assertEquals('@viewer', $parameters[1]); + $this->assertEquals('@self', $parameters[2]); + } + + /** + * Tests RestRequestItem->getPostData() + */ + public function testGetPostData() + { + $postData = $this->RestRequestItem->getPostData(); + $this->assertEquals('DataTest', $postData['data']); + } + + /** + * Tests RestRequestItem->getToken() + */ + public function testGetToken() + { + $this->assertEquals($this->getToken(), $this->RestRequestItem->getToken()); + } + + /** + * Tests RestRequestItem->getMethod() + */ + public function testGetMethod() + { + $this->assertEquals('GET', $this->RestRequestItem->getMethod()); + } + + /** + * Tests RestRequestItem->getUrl() + */ + public function testGetUrl() + { + $this->assertEquals("/people/@viewer/@self", $this->RestRequestItem->getUrl()); + } + + /** + * Tests RestRequestItem->getAppId() + */ + public function testGetAppId() + { + $this->assertEquals('0', $this->RestRequestItem->getAppId()); + } + + /** + * Tests RestRequestItem->getUser() + */ + public function testGetUser() + { + $userId = $this->RestRequestItem->getUser(); + $this->assertEquals('viewer', $userId->getType()); + } + + /** + * Tests RestRequestItem->getGroup() + */ + public function testGetGroup() + { + $groupId = $this->RestRequestItem->getGroup(); + $this->assertEquals('self', $groupId->getType()); + } + + /** + * Tests RestRequestItem->getStartIndex() + */ + public function testGetStartIndex() + { + $this->assertEquals('0', $this->RestRequestItem->getStartIndex()); + } + + /** + * Tests RestRequestItem->getCount() + */ + public function testGetCount() + { + $this->assertEquals('40', $this->RestRequestItem->getCount()); + } + + /** + * Tests RestRequestItem->getOrderBy() + */ + public function testGetOrderBy() + { + $this->assertEquals('name', $this->RestRequestItem->getOrderBy()); + } + + /** + * Tests RestRequestItem->getFilterBy() + */ + public function testGetFilterBy() + { + $this->assertEquals('all', $this->RestRequestItem->getFilterBy()); + } + + /** + * Tests RestRequestItem->getNetworkDistance() + */ + public function testGetNetworkDistance() + { + $this->assertEquals('1', $this->RestRequestItem->getNetworkDistance()); + } +} Added: incubator/shindig/trunk/php/test/social-api/UserIdTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social-api/UserIdTest.php?rev=686073&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/social-api/UserIdTest.php (added) +++ incubator/shindig/trunk/php/test/social-api/UserIdTest.php Thu Aug 14 15:49:17 2008 @@ -0,0 +1,96 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * UserId test case. + */ +class UserIdTest extends PHPUnit_Framework_TestCase { + + /** + * @var UserId + */ + private $UserId; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->UserId = new UserId(UserId::$types[0], 1); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->UserId = null; + parent::tearDown(); + } + + /** + * Constructs the test case. + */ + public function __construct() + { + } + + /** + * Tests UserId->__construct() + */ + public function test__construct() + { + $this->UserId->__construct(UserId::$types[0], 1); //viewer + } + + /** + * Tests UserId->getUserId() + */ + public function testGetUserId() + { + $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1'); + $userId = $this->UserId->getUserId($token); + $this->assertEquals('john.doe', $userId); + $this->UserId->__construct(UserId::$types[1], 1); //owner + $userId = $this->UserId->getUserId($token); + $this->assertEquals('john.doe', $userId); + $this->UserId->__construct(UserId::$types[2], 1); //userId + $userId = $this->UserId->getUserId($token); + $this->assertEquals('1', $userId); + } + + /** + * Tests UserId->getType() + */ + public function testGetType() + { + $this->assertEquals('viewer', $this->UserId->getType()); + } + + /** + * Tests UserId->fromJson() + */ + public function testFromJson() + { + $json = 'jsonid'; + $fromJson = $this->UserId->fromJson($json); + $this->assertEquals('userId', $fromJson->getType()); + } +}