TasksTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 TasksTest extends BaseTest
  18. {
  19. /** @var Google_TasksService */
  20. public $taskService;
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->taskService = new Google_Service_Tasks($this->getClient());
  25. }
  26. public function testInsertTask()
  27. {
  28. if (!$this->checkToken()) {
  29. return;
  30. }
  31. $list = $this->createTaskList('List: ' . __METHOD__);
  32. $task = $this->createTask('Task: '.__METHOD__, $list->id);
  33. $this->assertIsTask($task);
  34. }
  35. /**
  36. * @depends testInsertTask
  37. */
  38. public function testGetTask()
  39. {
  40. $tasks = $this->taskService->tasks;
  41. $list = $this->createTaskList('List: ' . __METHOD__);
  42. $task = $this->createTask('Task: '. __METHOD__, $list['id']);
  43. $task = $tasks->get($list['id'], $task['id']);
  44. $this->assertIsTask($task);
  45. }
  46. /**
  47. * @depends testInsertTask
  48. */
  49. public function testListTask()
  50. {
  51. $tasks = $this->taskService->tasks;
  52. $list = $this->createTaskList('List: ' . __METHOD__);
  53. for ($i=0; $i<4; $i++) {
  54. $this->createTask("Task: $i ".__METHOD__, $list['id']);
  55. }
  56. $tasksArray = $tasks->listTasks($list['id']);
  57. $this->assertTrue(sizeof($tasksArray) > 1);
  58. foreach ($tasksArray['items'] as $task) {
  59. $this->assertIsTask($task);
  60. }
  61. }
  62. private function createTaskList($name)
  63. {
  64. $list = new Google_Service_Tasks_TaskList();
  65. $list->title = $name;
  66. return $this->taskService->tasklists->insert($list);
  67. }
  68. private function createTask($title, $listId)
  69. {
  70. $tasks = $this->taskService->tasks;
  71. $task = new Google_Service_Tasks_Task();
  72. $task->title = $title;
  73. return $tasks->insert($listId, $task);
  74. }
  75. private function assertIsTask($task)
  76. {
  77. $this->assertArrayHasKey('title', $task);
  78. $this->assertArrayHasKey('kind', $task);
  79. $this->assertArrayHasKey('id', $task);
  80. $this->assertArrayHasKey('position', $task);
  81. }
  82. }