ElggCoreRiverAPITest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Elgg Test river api
  4. *
  5. * @package Elgg
  6. * @subpackage Test
  7. */
  8. class ElggCoreRiverAPITest extends \ElggCoreUnitTest {
  9. public function testElggCreateRiverItemWorks() {
  10. $entity = elgg_get_entities(array('limit' => 1));
  11. $entity = $entity[0];
  12. $params = array(
  13. 'view' => 'river/relationship/friend/create',
  14. 'action_type' => 'create',
  15. 'subject_guid' => $entity->guid,
  16. 'object_guid' => $entity->guid,
  17. );
  18. $id = elgg_create_river_item($params);
  19. $this->assertTrue(is_int($id));
  20. $this->assertTrue(elgg_delete_river(array('id' => $id)));
  21. }
  22. public function testElggCreateRiverItemMissingRequiredParam() {
  23. $entity = elgg_get_entities(array('limit' => 1));
  24. $entity = $entity[0];
  25. $params = array(
  26. 'view' => 'river/relationship/friend/create',
  27. 'action_type' => 'create',
  28. 'subject_guid' => $entity->guid,
  29. 'object_guid' => $entity->guid,
  30. );
  31. $no_view = $params;
  32. unset($no_view['view']);
  33. $this->assertFalse(elgg_create_river_item($no_view));
  34. $no_action = $params;
  35. unset($no_action['action_type']);
  36. $this->assertFalse(elgg_create_river_item($no_action));
  37. $no_subject = $params;
  38. unset($no_subject['subject_guid']);
  39. $this->assertFalse(elgg_create_river_item($no_subject));
  40. $no_object = $params;
  41. unset($no_object['object_guid']);
  42. $this->assertFalse(elgg_create_river_item($no_object));
  43. }
  44. public function testElggCreateRiverItemViewNotExist() {
  45. $entity = elgg_get_entities(array('limit' => 1));
  46. $entity = $entity[0];
  47. $params = array(
  48. 'view' => 'river/relationship/foo/create',
  49. 'action_type' => 'create',
  50. 'subject_guid' => $entity->guid,
  51. 'object_guid' => $entity->guid,
  52. );
  53. $this->assertFalse(elgg_create_river_item($params));
  54. }
  55. public function testElggCreateRiverItemBadEntity() {
  56. $entity = elgg_get_entities(array('limit' => 1));
  57. $entity = $entity[0];
  58. $params = array(
  59. 'view' => 'river/relationship/friend/create',
  60. 'action_type' => 'create',
  61. 'subject_guid' => $entity->guid,
  62. 'object_guid' => $entity->guid,
  63. 'target_guid' => $entity->guid,
  64. );
  65. $bad_subject = $params;
  66. $bad_subject['subject_guid'] = -1;
  67. $this->assertFalse(elgg_create_river_item($bad_subject));
  68. $bad_object = $params;
  69. $bad_object['object_guid'] = -1;
  70. $this->assertFalse(elgg_create_river_item($bad_object));
  71. $bad_target = $params;
  72. $bad_target['target_guid'] = -1;
  73. $this->assertFalse(elgg_create_river_item($bad_target));
  74. }
  75. public function testElggTypeSubtypeWhereSQL() {
  76. $types = array('object');
  77. $subtypes = array('blog');
  78. $result = _elgg_get_river_type_subtype_where_sql('rv', $types, $subtypes, null);
  79. $this->assertIdentical($result, "((rv.type = 'object') AND ((rv.subtype = 'blog')))");
  80. $types = array('object');
  81. $subtypes = array('blog', 'file');
  82. $result = _elgg_get_river_type_subtype_where_sql('rv', $types, $subtypes, null);
  83. $this->assertIdentical($result, "((rv.type = 'object') AND ((rv.subtype = 'blog') OR (rv.subtype = 'file')))");
  84. }
  85. public function testElggRiverDisableEnable() {
  86. $user = new \ElggUser();
  87. $user->save();
  88. $entity = new \ElggObject();
  89. $entity->save();
  90. $params = array(
  91. 'view' => 'river/relationship/friend/create',
  92. 'action_type' => 'create',
  93. 'subject_guid' => $user->guid,
  94. 'object_guid' => $entity->guid,
  95. );
  96. $id = elgg_create_river_item($params);
  97. $river = elgg_get_river(array('ids' => array($id)));
  98. $this->assertIdentical($river[0]->enabled, 'yes');
  99. $user->disable();
  100. // should no longer be able to get the river
  101. $river = elgg_get_river(array('ids' => array($id)));
  102. $this->assertIdentical($river, array());
  103. // renabling the user should re-enable the river
  104. access_show_hidden_entities(true);
  105. $user->enable();
  106. access_show_hidden_entities(false);
  107. $river = elgg_get_river(array('ids' => array($id)));
  108. $this->assertIdentical($river[0]->enabled, 'yes');
  109. $user->delete();
  110. $entity->delete();
  111. }
  112. }