PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Sabre/CardDAV/AddressBookQueryTest.php

https://github.com/agilastic/sabre-dav
PHP | 192 lines | 136 code | 52 blank | 4 comment | 0 complexity | 2fcd85ea8158ca241e2696c86e559285 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Sabre\CardDAV;
  3. use Sabre\HTTP;
  4. use Sabre\DAV;
  5. require_once 'Sabre/CardDAV/AbstractPluginTest.php';
  6. require_once 'Sabre/HTTP/ResponseMock.php';
  7. class AddressBookQueryTest extends AbstractPluginTest {
  8. function testQuery() {
  9. $request = HTTP\Request::createFromServerArray(array(
  10. 'REQUEST_METHOD' => 'REPORT',
  11. 'REQUEST_URI' => '/addressbooks/user1/book1',
  12. 'HTTP_DEPTH' => '1',
  13. ));
  14. $request->setBody(
  15. '<?xml version="1.0"?>
  16. <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
  17. <d:prop>
  18. <d:getetag />
  19. </d:prop>
  20. <c:filter>
  21. <c:prop-filter name="uid" />
  22. </c:filter>
  23. </c:addressbook-query>'
  24. );
  25. $response = new HTTP\ResponseMock();
  26. $this->server->httpRequest = $request;
  27. $this->server->httpResponse = $response;
  28. $this->server->exec();
  29. $this->assertEquals('207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
  30. // using the client for parsing
  31. $client = new DAV\Client(array('baseUri'=>'/'));
  32. $result = $client->parseMultiStatus($response->body);
  33. $this->assertEquals(array(
  34. '/addressbooks/user1/book1/card1' => array(
  35. 200 => array(
  36. '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
  37. ),
  38. ),
  39. '/addressbooks/user1/book1/card2' => array(
  40. 404 => array(
  41. '{DAV:}getetag' => null,
  42. ),
  43. )
  44. ), $result);
  45. }
  46. function testQueryDepth0() {
  47. $request = HTTP\Request::createFromServerArray(array(
  48. 'REQUEST_METHOD' => 'REPORT',
  49. 'REQUEST_URI' => '/addressbooks/user1/book1/card1',
  50. 'HTTP_DEPTH' => '0',
  51. ));
  52. $request->setBody(
  53. '<?xml version="1.0"?>
  54. <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
  55. <d:prop>
  56. <d:getetag />
  57. </d:prop>
  58. <c:filter>
  59. <c:prop-filter name="uid" />
  60. </c:filter>
  61. </c:addressbook-query>'
  62. );
  63. $response = new HTTP\ResponseMock();
  64. $this->server->httpRequest = $request;
  65. $this->server->httpResponse = $response;
  66. $this->server->exec();
  67. $this->assertEquals('207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
  68. // using the client for parsing
  69. $client = new DAV\Client(array('baseUri'=>'/'));
  70. $result = $client->parseMultiStatus($response->body);
  71. $this->assertEquals(array(
  72. '/addressbooks/user1/book1/card1' => array(
  73. 200 => array(
  74. '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
  75. ),
  76. ),
  77. ), $result);
  78. }
  79. function testQueryNoMatch() {
  80. $request = HTTP\Request::createFromServerArray(array(
  81. 'REQUEST_METHOD' => 'REPORT',
  82. 'REQUEST_URI' => '/addressbooks/user1/book1',
  83. 'HTTP_DEPTH' => '1',
  84. ));
  85. $request->setBody(
  86. '<?xml version="1.0"?>
  87. <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
  88. <d:prop>
  89. <d:getetag />
  90. </d:prop>
  91. <c:filter>
  92. <c:prop-filter name="email" />
  93. </c:filter>
  94. </c:addressbook-query>'
  95. );
  96. $response = new HTTP\ResponseMock();
  97. $this->server->httpRequest = $request;
  98. $this->server->httpResponse = $response;
  99. $this->server->exec();
  100. $this->assertEquals('207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
  101. // using the client for parsing
  102. $client = new DAV\Client(array('baseUri'=>'/'));
  103. $result = $client->parseMultiStatus($response->body);
  104. $this->assertEquals(array(), $result);
  105. }
  106. function testQueryLimit() {
  107. $request = HTTP\Request::createFromServerArray(array(
  108. 'REQUEST_METHOD' => 'REPORT',
  109. 'REQUEST_URI' => '/addressbooks/user1/book1',
  110. 'HTTP_DEPTH' => '1',
  111. ));
  112. $request->setBody(
  113. '<?xml version="1.0"?>
  114. <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
  115. <d:prop>
  116. <d:getetag />
  117. </d:prop>
  118. <c:filter>
  119. <c:prop-filter name="uid" />
  120. </c:filter>
  121. <c:limit><c:nresults>1</c:nresults></c:limit>
  122. </c:addressbook-query>'
  123. );
  124. $response = new HTTP\ResponseMock();
  125. $this->server->httpRequest = $request;
  126. $this->server->httpResponse = $response;
  127. $this->server->exec();
  128. $this->assertEquals('207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
  129. // using the client for parsing
  130. $client = new DAV\Client(array('baseUri'=>'/'));
  131. $result = $client->parseMultiStatus($response->body);
  132. $this->assertEquals(array(
  133. '/addressbooks/user1/book1/card1' => array(
  134. 200 => array(
  135. '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"',
  136. ),
  137. ),
  138. ), $result);
  139. }
  140. }