PageRenderTime 29ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/tine20/ActiveSync/Controller/ControllerTest.php

https://github.com/corneliusweiss/Tine-2.0-Open-Source-Groupware-and-CRM
PHP | 266 lines | 137 code | 58 blank | 71 comment | 1 complexity | 9b739f32dffdd15a5b0bfd674d52b433 MD5 | raw file
  1. <?php
  2. /**
  3. * Tine 2.0 - http://www.tine20.org
  4. *
  5. * @package ActiveSync
  6. * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
  7. * @copyright Copyright (c) 2010-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  8. * @author Lars Kneschke <l.kneschke@metaways.de>
  9. */
  10. /**
  11. * abstract test class for activesync controller tests
  12. *
  13. * @package ActiveSync
  14. */
  15. abstract class ActiveSync_Controller_ControllerTest extends ActiveSync_TestCase
  16. {
  17. /**
  18. * name of the controller
  19. *
  20. * @var string
  21. */
  22. protected $_controllerName;
  23. /**
  24. * @var ActiveSync_Controller_Abstract controller
  25. */
  26. protected $_controller;
  27. /**
  28. *
  29. * @return Syncroton_Model_Folder
  30. */
  31. public function testCreateFolder()
  32. {
  33. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), new Tinebase_DateTime(null, null, 'de_DE'));
  34. $syncrotonFolder = $controller->createFolder(new Syncroton_Model_Folder(array(
  35. 'parentId' => 0,
  36. 'displayName' => 'TestFolder'
  37. )));
  38. $this->assertTrue(!empty($syncrotonFolder->serverId));
  39. return $syncrotonFolder;
  40. }
  41. /**
  42. * testUpdateFolder (iPhone)
  43. *
  44. * @return Syncroton_Model_Folder
  45. */
  46. public function testUpdateFolder()
  47. {
  48. return $this->_testUpdateFolderForDeviceType(Syncroton_Model_Device::TYPE_IPHONE);
  49. }
  50. /**
  51. * @param string $type
  52. * @return Syncroton_Model_Folder
  53. */
  54. protected function _testUpdateFolderForDeviceType($type)
  55. {
  56. $syncrotonFolder = $this->testCreateFolder();
  57. $syncrotonFolder->displayName = 'RenamedTestFolder';
  58. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice($type), new Tinebase_DateTime(null, null, 'de_DE'));
  59. $updatedSyncrotonFolder = $controller->updateFolder($syncrotonFolder);
  60. $allFolders = $controller->getAllFolders();
  61. $this->assertArrayHasKey($syncrotonFolder->serverId, $allFolders);
  62. $this->assertEquals('RenamedTestFolder', $allFolders[$syncrotonFolder->serverId]->displayName);
  63. return $updatedSyncrotonFolder;
  64. }
  65. /**
  66. * @return Syncroton_Model_Folder
  67. */
  68. public function testUpdateFolderAndroid()
  69. {
  70. return $this->_testUpdateFolderForDeviceType(self::TYPE_ANDROID_6);
  71. }
  72. /**
  73. * @return Syncroton_Model_Folder
  74. */
  75. public function testUpdateFolderOldAndroid()
  76. {
  77. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_ANDROID), new Tinebase_DateTime(null, null, 'de_DE'));
  78. $syncrotonFolders = $controller->getAllFolders();
  79. self::assertTrue(isset($syncrotonFolders[$this->_specialFolderName]), 'could not find ' . $this->_specialFolderName);
  80. try {
  81. $controller->updateFolder($syncrotonFolders[$this->_specialFolderName]);
  82. self::fail('expected Syncroton_Exception_UnexpectedValue expcetion');
  83. } catch (Exception $e) {
  84. self::assertTrue($e instanceof Syncroton_Exception_UnexpectedValue, $e);
  85. }
  86. }
  87. /**
  88. * test if changed folders got returned
  89. */
  90. public function testGetChangedFolders()
  91. {
  92. $syncrotonFolder = $this->testUpdateFolder();
  93. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), new Tinebase_DateTime(null, null, 'de_DE'));
  94. $changedFolders = $controller->getChangedFolders(Tinebase_DateTime::now()->subMinute(1), Tinebase_DateTime::now());
  95. $this->assertGreaterThanOrEqual(1, count($changedFolders));
  96. $this->assertArrayHasKey($syncrotonFolder->serverId, $changedFolders);
  97. }
  98. public function testDeleteFolder()
  99. {
  100. $syncrotonFolder = $this->testCreateFolder();
  101. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), new Tinebase_DateTime(null, null, 'de_DE'));
  102. $controller->deleteFolder($syncrotonFolder);
  103. }
  104. public function testGetAllFoldersIPhone()
  105. {
  106. $this->_testGetAllFoldersForDeviceType(Syncroton_Model_Device::TYPE_IPHONE);
  107. }
  108. /**
  109. * get all folders test for given device type
  110. *
  111. * @param $type
  112. */
  113. protected function _testGetAllFoldersForDeviceType($type)
  114. {
  115. $syncrotonFolder = $this->testCreateFolder();
  116. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice($type),
  117. new Tinebase_DateTime(null, null, 'de_DE'));
  118. $allSyncrotonFolders = $controller->getAllFolders();
  119. $this->assertArrayHasKey($syncrotonFolder->serverId, $allSyncrotonFolders);
  120. $this->assertArrayNotHasKey($this->_specialFolderName, $allSyncrotonFolders);
  121. $this->assertTrue($allSyncrotonFolders[$syncrotonFolder->serverId] instanceof Syncroton_Model_Folder);
  122. $this->assertEquals($syncrotonFolder->serverId, $allSyncrotonFolders[$syncrotonFolder->serverId]->serverId, 'serverId mismatch');
  123. $this->assertEquals($syncrotonFolder->parentId, $allSyncrotonFolders[$syncrotonFolder->serverId]->parentId, 'parentId mismatch');
  124. $this->assertEquals($syncrotonFolder->displayName, $allSyncrotonFolders[$syncrotonFolder->serverId]->displayName);
  125. $this->assertTrue(!empty($allSyncrotonFolders[$syncrotonFolder->serverId]->type));
  126. }
  127. public function testGetAllFoldersPalm()
  128. {
  129. $syncrotonFolder = $this->testCreateFolder();
  130. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_WEBOS), new Tinebase_DateTime(null, null, 'de_DE'));
  131. $allSyncrotonFolders = $controller->getAllFolders();
  132. $this->assertArrayHasKey($this->_specialFolderName, $allSyncrotonFolders, "key {$this->_specialFolderName} not found in " . print_r($allSyncrotonFolders, true));
  133. }
  134. /**
  135. * @see 0012634: ActiveSync: Add android to multiple folders devices
  136. */
  137. public function testGetAllFoldersAndroid()
  138. {
  139. $this->_testGetAllFoldersForDeviceType(self::TYPE_ANDROID_6);
  140. }
  141. /**
  142. * testDeleteEntry
  143. */
  144. public function testDeleteEntry()
  145. {
  146. $syncrotonFolder = $this->testCreateFolder();
  147. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), new Tinebase_DateTime(null, null, 'de_DE'));
  148. list($serverId, $syncrotonContact) = $this->testCreateEntry($syncrotonFolder);
  149. $controller->deleteEntry($syncrotonFolder->serverId, $serverId, null);
  150. try {
  151. $syncrotonContact = $controller->getEntry(new Syncroton_Model_SyncCollection(array('collectionId' => $syncrotonFolder->serverId)), $serverId);
  152. $this->fail('should have thrown Syncroton_Exception_NotFound: '
  153. . var_export($syncrotonContact, TRUE)
  154. . ' tine contact: ' . print_r(Addressbook_Controller_Contact::getInstance()->get($serverId)->toArray(), TRUE));
  155. } catch (Syncroton_Exception_NotFound $senf) {
  156. $this->assertEquals('Syncroton_Exception_NotFound', get_class($senf));
  157. }
  158. }
  159. public function testGetInvalidEntry()
  160. {
  161. $syncrotonFolder = $this->testCreateFolder();
  162. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), new Tinebase_DateTime(null, null, 'de_DE'));
  163. $this->setExpectedException('Syncroton_Exception_NotFound');
  164. $syncrotonContact = $controller->getEntry(new Syncroton_Model_SyncCollection(array('collectionId' => $syncrotonFolder->serverId)), 'jdszfegd63gfrk');
  165. }
  166. /**
  167. * test get changed entries
  168. */
  169. public function testGetChangedEntries()
  170. {
  171. $syncrotonFolder = $this->testCreateFolder();
  172. list($serverId, $syncrotonContact) = $this->testUpdateEntry($syncrotonFolder);
  173. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), new Tinebase_DateTime(null, null, 'de_DE'));
  174. $changedEntries = $controller->getChangedEntries($syncrotonFolder->serverId, new DateTime('2000-01-01'));
  175. $this->assertContains($serverId, $changedEntries, 'did not get changed record id in ' . print_r($changedEntries, TRUE));
  176. }
  177. /**
  178. * test get changed entries for android
  179. */
  180. public function testGetChangedEntriesAndroid()
  181. {
  182. $syncrotonFolder = $this->testCreateFolder();
  183. list($serverId, $syncrotonContact) = $this->testUpdateEntry($syncrotonFolder);
  184. $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_ANDROID), Tinebase_DateTime::now());
  185. $changedEntries = $controller->getChangedEntries($this->_specialFolderName, new Tinebase_DateTime('2000-01-01'));
  186. $this->assertContains($serverId, $changedEntries, 'did not get changed record id in ' . print_r($changedEntries, TRUE));
  187. }
  188. /**
  189. * test convert from XML to Tine 2.0 model
  190. */
  191. abstract public function testCreateEntry($syncrotonFolder = null);
  192. /**
  193. * test xml generation for sync to client
  194. */
  195. abstract public function testUpdateEntry($syncrotonFolder = null);
  196. /**
  197. * get application activesync controller
  198. *
  199. * @param ActiveSync_Model_Device $_device
  200. */
  201. protected function _getController(ActiveSync_Model_Device $_device)
  202. {
  203. if ($this->_controller === null) {
  204. $this->_controller = Syncroton_Data_Factory::factory($this->_class, $_device, new Tinebase_DateTime(null, null, 'de_DE'));
  205. }
  206. return $this->_controller;
  207. }
  208. }