From 3745de8f5781abe83c4c4030e72bca4088bbc4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Wed, 16 Jul 2014 09:36:39 +0200 Subject: [PATCH] fixed position tests on brands --- core/lib/Thelia/Tests/Action/BrandTest.php | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/lib/Thelia/Tests/Action/BrandTest.php b/core/lib/Thelia/Tests/Action/BrandTest.php index e741e8cb0..5f47feb6b 100644 --- a/core/lib/Thelia/Tests/Action/BrandTest.php +++ b/core/lib/Thelia/Tests/Action/BrandTest.php @@ -155,6 +155,8 @@ class BrandTest extends TestCaseWithURLToolSetup public function testUpdatePositionUp() { + $this->resetBrandPosition(); + $brand = BrandQuery::create() ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); @@ -178,6 +180,8 @@ class BrandTest extends TestCaseWithURLToolSetup public function testUpdatePositionDown() { + $this->resetBrandPosition(); + $brand = BrandQuery::create() ->filterByPosition(1) ->findOne(); @@ -201,6 +205,8 @@ class BrandTest extends TestCaseWithURLToolSetup public function testUpdatePositionWithSpecificPosition() { + $this->resetBrandPosition(); + $brand = BrandQuery::create() ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); @@ -219,6 +225,23 @@ class BrandTest extends TestCaseWithURLToolSetup $this->assertEquals(1, $updatedBrand->getPosition(),sprintf("new position is 1, new position expected is %d for brand %d", $updatedBrand->getPosition(), $updatedBrand->getId())); } + + /** + * Reorder brand to have proper position + */ + protected function resetBrandPosition() + { + $brands = BrandQuery::create()->find(); + $counter = 1; + + /** @var \Thelia\Model\Brand $brand */ + foreach ($brands as $brand) { + $brand->setPosition($counter); + $brand->save(); + $counter++; + } + } + /** * @return \Thelia\Model\Brand */