diff options
author | Steve Clay <steve@mrclay.org> | 2013-06-03 17:02:33 -0400 |
---|---|---|
committer | Steve Clay <steve@mrclay.org> | 2013-06-03 17:02:33 -0400 |
commit | 35acc4a297de7660a191d4e7f9d3e8d55561885a (patch) | |
tree | 10a9ab4e9fc067cde92948597ffbfdce673af57d /engine/tests/api | |
parent | 50dee6fe09a1f600089b1684f6f8f91599c365a1 (diff) | |
download | elgg-35acc4a297de7660a191d4e7f9d3e8d55561885a.tar.gz elgg-35acc4a297de7660a191d4e7f9d3e8d55561885a.tar.bz2 |
Refs #5357: Introduces ElggBatch awareness of incomplete entities during fetch
Diffstat (limited to 'engine/tests/api')
-rw-r--r-- | engine/tests/api/helpers.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php index 62e4471e0..753d02915 100644 --- a/engine/tests/api/helpers.php +++ b/engine/tests/api/helpers.php @@ -578,6 +578,54 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $this->assertEqual(11, $j); } + public function testElggBatchHandlesBrokenEntities() { + $num_test_entities = 4; + $guids = array(); + $now = time(); + for ($i = $num_test_entities; $i > 0; $i--) { + $entity = new ElggObject(); + $entity->type = 'object'; + $entity->subtype = 'test_5357_subtype'; + $entity->access_id = ACCESS_PUBLIC; + $entity->time_created = ($now - $i); + $entity->save(); + $guids[] = $entity->guid; + _elgg_invalidate_cache_for_entity($entity->guid); + } + + // break the second entity + $db_prefix = elgg_get_config('dbprefix'); + delete_data("DELETE FROM {$db_prefix}objects_entity WHERE guid = {$guids[1]}"); + + $options = array( + 'type' => 'object', + 'subtype' => 'test_5357_subtype', + 'order' => 'e.time_created ASC', + ); + + $entities_visited = array(); + + $batch = new ElggBatch('elgg_get_entities', $options, null, 2); + foreach ($batch as $entity) { + $entities_visited[$entity->guid] = true; + } + + // All but the broken entity should have been visited + $this->assertEqual(count($entities_visited), $num_test_entities - 1); + + // cleanup (including leftovers from previous tests) + $entity_rows = elgg_get_entities(array_merge($options, array( + 'callback' => '', + 'limit' => false, + ))); + $guids = array(); + foreach ($entity_rows as $row) { + $guids[] = $row->guid; + } + delete_data("DELETE FROM {$db_prefix}entities WHERE guid IN (" . implode(',', $guids) . ")"); + delete_data("DELETE FROM {$db_prefix}objects_entity WHERE guid IN (" . implode(',', $guids) . ")"); + } + static function elgg_batch_callback_test($options, $reset = false) { static $count = 1; |