Merge branch 'master' of https://github.com/thelia/thelia
Conflicts: core/lib/Thelia/Core/Template/Element/BaseLoop.php
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,6 +15,5 @@ coverage
|
||||
.project
|
||||
.settings/
|
||||
local/cache/*
|
||||
composer.lock
|
||||
web/assets/*
|
||||
web/.htaccess
|
||||
|
||||
13
.travis.yml
Normal file
13
.travis.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- "5.4"
|
||||
- "5.5"
|
||||
|
||||
env:
|
||||
- DB_USER=root
|
||||
|
||||
before_script:
|
||||
- composer install --prefer-dist
|
||||
- sh -c "mysql -u$DB_USER -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS thelia;SET FOREIGN_KEY_CHECKS = 1;'; fi"
|
||||
- php Thelia thelia:install --db_host=localhost --db_username=$DB_USER --db_name=thelia
|
||||
1691
composer.lock
generated
Normal file
1691
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -41,6 +41,30 @@ class Install extends ContainerAwareCommand
|
||||
->setName("thelia:install")
|
||||
->setDescription("Install thelia using cli tools. For now Thelia only use mysql database")
|
||||
->setHelp("The <info>thelia:install</info> command install Thelia database and create config file needed.")
|
||||
->addOption(
|
||||
"db_host",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"host for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_username",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"username for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_password",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"password for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_name",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"database name"
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
@@ -56,9 +80,19 @@ class Install extends ContainerAwareCommand
|
||||
|
||||
$this->checkPermission($output);
|
||||
|
||||
do {
|
||||
$connectionInfo = $this->getConnectionInfo($input, $output);
|
||||
} while(false === $connection = $this->tryConnection($connectionInfo, $output));
|
||||
|
||||
$connectionInfo = array(
|
||||
"host" => $input->getOption("db_host"),
|
||||
"dbName" => $input->getOption("db_name"),
|
||||
"username" => $input->getOption("db_username"),
|
||||
"password" => $input->getOption("db_password")
|
||||
);
|
||||
|
||||
|
||||
|
||||
while(false === $connection = $this->tryConnection($connectionInfo, $output)) {
|
||||
$connectionInfo = $this->getConnectionInfo($input, $output);
|
||||
}
|
||||
|
||||
$this->createDatabase($connection, $connectionInfo["dbName"]);
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Core\Security\Encoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* use password api include in php 5.5 and available throw the password_compat library.
|
||||
*
|
||||
* Class PasswordPhpCompatEncoder
|
||||
* @package Thelia\Core\Security\Encoder
|
||||
*/
|
||||
class PasswordPhpCompatEncoder implements PasswordEncoderInterface {
|
||||
|
||||
/**
|
||||
* Encode a string.
|
||||
*
|
||||
* @param string $password the password to encode
|
||||
* @param string $algorithm the hash() algorithm
|
||||
* @return string $salt the salt, the salt is not used here.
|
||||
*/
|
||||
public function encode($password, $algorithm, $salt = null)
|
||||
{
|
||||
return password_hash($password, $algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a string against an encoded password.
|
||||
*
|
||||
* @param string $string the string to compare against password
|
||||
* @param string $password the encoded password
|
||||
* @param string $algorithm the hash() algorithm, not used here
|
||||
* @return string $salt the salt, not used here
|
||||
*/
|
||||
public function isEqual($string, $password, $algorithm = null, $salt = null)
|
||||
{
|
||||
return password_verify($string, $password);
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,7 @@ abstract class BaseLoop
|
||||
$faultDetails = array();
|
||||
|
||||
while (($argument = $this->args->current()) !== false) {
|
||||
$this->args->next();
|
||||
|
||||
$value = isset($nameValuePairs[$argument->name]) ? $nameValuePairs[$argument->name] : null;
|
||||
|
||||
|
||||
@@ -52,11 +52,11 @@ class Argument
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->value;
|
||||
return $this->type->getFormattedValue($this->value);
|
||||
}
|
||||
|
||||
public function setValue($value) {
|
||||
$this->value = $value;
|
||||
$this->value = $value === null ? null : (string)$value;
|
||||
}
|
||||
|
||||
public static function createAnyTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
||||
|
||||
@@ -83,7 +83,7 @@ class Category extends BaseLoop
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumType('alpha', 'alpha_reverse', 'reverse')
|
||||
new Type\EnumListType('alpha', 'alpha_reverse', 'reverse')
|
||||
)
|
||||
),
|
||||
Argument::createBooleanTypeArgument('random', 0),
|
||||
@@ -137,23 +137,32 @@ class Category extends BaseLoop
|
||||
|
||||
$search->filterByVisible($this->getVisible() ? 1 : 0);
|
||||
|
||||
switch ($this->getOrder()) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
||||
break;
|
||||
case "reverse":
|
||||
$search->orderByPosition(\Criteria::DESC);
|
||||
break;
|
||||
default:
|
||||
$search->orderByPosition();
|
||||
break;
|
||||
$orders = $this->getOrder();
|
||||
|
||||
if(null === $orders) {
|
||||
$search->orderByPosition();
|
||||
} else {
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
||||
break;
|
||||
case "reverse":
|
||||
$search->orderByPosition(\Criteria::DESC);
|
||||
break;
|
||||
default:
|
||||
$search->orderByPosition();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$random = $this->getRandom();
|
||||
|
||||
if ($this->getRandom() === true) {
|
||||
if ($random === true) {
|
||||
$search->clearOrderByColumns();
|
||||
$search->addAscendingOrderByColumn('RAND()');
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
@@ -34,8 +33,8 @@ use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\Map\ProductTableMap;
|
||||
use Thelia\Model\ProductCategoryQuery;
|
||||
use Thelia\Model\ProductPeer;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
@@ -80,7 +79,7 @@ class Product extends BaseLoop
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumType(array('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'category', 'manual', 'manual_reverse', 'ref', 'promo', 'new'))
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'manual', 'manual_reverse', 'ref', 'promo', 'new'))
|
||||
)
|
||||
),
|
||||
Argument::createBooleanTypeArgument('random', 0),
|
||||
@@ -97,6 +96,8 @@ class Product extends BaseLoop
|
||||
{
|
||||
$search = ProductQuery::create();
|
||||
|
||||
$search->withColumn('CASE WHEN ' . ProductTableMap::PROMO . '=1 THEN ' . ProductTableMap::PRICE2 . ' ELSE ' . ProductTableMap::PRICE . ' END', 'real_price');
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (!is_null($id)) {
|
||||
@@ -153,10 +154,15 @@ class Product extends BaseLoop
|
||||
$min_price = $this->getMin_price();
|
||||
|
||||
if(null !== $min_price) {
|
||||
$search->condition('in_promo', ProductPeer::PROMO . Criteria::EQUAL . '1')
|
||||
->condition('not_in_promo', ProductPeer::PROMO . Criteria::NOT_EQUAL . '1')
|
||||
->condition('min_price2', ProductPeer::PRICE2 . Criteria::GREATER_EQUAL . '?', $min_price)
|
||||
->condition('min_price', ProductPeer::PRICE . Criteria::GREATER_EQUAL . '?', $min_price)
|
||||
/**
|
||||
* Following should work but does not :
|
||||
*
|
||||
* $search->filterBy('real_price', $max_price, Criteria::GREATER_EQUAL);
|
||||
*/
|
||||
$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
|
||||
->condition('not_in_promo', ProductTableMap::PROMO . Criteria::NOT_EQUAL . '1')
|
||||
->condition('min_price2', ProductTableMap::PRICE2 . Criteria::GREATER_EQUAL . '?', $min_price)
|
||||
->condition('min_price', ProductTableMap::PRICE . Criteria::GREATER_EQUAL . '?', $min_price)
|
||||
->combine(array('in_promo', 'min_price2'), Criteria::LOGICAL_AND, 'in_promo_min_price')
|
||||
->combine(array('not_in_promo', 'min_price'), Criteria::LOGICAL_AND, 'not_in_promo_min_price')
|
||||
->where(array('not_in_promo_min_price', 'in_promo_min_price'), Criteria::LOGICAL_OR);
|
||||
@@ -165,10 +171,15 @@ class Product extends BaseLoop
|
||||
$max_price = $this->getMax_price();
|
||||
|
||||
if(null !== $max_price) {
|
||||
$search->condition('in_promo', ProductPeer::PROMO . Criteria::EQUAL . '1')
|
||||
->condition('not_in_promo', ProductPeer::PROMO . Criteria::NOT_EQUAL . '1')
|
||||
->condition('max_price2', ProductPeer::PRICE2 . Criteria::LESS_EQUAL . '?', $max_price)
|
||||
->condition('max_price', ProductPeer::PRICE . Criteria::LESS_EQUAL . '?', $max_price)
|
||||
/**
|
||||
* Following should work but does not :
|
||||
*
|
||||
* $search->filterBy('real_price', $max_price, Criteria::LESS_EQUAL);
|
||||
*/
|
||||
$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
|
||||
->condition('not_in_promo', ProductTableMap::PROMO . Criteria::NOT_EQUAL . '1')
|
||||
->condition('max_price2', ProductTableMap::PRICE2 . Criteria::LESS_EQUAL . '?', $max_price)
|
||||
->condition('max_price', ProductTableMap::PRICE . Criteria::LESS_EQUAL . '?', $max_price)
|
||||
->combine(array('in_promo', 'max_price2'), Criteria::LOGICAL_AND, 'in_promo_max_price')
|
||||
->combine(array('not_in_promo', 'max_price'), Criteria::LOGICAL_AND, 'not_in_promo_max_price')
|
||||
->where(array('not_in_promo_max_price', 'in_promo_max_price'), Criteria::LOGICAL_OR);
|
||||
@@ -222,47 +233,58 @@ class Product extends BaseLoop
|
||||
|
||||
$search->filterByVisible($this->getVisible());
|
||||
|
||||
switch ($this->getOrder()) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
||||
break;
|
||||
case "reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
case "min_price":
|
||||
//$search->order
|
||||
//$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
/*case "max_price":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
case "category":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;*/
|
||||
case "manual":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\ProductPeer::POSITION);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::POSITION);
|
||||
break;
|
||||
case "ref":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\ProductPeer::REF);
|
||||
break;
|
||||
case "promo":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::PROMO);
|
||||
break;
|
||||
case "new":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::NEWNESS);
|
||||
break;
|
||||
default:
|
||||
$search->orderByPosition();
|
||||
break;
|
||||
$orders = $this->getOrder();
|
||||
|
||||
if(null === $orders) {
|
||||
$search->orderByPosition();
|
||||
} else {
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
||||
break;
|
||||
case "reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
case "min_price":
|
||||
$search->orderBy('real_price', Criteria::ASC);
|
||||
break;
|
||||
case "max_price":
|
||||
$search->orderBy('real_price', Criteria::DESC);
|
||||
break;
|
||||
case "manual":
|
||||
if(null === $this->category || count($this->category) != 1)
|
||||
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
||||
$search->addAscendingOrderByColumn(ProductTableMap::POSITION);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
if(null === $this->category || count($this->category) != 1)
|
||||
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
||||
$search->addDescendingOrderByColumn(ProductTableMap::POSITION);
|
||||
break;
|
||||
case "ref":
|
||||
$search->addAscendingOrderByColumn(ProductTableMap::REF);
|
||||
break;
|
||||
case "promo":
|
||||
$search->addDescendingOrderByColumn(ProductTableMap::PROMO);
|
||||
break;
|
||||
case "new":
|
||||
$search->addDescendingOrderByColumn(ProductTableMap::NEWNESS);
|
||||
break;
|
||||
default:
|
||||
$search->orderByPosition();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getRandom() === true) {
|
||||
$random = $this->getRandom();
|
||||
|
||||
if ($random === true) {
|
||||
$search->clearOrderByColumns();
|
||||
$search->addAscendingOrderByColumn('RAND()');
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\ExecutionContext;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
@@ -105,7 +105,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
$this->setAlgo("PASSWORD_BCRYPT");
|
||||
return parent::setPassword(password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: manu
|
||||
* Date: 09/07/13
|
||||
* Time: 10:02
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
namespace Thelia\Tests\Security\Encoder;
|
||||
|
||||
|
||||
use Thelia\Core\Security\Encoder\PasswordPhpCompatEncoder;
|
||||
|
||||
class PasswordPhpCompatEncoderTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $encoder;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->encoder = new PasswordPhpCompatEncoder();
|
||||
}
|
||||
|
||||
public function testEncode()
|
||||
{
|
||||
$hash = $this->encoder->encode("foo", PASSWORD_BCRYPT);
|
||||
|
||||
$this->assertEquals($hash, crypt("foo", $hash));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $logger;
|
||||
|
||||
protected $regex = "/(\\d)(:)(\\s+)(%s)(\\s+)(\\[.*?\\])(\\s+)(\\{.*?\\})(\\s+)((?:2|1)\\d{3}(?:-|\\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))(.)(\\s+)(%s)([\n])/is";
|
||||
//protected $regex = "/(\\d)(:)(\\s+)(%s)(\\s+)(\\[.*?\\])(\\s+)(\\{.*?\\})(\\s+)(\\d{4})(-)(\\d{2})(-)(\\d{2})(\\s+)(\\d{2})(:)(\\d{2})(:)(\\d{2})(:)(\\s+)(%s)([\n])/is";
|
||||
protected $regex = "/[0-9]+:[\s](%s)+[\s]\[[a-zA-Z\.]+:[a-zA-Z]+\(\)\][\s]\{[0-9]+\}[\s][0-9]{4}-[0-9]{2}-[0-9]{2}[\s][0-9]{2}:[0-9]{2}:[0-9]{2}:[\s](%s).*$/is";
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ class AlphaNumStringListTypeTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatAlphaNumStringListType()
|
||||
{
|
||||
$type = new AlphaNumStringListType();
|
||||
$this->assertTrue(is_array($type->getFormatedValue('FOO1,FOO_2,FOO-3')));
|
||||
$this->assertNull($type->getFormatedValue('5€'));
|
||||
$this->assertTrue(is_array($type->getFormattedValue('FOO1,FOO_2,FOO-3')));
|
||||
$this->assertNull($type->getFormattedValue('5€'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ class BooleanTypeTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatBooleanType()
|
||||
{
|
||||
$booleanType = new BooleanType();
|
||||
$this->assertTrue($booleanType->getFormatedValue('yes'));
|
||||
$this->assertFalse($booleanType->getFormatedValue('no'));
|
||||
$this->assertNull($booleanType->getFormatedValue('foo'));
|
||||
$this->assertTrue($booleanType->getFormattedValue('yes'));
|
||||
$this->assertFalse($booleanType->getFormattedValue('no'));
|
||||
$this->assertNull($booleanType->getFormattedValue('foo'));
|
||||
}
|
||||
}
|
||||
|
||||
50
core/lib/Thelia/Tests/Type/EnumListTypeTest.php
Executable file
50
core/lib/Thelia/Tests/Type/EnumListTypeTest.php
Executable file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Type;
|
||||
|
||||
use Thelia\Type\EnumListType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class EnumListTypeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEnumListType()
|
||||
{
|
||||
$enumListType = new EnumListType(array("cat", "dog", "frog"));
|
||||
$this->assertTrue($enumListType->isValid('cat'));
|
||||
$this->assertTrue($enumListType->isValid('cat,dog'));
|
||||
$this->assertFalse($enumListType->isValid('potato'));
|
||||
$this->assertFalse($enumListType->isValid('cat,monkey'));
|
||||
}
|
||||
|
||||
public function testFormatEnumListType()
|
||||
{
|
||||
$enumListType = new EnumListType(array("cat", "dog", "frog"));
|
||||
$this->assertTrue(is_array($enumListType->getFormattedValue('cat,dog')));
|
||||
$this->assertNull($enumListType->getFormattedValue('cat,monkey'));
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class IntListTypeTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatIntListType()
|
||||
{
|
||||
$intListType = new IntListType();
|
||||
$this->assertTrue(is_array($intListType->getFormatedValue('1,2,3')));
|
||||
$this->assertNull($intListType->getFormatedValue('foo'));
|
||||
$this->assertTrue(is_array($intListType->getFormattedValue('1,2,3')));
|
||||
$this->assertNull($intListType->getFormattedValue('foo'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class JsonTypeTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatJsonType()
|
||||
{
|
||||
$jsonType = new JsonType();
|
||||
$this->assertTrue(is_array($jsonType->getFormatedValue('{"k0":"v0","k1":"v1","k2":"v2"}')));
|
||||
$this->assertNull($jsonType->getFormatedValue('foo'));
|
||||
$this->assertTrue(is_array($jsonType->getFormattedValue('{"k0":"v0","k1":"v1","k2":"v2"}')));
|
||||
$this->assertNull($jsonType->getFormattedValue('foo'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class AlphaNumStringListType implements TypeInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFormatedValue($values)
|
||||
public function getFormattedValue($values)
|
||||
{
|
||||
return $this->isValid($values) ? explode(',', $values) : null;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class AlphaNumStringType implements TypeInterface
|
||||
return preg_match('#^[a-zA-Z0-9\-_]+$#', $value) ? true : false;
|
||||
}
|
||||
|
||||
public function getFormatedValue($value)
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class AnyType implements TypeInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFormatedValue($value)
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class BooleanType implements TypeInterface
|
||||
return in_array($value, $this->trueValuesArray) || in_array($value, $this->falseValuesArray);
|
||||
}
|
||||
|
||||
public function getFormatedValue($value)
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
return $this->isValid($value) ? ( in_array($value, $this->trueValuesArray) ) : null;
|
||||
}
|
||||
|
||||
65
core/lib/Thelia/Type/EnumListType.php
Executable file
65
core/lib/Thelia/Type/EnumListType.php
Executable file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
class EnumListType implements TypeInterface
|
||||
{
|
||||
protected $values = array();
|
||||
|
||||
public function __construct($values = array())
|
||||
{
|
||||
if(is_array($values))
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'Enum list type';
|
||||
}
|
||||
|
||||
public function isValid($values)
|
||||
{
|
||||
foreach(explode(',', $values) as $value) {
|
||||
if(!$this->isSingleValueValid($value))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFormattedValue($values)
|
||||
{
|
||||
return $this->isValid($values) ? explode(',', $values) : null;
|
||||
}
|
||||
|
||||
public function isSingleValueValid($value)
|
||||
{
|
||||
return in_array($value, $this->values);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class EnumType implements TypeInterface
|
||||
return in_array($value, $this->values);
|
||||
}
|
||||
|
||||
public function getFormatedValue($value)
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class FloatType implements TypeInterface
|
||||
return filter_var($value, FILTER_VALIDATE_FLOAT) === false ? false : true;
|
||||
}
|
||||
|
||||
public function getFormatedValue($value)
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class IntListType implements TypeInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFormatedValue($values)
|
||||
public function getFormattedValue($values)
|
||||
{
|
||||
return $this->isValid($values) ? explode(',', $values) : null;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class IntType implements TypeInterface
|
||||
return filter_var($value, FILTER_VALIDATE_INT) === false ? false : true;
|
||||
}
|
||||
|
||||
public function getFormatedValue($value)
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class JsonType implements TypeInterface
|
||||
return (json_last_error() == JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
public function getFormatedValue($value)
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
return $this->isValid($value) ? json_decode($value, true) : null;
|
||||
}
|
||||
|
||||
@@ -133,10 +133,10 @@ class TypeCollection implements \Iterator
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFormatedValue($value) {
|
||||
public function getFormattedValue($value) {
|
||||
foreach($this as $type) {
|
||||
if($type->isValid($value)) {
|
||||
return $type->getFormatedValue($value);
|
||||
return $type->getFormattedValue($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,5 +34,5 @@ interface TypeInterface
|
||||
|
||||
public function isValid($value);
|
||||
|
||||
public function getFormatedValue($value);
|
||||
public function getFormattedValue($value);
|
||||
}
|
||||
|
||||
0
local/config/database.yml.sample
Executable file → Normal file
0
local/config/database.yml.sample
Executable file → Normal file
@@ -19,7 +19,7 @@
|
||||
<hr />
|
||||
{/loop*}
|
||||
<h2>PRODUCTS</h2>
|
||||
{loop name="product" type="product" order="min_price"}
|
||||
{loop name="product" type="product" order="promo,min_price"}
|
||||
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||
price : #PRICE €<br />
|
||||
promo price : #PROMO_PRICE €<br />
|
||||
|
||||
Reference in New Issue
Block a user