From 9fe063022e08a4b6fa5f5935f8f185d5d95814a4 Mon Sep 17 00:00:00 2001 From: Sem Date: Wed, 25 Apr 2012 19:09:22 +0200 Subject: Upgraded to Elgg 1.8.4. --- engine/tests/api/helpers.php | 83 ++++++++++++++++++++++++++++++++++++++++ engine/tests/api/metastrings.php | 6 ++- 2 files changed, 88 insertions(+), 1 deletion(-) (limited to 'engine/tests/api') diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php index 77205138d..62e4471e0 100644 --- a/engine/tests/api/helpers.php +++ b/engine/tests/api/helpers.php @@ -518,4 +518,87 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $this->assertIdentical($elements_sorted_string, $test_elements); } + + // see http://trac.elgg.org/ticket/4288 + public function testElggBatchIncOffset() { + // normal increment + $options = array( + 'offset' => 0, + 'limit' => 11 + ); + $batch = new ElggBatch(array('ElggCoreHelpersTest', 'elgg_batch_callback_test'), $options, + null, 5); + $j = 0; + foreach ($batch as $e) { + $offset = floor($j / 5) * 5; + $this->assertEqual($offset, $e['offset']); + $this->assertEqual($j + 1, $e['index']); + $j++; + } + + $this->assertEqual(11, $j); + + // no increment, 0 start + ElggCoreHelpersTest::elgg_batch_callback_test(array(), true); + $options = array( + 'offset' => 0, + 'limit' => 11 + ); + $batch = new ElggBatch(array('ElggCoreHelpersTest', 'elgg_batch_callback_test'), $options, + null, 5); + $batch->setIncrementOffset(false); + + $j = 0; + foreach ($batch as $e) { + $this->assertEqual(0, $e['offset']); + // should always be the same 5 + $this->assertEqual($e['index'], $j + 1 - (floor($j / 5) * 5)); + $j++; + } + $this->assertEqual(11, $j); + + // no increment, 3 start + ElggCoreHelpersTest::elgg_batch_callback_test(array(), true); + $options = array( + 'offset' => 3, + 'limit' => 11 + ); + $batch = new ElggBatch(array('ElggCoreHelpersTest', 'elgg_batch_callback_test'), $options, + null, 5); + $batch->setIncrementOffset(false); + + $j = 0; + foreach ($batch as $e) { + $this->assertEqual(3, $e['offset']); + // same 5 results + $this->assertEqual($e['index'], $j + 4 - (floor($j / 5) * 5)); + $j++; + } + + $this->assertEqual(11, $j); + } + + static function elgg_batch_callback_test($options, $reset = false) { + static $count = 1; + + if ($reset) { + $count = 1; + return true; + } + + if ($count > 20) { + return false; + } + + for ($j = 0; ($options['limit'] < 5) ? $j < $options['limit'] : $j < 5; $j++) { + $return[] = array( + 'offset' => $options['offset'], + 'limit' => $options['limit'], + 'count' => $count++, + 'index' => 1 + $options['offset'] + $j + ); + } + + return $return; + } } \ No newline at end of file diff --git a/engine/tests/api/metastrings.php b/engine/tests/api/metastrings.php index a96388217..0a8945084 100644 --- a/engine/tests/api/metastrings.php +++ b/engine/tests/api/metastrings.php @@ -132,7 +132,7 @@ class ElggCoreMetastringsTest extends ElggCoreUnitTest { public function testKeepMeFromDeletingEverything() { foreach ($this->metastringTypes as $type) { $required = array( - 'guid', 'guids', 'limit' + 'guid', 'guids' ); switch ($type) { @@ -160,6 +160,10 @@ class ElggCoreMetastringsTest extends ElggCoreUnitTest { $options = array(); $this->assertFalse(elgg_is_valid_options_for_batch_operation($options, $type)); + // limit alone isn't valid: + $options = array('limit' => 10); + $this->assertFalse(elgg_is_valid_options_for_batch_operation($options, $type)); + foreach ($required as $key) { $options = array(); -- cgit v1.2.3