ElggCoreGetEntitiesFromPrivateSettingsTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Test elgg_get_entities_from_private_settings()
  4. */
  5. class ElggCoreGetEntitiesFromPrivateSettingsTest extends \ElggCoreGetEntitiesBaseTest {
  6. public function testElggApiGettersEntitiesFromPrivateSettings() {
  7. // create some test private settings
  8. $setting_name = 'test_setting_name_' . rand();
  9. $setting_value = rand(1000, 9999);
  10. $setting_name2 = 'test_setting_name_' . rand();
  11. $setting_value2 = rand(1000, 9999);
  12. $subtypes = $this->getRandomValidSubtypes(array('object'), 1);
  13. $subtype = $subtypes[0];
  14. $guids = array();
  15. // our targets
  16. $valid = new \ElggObject();
  17. $valid->subtype = $subtype;
  18. $valid->save();
  19. $guids[] = $valid->getGUID();
  20. set_private_setting($valid->getGUID(), $setting_name, $setting_value);
  21. set_private_setting($valid->getGUID(), $setting_name2, $setting_value2);
  22. $valid2 = new \ElggObject();
  23. $valid2->subtype = $subtype;
  24. $valid2->save();
  25. $guids[] = $valid2->getGUID();
  26. set_private_setting($valid2->getGUID(), $setting_name, $setting_value);
  27. set_private_setting($valid2->getGUID(), $setting_name2, $setting_value2);
  28. // simple test with name
  29. $options = array(
  30. 'private_setting_name' => $setting_name
  31. );
  32. $entities = elgg_get_entities_from_private_settings($options);
  33. foreach ($entities as $entity) {
  34. $this->assertTrue(in_array($entity->getGUID(), $guids));
  35. $value = get_private_setting($entity->getGUID(), $setting_name);
  36. $this->assertEqual($value, $setting_value);
  37. }
  38. // simple test with value
  39. $options = array(
  40. 'private_setting_value' => $setting_value
  41. );
  42. $entities = elgg_get_entities_from_private_settings($options);
  43. foreach ($entities as $entity) {
  44. $this->assertTrue(in_array($entity->getGUID(), $guids));
  45. $value = get_private_setting($entity->getGUID(), $setting_name);
  46. $this->assertEqual($value, $setting_value);
  47. }
  48. // test pairs
  49. $options = array(
  50. 'type' => 'object',
  51. 'subtype' => $subtype,
  52. 'private_setting_name_value_pairs' => array(
  53. array(
  54. 'name' => $setting_name,
  55. 'value' => $setting_value
  56. ),
  57. array(
  58. 'name' => $setting_name2,
  59. 'value' => $setting_value2
  60. )
  61. )
  62. );
  63. $entities = elgg_get_entities_from_private_settings($options);
  64. $this->assertEqual(2, count($entities));
  65. foreach ($entities as $entity) {
  66. $this->assertTrue(in_array($entity->getGUID(), $guids));
  67. }
  68. foreach ($guids as $guid) {
  69. if ($e = get_entity($guid)) {
  70. $e->delete();
  71. }
  72. }
  73. }
  74. }