ApiModelTest

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

Defined (1)

The class is defined in the following location(s).

/lib/vendor/google/apiclient/tests/general/ApiModelTest.php  
  1. class ApiModelTest extends BaseTest 
  2. public function testModelMutation() 
  3. $htmlLink = 'https://www.google.com/calendar/event?' 
  4. . 'eid=NWdpMmFjNDkzbm5yZzh2N2poZXNhZmdldDggaWFuLmJhcmJlckBt'; 
  5. $data = json_decode( 
  6. '{ 
  7. "kind": "calendar#event",  
  8. "etag": "\"-kteSF26GsdKQ5bfmcd4H3_-u3g/MTE0NTUyNTAxOTk0MjAwMA\"",  
  9. "id": "1234566",  
  10. "status": "confirmed",  
  11. "htmlLink": "' . $htmlLink . '",  
  12. "created": "2006-04-13T14:22:08.000Z",  
  13. "updated": "2006-04-20T09:23:39.942Z",  
  14. "summary": "Evening Jolt Q3 CTFL",  
  15. "description": "6.30 - Adminning\n9.30 - Game",  
  16. "creator": { 
  17. "email": "ian@example.com",  
  18. "displayName": "Ian Test",  
  19. "self": true 
  20. },  
  21. "organizer": { 
  22. "email": "ian@example.com",  
  23. "displayName": "Ian Test",  
  24. "self": true 
  25. },  
  26. "start": { 
  27. "date": "2006-04-23" 
  28. },  
  29. "end": { 
  30. "date": "2006-04-24" 
  31. },  
  32. "iCalUID": "5gi2ac493nnrfdfd7jhesafget8@google.com",  
  33. "sequence": 0,  
  34. "reminders": { 
  35. "useDefault": false 
  36. }',  
  37. true 
  38. ); 
  39. $event = new Google_Service_Calendar_Event($data); 
  40. $date = new Google_Service_Calendar_EventDateTime(); 
  41. date_default_timezone_set('UTC'); 
  42. $dateString = Date("c"); 
  43. $summary = "hello"; 
  44. $date->setDate($dateString); 
  45. $event->setStart($date); 
  46. $event->setEnd($date); 
  47. $event->setSummary($summary); 
  48. $simpleEvent = $event->toSimpleObject(); 
  49. $this->assertEquals($dateString, $simpleEvent->start->date); 
  50. $this->assertEquals($dateString, $simpleEvent->end->date); 
  51. $this->assertEquals($summary, $simpleEvent->summary); 
  52.  
  53. $event2 = new Google_Service_Calendar_Event(); 
  54. $this->assertNull($event2->getStart()); 
  55.  
  56. public function testOddMappingNames() 
  57. $creative = new Google_Service_AdExchangeBuyer_Creative(); 
  58. $creative->setAccountId('12345'); 
  59. $creative->setBuyerCreativeId('12345'); 
  60. $creative->setAdvertiserName('Hi'); 
  61. $creative->setHTMLSnippet("<p>Foo!</p>"); 
  62. $creative->setClickThroughUrl(array('http://somedomain.com')); 
  63. $creative->setWidth(100); 
  64. $creative->setHeight(100); 
  65. $data = json_decode(json_encode($creative->toSimpleObject()), true); 
  66. $this->assertEquals($data['HTMLSnippet'], "<p>Foo!</p>"); 
  67. $this->assertEquals($data['width'], 100); 
  68. $this->assertEquals($data['height'], 100); 
  69. $this->assertEquals($data['accountId'], "12345"); 
  70.  
  71. public function testJsonStructure() 
  72. $model = new Google_Model(); 
  73. $model->publicA = "This is a string"; 
  74. $model2 = new Google_Model(); 
  75. $model2->publicC = 12345; 
  76. $model2->publicD = null; 
  77. $model->publicB = $model2; 
  78. $model3 = new Google_Model(); 
  79. $model3->publicE = 54321; 
  80. $model3->publicF = null; 
  81. $model->publicG = array($model3, "hello", false); 
  82. $model->publicH = false; 
  83. $model->publicI = 0; 
  84. $string = json_encode($model->toSimpleObject()); 
  85. $data = json_decode($string, true); 
  86. $this->assertEquals(12345, $data['publicB']['publicC']); 
  87. $this->assertEquals("This is a string", $data['publicA']); 
  88. $this->assertArrayNotHasKey("publicD", $data['publicB']); 
  89. $this->assertArrayHasKey("publicE", $data['publicG'][0]); 
  90. $this->assertArrayNotHasKey("publicF", $data['publicG'][0]); 
  91. $this->assertEquals("hello", $data['publicG'][1]); 
  92. $this->assertEquals(false, $data['publicG'][2]); 
  93. $this->assertArrayNotHasKey("data", $data); 
  94. $this->assertEquals(false, $data['publicH']); 
  95. $this->assertEquals(0, $data['publicI']); 
  96.  
  97. public function testIssetPropertyOnModel() 
  98. $model = new Google_Model(); 
  99. $model['foo'] = 'bar'; 
  100. $this->assertTrue(isset($model->foo)); 
  101.  
  102. public function testUnsetPropertyOnModel() 
  103. $model = new Google_Model(); 
  104. $model['foo'] = 'bar'; 
  105. unset($model->foo); 
  106. $this->assertFalse(isset($model->foo)); 
  107.  
  108. public function testCollection() 
  109. $data = json_decode( 
  110. '{ 
  111. "kind": "calendar#events",  
  112. "id": "1234566",  
  113. "etag": "abcdef",  
  114. "totalItems": 4,  
  115. "items": [ 
  116. {"id": 1},  
  117. {"id": 2},  
  118. {"id": 3},  
  119. {"id": 4} 
  120. }', true); 
  121. $collection = new Google_Service_Calendar_Events($data); 
  122. $this->assertEquals(4, count($collection)); 
  123. $count = 0; 
  124. foreach ($collection as $col) { 
  125. $count++; 
  126. $this->assertEquals(4, $count); 
  127. $this->assertEquals(1, $collection[0]->id);