PlusTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * Copyright 2011 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. class PlusTest extends BaseTest
  18. {
  19. /** @var Google_PlusService */
  20. public $plus;
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->plus = new Google_Service_Plus($this->getClient());
  25. }
  26. public function testGetPerson()
  27. {
  28. $this->checkToken();
  29. $person = $this->plus->people->get("118051310819094153327");
  30. $this->assertArrayHasKey('kind', $person);
  31. $this->assertArrayHasKey('displayName', $person);
  32. $this->assertArrayHasKey('gender', $person);
  33. $this->assertArrayHasKey('id', $person);
  34. }
  35. public function testListActivities()
  36. {
  37. $this->checkToken();
  38. $activities = $this->plus->activities
  39. ->listActivities("118051310819094153327", "public");
  40. $this->assertArrayHasKey('kind', $activities);
  41. $this->assertGreaterThan(0, count($activities));
  42. // Test a variety of access methods.
  43. $this->assertItem($activities['items'][0]);
  44. $this->assertItem($activities[0]);
  45. foreach ($activities as $item) {
  46. $this->assertItem($item);
  47. break;
  48. }
  49. // Test deeper type transformations
  50. $this->assertGreaterThan(0, strlen($activities[0]->actor->displayName));
  51. }
  52. public function assertItem($item)
  53. {
  54. // assertArrayHasKey uses array_key_exists, which is not great:
  55. // it doesn't understand SPL ArrayAccess
  56. $this->assertTrue(isset($item['actor']));
  57. $this->assertInstanceOf('Google_Service_Plus_ActivityActor', $item->actor);
  58. $this->assertTrue(isset($item['actor']['displayName']));
  59. $this->assertTrue(isset($item['actor']->url));
  60. $this->assertTrue(isset($item['object']));
  61. $this->assertTrue(isset($item['access']));
  62. $this->assertTrue(isset($item['provider']));
  63. }
  64. }