Merge branch 'master' of http://git.tine20.org/git/Syncope
[tine20] / tine20 / library / Syncope / tests / Syncope / Command / GetItemEstimateTests.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Tests
6  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
7  * @copyright   Copyright (c) 2010-2011 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Cornelius Weiss <c.weiss@metaways.de>
9  */
10
11 /**
12  * Test class for FolderSync_Controller_Event
13  * 
14  * @package     Tests
15  */
16 class Syncope_Command_GetItemEstimateTests extends Syncope_Command_ATestCase
17 {
18     #protected $_logPriority = Zend_Log::DEBUG;
19     
20     /**
21      * Runs the test methods of this class.
22      *
23      * @access public
24      * @static
25      */
26     public static function main()
27     {
28         $suite  = new PHPUnit_Framework_TestSuite('ActiveSync GetItemEstimate command tests');
29         PHPUnit_TextUI_TestRunner::run($suite);
30     }
31     
32     /**
33      * 
34      */
35     public function _testGetItemEstimateWithInvalidFolder()
36     {
37         $doc = new DOMDocument();
38         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
39             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
40             <GetItemEstimate xmlns="uri:ItemEstimate" xmlns:AirSync="uri:AirSync"><Collections><Collection><AirSync:FilterType>0</AirSync:FilterType><AirSync:SyncKey>0</AirSync:SyncKey><Class>Contacts</Class><CollectionId>1212</CollectionId></Collection></Collections></GetItemEstimate>'
41         );
42         
43         $search = new Syncope_Command_GetItemEstimate($doc, $this->_device, null);
44         
45         $search->handle();
46         
47         $responseDoc = $search->getResponse();
48         $responseDoc->formatOutput = true; echo $responseDoc->saveXML();
49         
50         $xpath = new DomXPath($responseDoc);
51         $xpath->registerNamespace('ItemEstimate', 'uri:ItemEstimate');
52         
53         $nodes = $xpath->query('//ItemEstimate:GetItemEstimate/ItemEstimate:Response/ItemEstimate:Status');
54         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
55         $this->assertEquals(Syncope_Command_GetItemEstimate::STATUS_INVALID_COLLECTION, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
56     }
57         
58     /**
59      * 
60      */
61     public function testGetItemEstimate()
62     {
63         // first do a foldersync
64         $doc = new DOMDocument();
65         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
66             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
67             <FolderSync xmlns="uri:FolderHierarchy"><SyncKey>0</SyncKey></FolderSync>'
68         );
69         $folderSync = new Syncope_Command_FolderSync($doc, $this->_device, $this->_device->policykey);
70         $folderSync->handle();
71         $folderSync->getResponse();
72         
73         // and now we can start the ping request
74         $doc = new DOMDocument();
75         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
76             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
77             <GetItemEstimate xmlns="uri:ItemEstimate" xmlns:AirSync="uri:AirSync"><Collections><Collection><AirSync:FilterType>0</AirSync:FilterType><AirSync:SyncKey>0</AirSync:SyncKey><Class>Contacts</Class><CollectionId>addressbookFolderId</CollectionId></Collection></Collections></GetItemEstimate>'
78         );
79                 
80         $search = new Syncope_Command_GetItemEstimate($doc, $this->_device, null);
81         $search->handle();
82         $responseDoc = $search->getResponse();
83         #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
84         
85         $xpath = new DomXPath($responseDoc);
86         $xpath->registerNamespace('ItemEstimate', 'uri:ItemEstimate');
87         
88         $nodes = $xpath->query('//ItemEstimate:GetItemEstimate/ItemEstimate:Response/ItemEstimate:Status');
89         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
90         $this->assertEquals(Syncope_Command_GetItemEstimate::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
91                 
92         $nodes = $xpath->query('//ItemEstimate:GetItemEstimate/ItemEstimate:Response/ItemEstimate:Collection/ItemEstimate:Estimate');
93         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
94         $this->assertEquals(10, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
95         
96     }    
97 }