ElggAnnotationTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * test \ElggAnnotation
  4. *
  5. * @package Elgg
  6. * @subpackage Test
  7. */
  8. class ElggAnnotationTest extends \ElggCoreUnitTest {
  9. /**
  10. * @var \ElggEntity
  11. */
  12. protected $entity;
  13. /**
  14. * Called before each test method.
  15. */
  16. public function setUp() {
  17. $this->original_hooks = _elgg_services()->hooks;
  18. _elgg_services()->hooks = new \Elgg\PluginHooksService();
  19. $this->entity = new \ElggObject();
  20. $this->entity->subtype = 'elgg_annotation_test';
  21. $this->entity->access_id = ACCESS_PUBLIC;
  22. $this->entity->save();
  23. }
  24. /**
  25. * Called after each test method.
  26. */
  27. public function tearDown() {
  28. $this->entity->delete();
  29. remove_subtype('object', 'elgg_annotation_test');
  30. _elgg_services()->hooks = $this->original_hooks;
  31. }
  32. public function testCanEdit() {
  33. $user = new \ElggUser();
  34. $user->save();
  35. $id = $this->entity->annotate('test', 'foo', ACCESS_LOGGED_IN, elgg_get_logged_in_user_guid());
  36. $a = elgg_get_annotation_from_id($id);
  37. $this->assertTrue($a->canEdit());
  38. $this->assertFalse($a->canEdit($user->guid));
  39. $id = $this->entity->annotate('test', 'foo2', ACCESS_LOGGED_IN, $user->guid);
  40. $a = elgg_get_annotation_from_id($id);
  41. $this->assertTrue($a->canEdit());
  42. $this->assertTrue($a->canEdit($user->guid));
  43. $user->delete();
  44. }
  45. }