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

/tests/Sabre/CardDAV/AddressBookQueryTest.php

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