ElggCoreAnnotationAPITest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * Elgg Test annotation api
  4. *
  5. * @package Elgg
  6. * @subpackage Test
  7. */
  8. class ElggCoreAnnotationAPITest extends \ElggCoreUnitTest {
  9. protected $metastrings;
  10. /**
  11. * Called before each test method.
  12. */
  13. public function setUp() {
  14. $this->object = new \ElggObject();
  15. }
  16. /**
  17. * Called after each test method.
  18. */
  19. public function tearDown() {
  20. unset($this->object);
  21. }
  22. public function testElggGetAnnotationsCount() {
  23. $this->object->title = 'Annotation Unit Test';
  24. $this->object->save();
  25. $guid = $this->object->getGUID();
  26. create_annotation($guid, 'tested', 'tested1', 'text', 0, ACCESS_PUBLIC);
  27. create_annotation($guid, 'tested', 'tested2', 'text', 0, ACCESS_PUBLIC);
  28. $count = (int)elgg_get_annotations(array(
  29. 'annotation_names' => array('tested'),
  30. 'guid' => $guid,
  31. 'count' => true,
  32. ));
  33. $this->assertIdentical($count, 2);
  34. $this->object->delete();
  35. }
  36. public function testElggDeleteAnnotations() {
  37. $e = new \ElggObject();
  38. $e->save();
  39. for ($i=0; $i<30; $i++) {
  40. $e->annotate('test_annotation', rand(0,10000));
  41. }
  42. $options = array(
  43. 'guid' => $e->getGUID(),
  44. 'limit' => 0
  45. );
  46. $annotations = elgg_get_annotations($options);
  47. $this->assertIdentical(30, count($annotations));
  48. $this->assertTrue(elgg_delete_annotations($options));
  49. $annotations = elgg_get_annotations($options);
  50. $this->assertTrue(empty($annotations));
  51. // nothing to delete so null returned
  52. $this->assertNull(elgg_delete_annotations($options));
  53. $this->assertTrue($e->delete());
  54. }
  55. public function testElggDisableAnnotations() {
  56. $e = new \ElggObject();
  57. $e->save();
  58. for ($i=0; $i<30; $i++) {
  59. $e->annotate('test_annotation', rand(0,10000));
  60. }
  61. $options = array(
  62. 'guid' => $e->getGUID(),
  63. 'limit' => 0
  64. );
  65. $this->assertTrue(elgg_disable_annotations($options));
  66. $annotations = elgg_get_annotations($options);
  67. $this->assertTrue(empty($annotations));
  68. access_show_hidden_entities(true);
  69. $annotations = elgg_get_annotations($options);
  70. $this->assertIdentical(30, count($annotations));
  71. access_show_hidden_entities(false);
  72. $this->assertTrue($e->delete());
  73. }
  74. public function testElggEnableAnnotations() {
  75. $e = new \ElggObject();
  76. $e->save();
  77. for ($i=0; $i<30; $i++) {
  78. $e->annotate('test_annotation', rand(0,10000));
  79. }
  80. $options = array(
  81. 'guid' => $e->getGUID(),
  82. 'limit' => 0
  83. );
  84. $this->assertTrue(elgg_disable_annotations($options));
  85. // cannot see any annotations so returns null
  86. $this->assertNull(elgg_enable_annotations($options));
  87. access_show_hidden_entities(true);
  88. $this->assertTrue(elgg_enable_annotations($options));
  89. access_show_hidden_entities(false);
  90. $annotations = elgg_get_annotations($options);
  91. $this->assertIdentical(30, count($annotations));
  92. $this->assertTrue($e->delete());
  93. }
  94. public function testElggAnnotationExists() {
  95. $e = new \ElggObject();
  96. $e->save();
  97. $guid = $e->getGUID();
  98. $this->assertFalse(elgg_annotation_exists($guid, 'test_annotation'));
  99. $e->annotate('test_annotation', rand(0, 10000));
  100. $this->assertTrue(elgg_annotation_exists($guid, 'test_annotation'));
  101. // this metastring should always exist but an annotation of this name should not
  102. $this->assertFalse(elgg_annotation_exists($guid, 'email'));
  103. $options = array(
  104. 'guid' => $guid,
  105. 'limit' => 0
  106. );
  107. $this->assertTrue(elgg_disable_annotations($options));
  108. $this->assertTrue(elgg_annotation_exists($guid, 'test_annotation'));
  109. $this->assertTrue($e->delete());
  110. $this->assertFalse(elgg_annotation_exists($guid, 'test_annotation'));
  111. }
  112. }