ActiveSync - add Json FE remoteResetDevices
[tine20] / tests / tine20 / ActiveSync / Frontend / JsonTests.php
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) 2015-2017 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Philipp Schüle <p.schuele@metaways.de>
9  */
10
11 /**
12  * Test class for ActiveSync_Frontend_Json
13  * 
14  * @package     ActiveSync
15  */
16 class ActiveSync_Frontend_JsonTests extends ActiveSync_TestCase
17 {
18     /**
19      * lazy init of uit
20      *
21      * @return ActiveSync_Frontend_Json
22      */
23     protected function _getUit()
24     {
25         /** @var ActiveSync_Frontend_Json $uit */
26         $uit = parent::_getUit();
27         return $uit;
28     }
29     
30     /**
31      * Search for records matching given arguments
32      */
33     public function testSearchSyncDevices()
34     {
35         $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE);
36         
37         $result = $this->_getUit()->searchSyncDevices(array(), array());
38         
39         $this->assertEquals(1, $result['totalcount']);
40         $this->assertEquals('iphone-abcd', $result['results'][0]['deviceid'], print_r($result['results'], true));
41     }
42     
43     /**
44      * deletes existing records
45      */
46     public function testDeleteSyncDevices()
47     {
48         $device = $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE);
49         $this->_getUit()->deleteSyncDevices(array($device->id));
50         $result = $this->_getUit()->searchSyncDevices(array(), array());
51         
52         $this->assertEquals(0, $result['totalcount']);
53     }
54     
55     /**
56      * Return a single record
57      * 
58      * @return array
59      */
60     public function testGetSyncDevice()
61     {
62         $device = $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE);
63         $fetchedDevice = $this->_getUit()->getSyncDevice($device->id);
64         
65         $this->assertTrue(is_array($fetchedDevice['owner_id']), print_r($fetchedDevice, true));
66         $this->assertEquals($this->_testUser->getId(), $fetchedDevice['owner_id']['accountId'], print_r($fetchedDevice['owner_id'], true));
67         
68         return $fetchedDevice;
69     }
70     
71     /**
72      * updates a record
73      */
74     public function testSaveSyncDevice()
75     {
76         $uit = $this->_getUit();
77         $device = $this->testGetSyncDevice();
78         
79         $device['friendlyname'] = 'Very friendly name';
80         $device['owner_id'] = $device['owner_id']['accountId'];
81         $device['remotewipe'] = 1;
82         $updatedDevice = $uit->saveSyncDevice($device);
83
84         static::assertEquals($device['friendlyname'], $updatedDevice['friendlyname']);
85         static::assertEquals(0, $updatedDevice['remotewipe']);
86
87
88         $result = $uit->remoteResetDevices(array($updatedDevice['id']));
89         static::assertTrue(is_array($result) && isset($result['success']) && true === $result['success'] &&
90             count($result) === 1, 'result of remoteResetDevices should be array(\'success\' => true)');
91
92         $fetchedDevice = $uit->getSyncDevice($updatedDevice['id']);
93         static::assertEquals(1, $fetchedDevice['remotewipe'], 'remote wipe not set successfully!');
94
95         $catched = false;
96         try {
97             unset($updatedDevice['id']);
98             $uit->saveSyncDevice($updatedDevice);
99         } catch (Tinebase_Exception_AccessDenied $tead) {
100             $catched = true;
101         }
102         static::assertTrue($catched, 'misuse of saveSyncDevice to create a new device must not be possible');
103     }
104 }