diff options
| author | Sem <sembrestels@riseup.net> | 2014-01-22 03:37:52 +0100 | 
|---|---|---|
| committer | Sem <sembrestels@riseup.net> | 2014-01-22 03:37:52 +0100 | 
| commit | 4a2ed114bb18c5363f594a380676c5654f4165a4 (patch) | |
| tree | 3a37094b249c40e3e6bf122691db53115f65f8f0 /engine/tests/api/helpers.php | |
| parent | 673932bc46a3918293a28c2c2fc622b3e5ff6bde (diff) | |
| parent | 0dd36c458d41e77521c36ae572fe73114ad4bc5a (diff) | |
| download | elgg-4a2ed114bb18c5363f594a380676c5654f4165a4.tar.gz elgg-4a2ed114bb18c5363f594a380676c5654f4165a4.tar.bz2 | |
Merge tag '1.8.18' of git://github.com/Elgg/Elgg into develop
1.8.18
Conflicts:
	mod/tinymce/vendor/tinymce/jscripts/tiny_mce/langs/en.js
	mod/tinymce/vendor/tinymce/jscripts/tiny_mce/themes/advanced/langs/en_dlg.js
Diffstat (limited to 'engine/tests/api/helpers.php')
| -rw-r--r-- | engine/tests/api/helpers.php | 103 | 
1 files changed, 102 insertions, 1 deletions
| diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php index 62e4471e0..414fb4145 100644 --- a/engine/tests/api/helpers.php +++ b/engine/tests/api/helpers.php @@ -519,7 +519,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {  		$this->assertIdentical($elements_sorted_string, $test_elements);  	} -	// see http://trac.elgg.org/ticket/4288 +	// see https://github.com/elgg/elgg/issues/4288  	public function testElggBatchIncOffset() {  		// normal increment  		$options = array( @@ -578,6 +578,107 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {  		$this->assertEqual(11, $j);  	} +	public function testElggBatchReadHandlesBrokenEntities() { +		$num_test_entities = 8; +		$guids = array(); +		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->save(); +			$guids[] = $entity->guid; +			_elgg_invalidate_cache_for_entity($entity->guid); +		} + +		// break entities such that the first fetch has one incomplete +		// and the second and third fetches have only incompletes! +		$db_prefix = elgg_get_config('dbprefix'); +		delete_data(" +			DELETE FROM {$db_prefix}objects_entity +			WHERE guid IN ({$guids[1]}, {$guids[2]}, {$guids[3]}, {$guids[4]}, {$guids[5]}) +		"); + +		$options = array( +			'type' => 'object', +			'subtype' => 'test_5357_subtype', +			'order_by' => 'e.guid', +		); + +		$entities_visited = array(); +		$batch = new ElggBatch('elgg_get_entities', $options, null, 2); +		/* @var ElggEntity[] $batch */ +		foreach ($batch as $entity) { +			$entities_visited[] = $entity->guid; +		} + +		// The broken entities should not have been visited +		$this->assertEqual($entities_visited, array($guids[0], $guids[6], $guids[7])); + +		// 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) . ")"); +	} + +	public function testElggBatchDeleteHandlesBrokenEntities() { +		$num_test_entities = 8; +		$guids = array(); +		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->save(); +			$guids[] = $entity->guid; +			_elgg_invalidate_cache_for_entity($entity->guid); +		} + +		// break entities such that the first fetch has one incomplete +		// and the second and third fetches have only incompletes! +		$db_prefix = elgg_get_config('dbprefix'); +		delete_data(" +			DELETE FROM {$db_prefix}objects_entity +			WHERE guid IN ({$guids[1]}, {$guids[2]}, {$guids[3]}, {$guids[4]}, {$guids[5]}) +		"); + +		$options = array( +			'type' => 'object', +			'subtype' => 'test_5357_subtype', +			'order_by' => 'e.guid', +		); + +		$entities_visited = array(); +		$batch = new ElggBatch('elgg_get_entities', $options, null, 2, false); +		/* @var ElggEntity[] $batch */ +		foreach ($batch as $entity) { +			$entities_visited[] = $entity->guid; +			$entity->delete(); +		} + +		// The broken entities should not have been visited +		$this->assertEqual($entities_visited, array($guids[0], $guids[6], $guids[7])); + +		// 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; | 
