ElggEntityPreloaderIntegrationTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class ElggEntityPreloaderIntegrationTest extends ElggCoreUnitTest {
  3. protected $realPreloader;
  4. /**
  5. * @var MockEntityPreloader20140623
  6. */
  7. protected $mockPreloader;
  8. public function setUp() {
  9. $this->realPreloader = _elgg_services()->entityPreloader;
  10. $this->mockPreloader = new MockEntityPreloader20140623();
  11. _elgg_services()->setValue('entityPreloader', $this->mockPreloader);
  12. }
  13. public function tearDown() {
  14. _elgg_services()->setValue('entityPreloader', $this->realPreloader);
  15. }
  16. public function testEGECanUsePreloader() {
  17. $options = array(
  18. 'limit' => 3,
  19. );
  20. elgg_get_entities($options);
  21. $this->assertNull($this->mockPreloader->preloaded);
  22. $options['preload_owners'] = true;
  23. elgg_get_entities($options);
  24. $this->assertEqual(3, count($this->mockPreloader->preloaded));
  25. }
  26. public function testEGMCanUsePreloader() {
  27. $options = array(
  28. 'limit' => 3,
  29. );
  30. elgg_get_metadata($options);
  31. $this->assertNull($this->mockPreloader->preloaded);
  32. $options['preload_owners'] = true;
  33. elgg_get_metadata($options);
  34. $this->assertEqual(3, count($this->mockPreloader->preloaded));
  35. }
  36. }
  37. class MockEntityPreloader20140623 extends Elgg\EntityPreloader {
  38. public $preloaded;
  39. public function preload($objects, array $guid_properties) {
  40. $this->preloaded = $objects;
  41. }
  42. }