PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php

http://github.com/evert/SabreDAV
PHP | 131 lines | 90 code | 41 blank | 0 comment | 1 complexity | 3cb773dd0c6eab96e4f1284abc7fd1a1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. require_once 'Sabre/HTTP/ResponseMock.php';
  3. require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
  4. class Sabre_DAVACL_PrincipalSearchPropertySetTest extends PHPUnit_Framework_TestCase {
  5. function getServer() {
  6. $backend = new Sabre_DAVACL_MockPrincipalBackend();
  7. $dir = new Sabre_DAV_SimpleCollection('root');
  8. $principals = new Sabre_DAVACL_PrincipalCollection($backend);
  9. $dir->addChild($principals);
  10. $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree($dir));
  11. $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock();
  12. $plugin = new Sabre_DAVACL_Plugin($backend,'realm');
  13. $this->assertTrue($plugin instanceof Sabre_DAVACL_Plugin);
  14. $fakeServer->addPlugin($plugin);
  15. $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
  16. return $fakeServer;
  17. }
  18. function testDepth1() {
  19. $xml = '<?xml version="1.0"?>
  20. <d:principal-search-property-set xmlns:d="DAV:" />';
  21. $serverVars = array(
  22. 'REQUEST_METHOD' => 'REPORT',
  23. 'HTTP_DEPTH' => '1',
  24. 'REQUEST_URI' => '/principals',
  25. );
  26. $request = new Sabre_HTTP_Request($serverVars);
  27. $request->setBody($xml);
  28. $server = $this->getServer();
  29. $server->httpRequest = $request;
  30. $server->exec();
  31. $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status);
  32. $this->assertEquals(array(
  33. 'Content-Type' => 'application/xml; charset=utf-8',
  34. ), $server->httpResponse->headers);
  35. }
  36. function testDepthIncorrectXML() {
  37. $xml = '<?xml version="1.0"?>
  38. <d:principal-search-property-set xmlns:d="DAV:"><d:ohell /></d:principal-search-property-set>';
  39. $serverVars = array(
  40. 'REQUEST_METHOD' => 'REPORT',
  41. 'HTTP_DEPTH' => '0',
  42. 'REQUEST_URI' => '/principals',
  43. );
  44. $request = new Sabre_HTTP_Request($serverVars);
  45. $request->setBody($xml);
  46. $server = $this->getServer();
  47. $server->httpRequest = $request;
  48. $server->exec();
  49. $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status, $server->httpResponse->body);
  50. $this->assertEquals(array(
  51. 'Content-Type' => 'application/xml; charset=utf-8',
  52. ), $server->httpResponse->headers);
  53. }
  54. function testCorrect() {
  55. $xml = '<?xml version="1.0"?>
  56. <d:principal-search-property-set xmlns:d="DAV:"/>';
  57. $serverVars = array(
  58. 'REQUEST_METHOD' => 'REPORT',
  59. 'HTTP_DEPTH' => '0',
  60. 'REQUEST_URI' => '/principals',
  61. );
  62. $request = new Sabre_HTTP_Request($serverVars);
  63. $request->setBody($xml);
  64. $server = $this->getServer();
  65. $server->httpRequest = $request;
  66. $server->exec();
  67. $this->assertEquals('HTTP/1.1 200 OK', $server->httpResponse->status, $server->httpResponse->body);
  68. $this->assertEquals(array(
  69. 'Content-Type' => 'application/xml; charset=utf-8',
  70. ), $server->httpResponse->headers);
  71. $check = array(
  72. '/d:principal-search-property-set',
  73. '/d:principal-search-property-set/d:principal-search-property' => 2,
  74. '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2,
  75. '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1,
  76. '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1,
  77. '/d:principal-search-property-set/d:principal-search-property/d:description' => 2,
  78. );
  79. $xml = simplexml_load_string($server->httpResponse->body);
  80. $xml->registerXPathNamespace('d','DAV:');
  81. $xml->registerXPathNamespace('s','http://sabredav.org/ns');
  82. foreach($check as $v1=>$v2) {
  83. $xpath = is_int($v1)?$v2:$v1;
  84. $result = $xml->xpath($xpath);
  85. $count = 1;
  86. if (!is_int($v1)) $count = $v2;
  87. $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body);
  88. }
  89. }
  90. }