new types

This commit is contained in:
Etienne Roudeix
2013-07-03 10:52:24 +02:00
parent 32f1fb3441
commit 92d15d44c7
7 changed files with 214 additions and 32 deletions

View File

@@ -95,6 +95,7 @@ class Product extends BaseLoop
new Argument(
'ref',
new TypeCollection(
new Type\AlphaNumStringType(),
new Type\JsonType()
)
),
@@ -139,6 +140,11 @@ class Product extends BaseLoop
}
if (!is_null($this->category)) {
if(null !== $this->depth) {
}
$search->filterByCategory(
CategoryQuery::create()->filterById($this->category, \Criteria::IN)->find(),
\Criteria::IN

View File

@@ -0,0 +1,48 @@
<?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\AlphaNumStringListType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class AlphaNumStringListTypeTest extends \PHPUnit_Framework_TestCase
{
public function testAlphaNumStringListType()
{
$type = new AlphaNumStringListType();
$this->assertTrue($type->isValid('FOO1,FOO_2,FOO-3'));
$this->assertFalse($type->isValid('FOO.1,FOO$_2,FOO-3'));
}
public function testFormatAlphaNumStringListType()
{
$type = new AlphaNumStringListType();
$this->assertTrue(is_array($type->getFormatedValue('FOO1,FOO_2,FOO-3')));
$this->assertNull($type->getFormatedValue('5€'));
}
}

View File

@@ -0,0 +1,43 @@
<?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\AlphaNumStringType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class AlphaNumStringTypeTest extends \PHPUnit_Framework_TestCase
{
public function testAlphaNumStringType()
{
$type = new AlphaNumStringType();
$this->assertTrue($type->isValid('azs_qs-0-9ds'));
$this->assertFalse($type->isValid('3.3'));
$this->assertFalse($type->isValid('3 3'));
$this->assertFalse($type->isValid('3€3'));
}
}

View File

@@ -40,7 +40,7 @@ class IntListTypeTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($intListType->isValid('1,2,3.3'));
}
public function testFormatJsonType()
public function testFormatIntListType()
{
$intListType = new IntListType();
$this->assertTrue(is_array($intListType->getFormatedValue('1,2,3')));

View File

@@ -0,0 +1,52 @@
<?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 AlphaNumStringListType implements TypeInterface
{
public function getType()
{
return 'Alphanumeric string list type';
}
public function isValid($values)
{
foreach(explode(',', $values) as $value) {
if(!preg_match('#^[a-zA-Z0-9\-_]+$#', $value))
return false;
}
return true;
}
public function getFormatedValue($values)
{
return $this->isValid($values) ? explode(',', $values) : null;
}
}

View File

@@ -0,0 +1,47 @@
<?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 AlphaNumStringType implements TypeInterface
{
public function getType()
{
return 'Alphanumeric string type';
}
public function isValid($value)
{
return preg_match('#^[a-zA-Z0-9\-_]+$#', $value) ? true : false;
}
public function getFormatedValue($value)
{
return $this->isValid($value) ? $value : null;
}
}