From 18dd7c1fbff1d4ba5ac0cfc0560fdd6e4f893dc7 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 31 Jul 2013 14:02:59 +0200 Subject: [PATCH 1/5] testing loop title --- .../Tests/Core/Template/Loop/TitleTest.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php new file mode 100755 index 000000000..c506c22f5 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php @@ -0,0 +1,53 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Core\Template\Loop\Title; + +/** + * + * @author Etienne Roudeix + * + */ +class TitleTest extends \PHPUnit_Framework_TestCase +{ + public function testGetArgDefinitions() + { + $title = new Title(); +/* + $this->assertTrue($collection->getCount() == 3); + + $this->assertTrue($collection->key() == 'arg0'); + $collection->next(); + $this->assertTrue($collection->key() == 'arg1'); + $collection->next(); + $this->assertTrue($collection->key() == 'arg2'); + $collection->next(); + + $this->assertFalse($collection->valid()); + + $collection->rewind(); + $this->assertTrue($collection->key() == 'arg0');*/ + } +} From 8f46c57d7266bbed007f9ee77dcb57558754281c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 1 Aug 2013 11:53:40 +0200 Subject: [PATCH 2/5] update faker script --- install/faker.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install/faker.php b/install/faker.php index 52572dc81..85a338ebe 100755 --- a/install/faker.php +++ b/install/faker.php @@ -62,14 +62,14 @@ try { $product->setRef($faker->text(255)); $product->save(); - $stock = new \Thelia\Model\Stock(); + $stock = new \Thelia\Model\ProductSaleElements(); $stock->setProduct($product); $stock->setQuantity($faker->randomNumber(1,50)); $stock->setPromo($faker->randomNumber(0,1)); $stock->save(); $productPrice = new \Thelia\Model\ProductPrice(); - $productPrice->setStock($stock); + $productPrice->setProductSaleElements($stock); $productPrice->setCurrency($currency); $productPrice->setPrice($faker->randomFloat(2, 20, 2500)); $productPrice->save(); @@ -88,14 +88,14 @@ try { $product->setRef($faker->text(255)); $product->save(); - $stock = new \Thelia\Model\Stock(); + $stock = new \Thelia\Model\ProductSaleElements(); $stock->setProduct($product); $stock->setQuantity($faker->randomNumber(1,50)); $stock->setPromo($faker->randomNumber(0,1)); $stock->save(); $productPrice = new \Thelia\Model\ProductPrice(); - $productPrice->setStock($stock); + $productPrice->setProductSaleElements($stock); $productPrice->setCurrency($currency); $productPrice->setPrice($faker->randomFloat(2, 20, 2500)); $productPrice->save(); From 96bf685b39d35506ba2139390cbeab058ad27938 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 2 Aug 2013 10:11:54 +0200 Subject: [PATCH 3/5] change default product loop order value add tests --- .../Core/Template/Loop/FeatureValue.php | 2 +- .../lib/Thelia/Core/Template/Loop/Product.php | 6 +- .../Core/Template/Element/BaseLoopTestor.php | 86 +++++++++++++++++++ .../Core/Template/Loop/AccessoryTest.php | 51 +++++++++++ .../Tests/Core/Template/Loop/AddressTest.php | 51 +++++++++++ .../Tests/Core/Template/Loop/CategoryTest.php | 51 +++++++++++ .../Tests/Core/Template/Loop/CountryTest.php | 51 +++++++++++ .../Tests/Core/Template/Loop/CustomerTest.php | 51 +++++++++++ .../Template/Loop/FeatureAvailableTest.php | 51 +++++++++++ .../Tests/Core/Template/Loop/FeatureTest.php | 51 +++++++++++ .../Core/Template/Loop/FeatureValueTest.php | 51 +++++++++++ .../Tests/Core/Template/Loop/ProductTest.php | 51 +++++++++++ .../Tests/Core/Template/Loop/TitleTest.php | 28 +++--- 13 files changed, 562 insertions(+), 19 deletions(-) create mode 100755 core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/AccessoryTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/AddressTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/CountryTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/CustomerTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/FeatureAvailableTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/FeatureTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/FeatureValueTest.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php index 67aa7b402..403baf37a 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php @@ -87,7 +87,7 @@ class FeatureValue extends BaseLoop $search->filterByProductId($product, Criteria::EQUAL); - $featureAvailable = $this->geFeature_available(); + $featureAvailable = $this->getFeature_available(); if (null !== $featureAvailable) { $search->filterByFeatureAvId($featureAvailable, Criteria::IN); diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index e9c1f689a..6debd5034 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -86,7 +86,7 @@ class Product extends BaseLoop new TypeCollection( new Type\EnumListType(array('alpha', 'alpha_reverse', /*'min_price', 'max_price',*/ 'manual', 'manual_reverse', 'ref', /*'promo', 'new',*/ 'random', 'given_id')) ), - 'manual' + 'alpha' ), Argument::createIntListTypeArgument('exclude'), Argument::createIntListTypeArgument('exclude_category'), @@ -271,12 +271,12 @@ class Product extends BaseLoop $search->orderBy('real_price', Criteria::DESC); break;*/ case "manual": - if(null === $this->category || count($this->category) != 1) + if(null === $category || count($category) != 1) throw new \InvalidArgumentException('Manual order cannot be set without single category argument'); $search->orderByPosition(Criteria::ASC); break; case "manual_reverse": - if(null === $this->category || count($this->category) != 1) + if(null === $category || count($category) != 1) throw new \InvalidArgumentException('Manual order cannot be set without single category argument'); $search->orderByPosition(Criteria::DESC); break; diff --git a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php new file mode 100755 index 000000000..bad6dc428 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php @@ -0,0 +1,86 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Element; + +use Symfony\Component\EventDispatcher\EventDispatcher; +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Security\SecurityContext; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Thelia\Core\HttpFoundation\Session\Session; + +/** + * + * @author Etienne Roudeix + * + */ +abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase +{ + protected $request; + protected $dispatcher; + protected $securityContext; + + protected $instance; + + abstract public function getTestedClassName(); + abstract public function getTestedInstance(); + abstract public function getMandatoryArguments(); + + protected function getMethod($name) { + $class = new \ReflectionClass($this->getTestedClassName()); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method; + } + + public function setUp() + { + $this->request = new Request(); + $this->request->setSession(new Session(new MockArraySessionStorage())); + + $this->dispatcher = new EventDispatcher(); + + $this->securityContext = new SecurityContext($this->request); + + $this->instance = $this->getTestedInstance(); + $this->instance->initializeArgs($this->getMandatoryArguments()); + } + + public function testGetArgDefinitions() + { + $method = $this->getMethod('getArgDefinitions'); + + $methodReturn = $method->invoke($this->instance); + + $this->assertInstanceOf('Thelia\Core\Template\Loop\Argument\ArgumentCollection', $methodReturn); + } + + public function testExec() + { + $method = $this->getMethod('exec'); + + $methodReturn = $method->invokeArgs($this->instance, array(null)); + + $this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/AccessoryTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/AccessoryTest.php new file mode 100755 index 000000000..99f5a0310 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/AccessoryTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Accessory; + +/** + * + * @author Etienne Roudeix + * + */ +class AccessoryTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Accessory'; + } + + public function getTestedInstance() + { + return new Accessory($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array('product' => 1); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/AddressTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/AddressTest.php new file mode 100755 index 000000000..7ca5c094b --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/AddressTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Address; + +/** + * + * @author Etienne Roudeix + * + */ +class AddressTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Address'; + } + + public function getTestedInstance() + { + return new Address($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php new file mode 100755 index 000000000..f33d07868 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Category; + +/** + * + * @author Etienne Roudeix + * + */ +class CategoryTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Category'; + } + + public function getTestedInstance() + { + return new Category($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/CountryTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/CountryTest.php new file mode 100755 index 000000000..389d0bc5d --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/CountryTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Country; + +/** + * + * @author Etienne Roudeix + * + */ +class CountryTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Country'; + } + + public function getTestedInstance() + { + return new Country($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/CustomerTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/CustomerTest.php new file mode 100755 index 000000000..62bcaa3be --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/CustomerTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Customer; + +/** + * + * @author Etienne Roudeix + * + */ +class CustomerTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Customer'; + } + + public function getTestedInstance() + { + return new Customer($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/FeatureAvailableTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/FeatureAvailableTest.php new file mode 100755 index 000000000..e93b05a69 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/FeatureAvailableTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\FeatureAvailable; + +/** + * + * @author Etienne Roudeix + * + */ +class FeatureAvailableTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\FeatureAvailable'; + } + + public function getTestedInstance() + { + return new FeatureAvailable($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/FeatureTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/FeatureTest.php new file mode 100755 index 000000000..155088173 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/FeatureTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Feature; + +/** + * + * @author Etienne Roudeix + * + */ +class FeatureTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Feature'; + } + + public function getTestedInstance() + { + return new Feature($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/FeatureValueTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/FeatureValueTest.php new file mode 100755 index 000000000..3f6a14a16 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/FeatureValueTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\FeatureValue; + +/** + * + * @author Etienne Roudeix + * + */ +class FeatureValueTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\FeatureValue'; + } + + public function getTestedInstance() + { + return new FeatureValue($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array('product' => 1, 'feature' => 1); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php new file mode 100755 index 000000000..58eaf55fd --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Product; + +/** + * + * @author Etienne Roudeix + * + */ +class ProductTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Product'; + } + + public function getTestedInstance() + { + return new Product($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php index c506c22f5..392e97930 100755 --- a/core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Loop/TitleTest.php @@ -23,6 +23,8 @@ namespace Thelia\Tests\Core\Template\Loop; +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + use Thelia\Core\Template\Loop\Title; /** @@ -30,24 +32,20 @@ use Thelia\Core\Template\Loop\Title; * @author Etienne Roudeix * */ -class TitleTest extends \PHPUnit_Framework_TestCase +class TitleTest extends BaseLoopTestor { - public function testGetArgDefinitions() + public function getTestedClassName() { - $title = new Title(); -/* - $this->assertTrue($collection->getCount() == 3); + return 'Thelia\Core\Template\Loop\Title'; + } - $this->assertTrue($collection->key() == 'arg0'); - $collection->next(); - $this->assertTrue($collection->key() == 'arg1'); - $collection->next(); - $this->assertTrue($collection->key() == 'arg2'); - $collection->next(); + public function getTestedInstance() + { + return new Title($this->request, $this->dispatcher, $this->securityContext); + } - $this->assertFalse($collection->valid()); - - $collection->rewind(); - $this->assertTrue($collection->key() == 'arg0');*/ + public function getMandatoryArguments() + { + return array(); } } From e8a6d9c90074ab49a646fc96acd8e566117a9827 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 2 Aug 2013 13:39:05 +0200 Subject: [PATCH 4/5] detailed loop error --- core/lib/Thelia/Core/Template/Element/BaseLoop.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index debc022b6..7c9740ee0 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -117,6 +117,9 @@ abstract class BaseLoop $faultActor = array(); $faultDetails = array(); + $loopType = isset($nameValuePairs['type']) ? $nameValuePairs['type'] : "undefined"; + $loopName = isset($nameValuePairs['name']) ? $nameValuePairs['name'] : "undefined"; + while (($argument = $this->args->current()) !== false) { $this->args->next(); @@ -125,17 +128,17 @@ abstract class BaseLoop /* check if mandatory */ if($value === null && $argument->mandatory) { $faultActor[] = $argument->name; - $faultDetails[] = sprintf('"%s" parameter is missing', $argument->name); + $faultDetails[] = sprintf('"%s" parameter is missing in loop type: %s, name: %s', $argument->name, $loopType, $loopName); } else if($value === '' && !$argument->empty) { /* check if empty */ $faultActor[] = $argument->name; - $faultDetails[] = sprintf('"%s" parameter cannot be empty', $argument->name); + $faultDetails[] = sprintf('"%s" parameter cannot be empty in loop type: %s, name: %s', $argument->name, $loopType, $loopName); } else if($value !== null && !$argument->type->isValid($value)) { /* check type */ $faultActor[] = $argument->name; - $faultDetails[] = sprintf('Invalid value for "%s" argument', $argument->name); + $faultDetails[] = sprintf('Invalid value for "%s" argument in loop type: %s, name: %s', $argument->name, $loopType, $loopName); } else { /* set default */ From e4a8f95b0a21e2ad9fbcfe6e2cdda4a8d891ce17 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 2 Aug 2013 13:42:30 +0200 Subject: [PATCH 5/5] add bug template --- templates/default/bug.html | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 templates/default/bug.html diff --git a/templates/default/bug.html b/templates/default/bug.html new file mode 100644 index 000000000..a1bc296ac --- /dev/null +++ b/templates/default/bug.html @@ -0,0 +1,4 @@ +{loop name="cat" type="category" id="99999"} + {loop name="prod" type="product" category="#ID"} + {/loop} +{/loop} \ No newline at end of file