PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Sabre/CardDAV/CardTest.php

https://github.com/KOLANICH/SabreDAV
PHP | 215 lines | 154 code | 49 blank | 12 comment | 0 complexity | e559124bbb90da8764b3924ab4d8feec MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Sabre\CardDAV;
  3. class CardTest extends \PHPUnit_Framework_TestCase {
  4. /**
  5. * @var Sabre\CardDAV\Card
  6. */
  7. protected $card;
  8. /**
  9. * @var Sabre\CardDAV\MockBackend
  10. */
  11. protected $backend;
  12. function setUp() {
  13. $this->backend = new Backend\Mock();
  14. $this->card = new Card(
  15. $this->backend,
  16. array(
  17. 'uri' => 'book1',
  18. 'id' => 'foo',
  19. 'principaluri' => 'principals/user1',
  20. ),
  21. array(
  22. 'uri' => 'card1',
  23. 'addressbookid' => 'foo',
  24. 'carddata' => 'card',
  25. )
  26. );
  27. }
  28. function testGet() {
  29. $result = $this->card->get();
  30. $this->assertEquals('card', $result);
  31. }
  32. function testGet2() {
  33. $this->card = new Card(
  34. $this->backend,
  35. array(
  36. 'uri' => 'book1',
  37. 'id' => 'foo',
  38. 'principaluri' => 'principals/user1',
  39. ),
  40. array(
  41. 'uri' => 'card1',
  42. 'addressbookid' => 'foo',
  43. )
  44. );
  45. $result = $this->card->get();
  46. $this->assertEquals("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", $result);
  47. }
  48. /**
  49. * @depends testGet
  50. */
  51. function testPut() {
  52. $file = fopen('php://memory','r+');
  53. fwrite($file, 'newdata');
  54. rewind($file);
  55. $this->card->put($file);
  56. $result = $this->card->get();
  57. $this->assertEquals('newdata', $result);
  58. }
  59. function testDelete() {
  60. $this->card->delete();
  61. $this->assertEquals(1, count($this->backend->cards['foo']));
  62. }
  63. function testGetContentType() {
  64. $this->assertEquals('text/x-vcard; charset=utf-8', $this->card->getContentType());
  65. }
  66. function testGetETag() {
  67. $this->assertEquals('"' . md5('card') . '"' , $this->card->getETag());
  68. }
  69. function testGetETag2() {
  70. $card = new Card(
  71. $this->backend,
  72. array(
  73. 'uri' => 'book1',
  74. 'id' => 'foo',
  75. 'principaluri' => 'principals/user1',
  76. ),
  77. array(
  78. 'uri' => 'card1',
  79. 'addressbookid' => 'foo',
  80. 'carddata' => 'card',
  81. 'etag' => '"blabla"',
  82. )
  83. );
  84. $this->assertEquals('"blabla"' , $card->getETag());
  85. }
  86. function testGetLastModified() {
  87. $this->assertEquals(null, $this->card->getLastModified());
  88. }
  89. function testGetSize() {
  90. $this->assertEquals(4, $this->card->getSize());
  91. $this->assertEquals(4, $this->card->getSize());
  92. }
  93. function testGetSize2() {
  94. $card = new Card(
  95. $this->backend,
  96. array(
  97. 'uri' => 'book1',
  98. 'id' => 'foo',
  99. 'principaluri' => 'principals/user1',
  100. ),
  101. array(
  102. 'uri' => 'card1',
  103. 'addressbookid' => 'foo',
  104. 'etag' => '"blabla"',
  105. 'size' => 4,
  106. )
  107. );
  108. $this->assertEquals(4, $card->getSize());
  109. }
  110. function testACLMethods() {
  111. $this->assertEquals('principals/user1', $this->card->getOwner());
  112. $this->assertNull($this->card->getGroup());
  113. $this->assertEquals(array(
  114. array(
  115. 'privilege' => '{DAV:}read',
  116. 'principal' => 'principals/user1',
  117. 'protected' => true,
  118. ),
  119. array(
  120. 'privilege' => '{DAV:}write',
  121. 'principal' => 'principals/user1',
  122. 'protected' => true,
  123. ),
  124. ), $this->card->getACL());
  125. }
  126. function testOverrideACL() {
  127. $card = new Card(
  128. $this->backend,
  129. array(
  130. 'uri' => 'book1',
  131. 'id' => 'foo',
  132. 'principaluri' => 'principals/user1',
  133. ),
  134. array(
  135. 'uri' => 'card1',
  136. 'addressbookid' => 'foo',
  137. 'carddata' => 'card',
  138. 'acl' => array(
  139. array(
  140. 'privilege' => '{DAV:}read',
  141. 'principal' => 'principals/user1',
  142. 'protected' => true,
  143. ),
  144. ),
  145. )
  146. );
  147. $this->assertEquals(array(
  148. array(
  149. 'privilege' => '{DAV:}read',
  150. 'principal' => 'principals/user1',
  151. 'protected' => true,
  152. ),
  153. ), $card->getACL());
  154. }
  155. /**
  156. * @expectedException Sabre\DAV\Exception\MethodNotAllowed
  157. */
  158. function testSetACL() {
  159. $this->card->setACL(array());
  160. }
  161. function testGetSupportedPrivilegeSet() {
  162. $this->assertNull(
  163. $this->card->getSupportedPrivilegeSet()
  164. );
  165. }
  166. }