From 0c81b2f997323e0d91f0f592e690d1be12d330e8 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 13 Oct 2010 04:05:04 +0000 Subject: [PATCH] APICHANGE: changed the modulus offset to 1 to correctly order sets (from r103792) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112158 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/ViewableData.php | 6 +++--- tests/DataObjectSetTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/ViewableData.php b/core/ViewableData.php index c9ab478a3..37e942dd6 100755 --- a/core/ViewableData.php +++ b/core/ViewableData.php @@ -611,16 +611,16 @@ class ViewableData extends Object implements IteratorAggregate { /** * Returns the modulus of the numerical position of the item in the data set. - * The count starts from $startIndex, which defaults to 0. + * The count starts from $startIndex, which defaults to 1. * @param int $Mod The number to perform Mod operation to. * @param int $startIndex Number to start count from. * @return int */ - public function Modulus($mod, $startIndex = 0) { + public function Modulus($mod, $startIndex = 1) { return ($this->iteratorPos + $startIndex) % $mod; } - public function MultipleOf($factor, $offset = 0) { + public function MultipleOf($factor, $offset = 1) { return ($this->Modulus($factor, $offset) == 0); } diff --git a/tests/DataObjectSetTest.php b/tests/DataObjectSetTest.php index fdab97a5e..c35c91387 100644 --- a/tests/DataObjectSetTest.php +++ b/tests/DataObjectSetTest.php @@ -108,7 +108,7 @@ class DataObjectSetTest extends SapphireTest { public function testMultipleOf() { $comments = DataObject::get('PageComment', '', "\"ID\" ASC"); $commArr = $comments->toArray(); - $multiplesOf3 = 0; + $multiplesOf3 = 1; foreach($comments as $comment) { if($comment->MultipleOf(3)) { @@ -121,13 +121,13 @@ class DataObjectSetTest extends SapphireTest { $this->assertEquals(3, $multiplesOf3); - $this->assertTrue($commArr[0]->IsMultipleOf3); + $this->assertFalse($commArr[0]->IsMultipleOf3); $this->assertFalse($commArr[1]->IsMultipleOf3); - $this->assertFalse($commArr[2]->IsMultipleOf3); - $this->assertTrue($commArr[3]->IsMultipleOf3); + $this->assertTrue($commArr[2]->IsMultipleOf3); + $this->assertFalse($commArr[3]->IsMultipleOf3); $this->assertFalse($commArr[4]->IsMultipleOf3); - $this->assertFalse($commArr[5]->IsMultipleOf3); - $this->assertTrue($commArr[6]->IsMultipleOf3); + $this->assertTrue($commArr[5]->IsMultipleOf3); + $this->assertFalse($commArr[6]->IsMultipleOf3); foreach($comments as $comment) { if($comment->MultipleOf(3, 1)) {