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).

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