aboutsummaryrefslogtreecommitdiff
path: root/engine/tests
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2012-01-25 11:41:01 -0800
committerBrett Profitt <brett.profitt@gmail.com>2012-01-25 11:41:01 -0800
commite2af7b73d92a5eddeaed4bd129333045f6060c46 (patch)
tree367b55450db7b7823519bbe07aa8fd3bb3cb683b /engine/tests
parent5a3390fbb42a787f7c2ba4f13b6a6843d9a90c7b (diff)
downloadelgg-e2af7b73d92a5eddeaed4bd129333045f6060c46.tar.gz
elgg-e2af7b73d92a5eddeaed4bd129333045f6060c46.tar.bz2
Fixes #4288. Added setIncrementOffset() to ElggBatch.
Diffstat (limited to 'engine/tests')
-rw-r--r--engine/tests/api/helpers.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
index 77205138d..a615be0c0 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', 'test_elgg_batch_callback'), $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::test_elgg_batch_callback(array(), true);
+ $options = array(
+ 'offset' => 0,
+ 'limit' => 11
+ );
+ $batch = new ElggBatch(array('ElggCoreHelpersTest', 'test_elgg_batch_callback'), $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::test_elgg_batch_callback(array(), true);
+ $options = array(
+ 'offset' => 3,
+ 'limit' => 11
+ );
+ $batch = new ElggBatch(array('ElggCoreHelpersTest', 'test_elgg_batch_callback'), $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 test_elgg_batch_callback($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