Fixed some unit tests

This commit is contained in:
franck
2013-09-18 01:24:37 +02:00
parent d02f13f021
commit 48e2be57c6
8 changed files with 84 additions and 30 deletions

View File

@@ -175,7 +175,7 @@ class Image extends BaseI18nLoop
$source_id = $this->getSourceId(); $source_id = $this->getSourceId();
$id = $this->getId(); $id = $this->getId();
//echo "source = ".$this->getSource()."source_id=$source_id, id=$id<br />"; //echo "source = ".$this->getSourceId()."source_id=$source_id, id=$id<br />";
if (is_null($source_id) && is_null($id)) { if (is_null($source_id) && is_null($id)) {
throw new \InvalidArgumentException("If 'source' argument is specified, 'id' or 'source_id' argument should be specified"); throw new \InvalidArgumentException("If 'source' argument is specified, 'id' or 'source_id' argument should be specified");
@@ -214,6 +214,7 @@ class Image extends BaseI18nLoop
*/ */
public function exec(&$pagination) public function exec(&$pagination)
{ {
// Select the proper query to use, and get the object type // Select the proper query to use, and get the object type
$object_type = $object_id = null; $object_type = $object_id = null;
@@ -262,13 +263,14 @@ class Image extends BaseI18nLoop
} }
//echo "sql=".$search->toString(); // echo "sql=".$search->toString();
$results = $this->search($search, $pagination); $results = $this->search($search, $pagination);
$loopResult = new LoopResult($results); $loopResult = new LoopResult($results);
foreach ($results as $result) { foreach ($results as $result) {
// Create image processing event // Create image processing event
$event = new ImageEvent($this->request); $event = new ImageEvent($this->request);
@@ -315,7 +317,8 @@ class Image extends BaseI18nLoop
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} catch (\Exception $ex) { }
catch (\Exception $ex) {
// Ignore the result and log an error // Ignore the result and log an error
Tlog::getInstance()->addError("Failed to process image in image loop: ", $this->args); Tlog::getInstance()->addError("Failed to process image in image loop: ", $this->args);
} }

View File

@@ -31,11 +31,9 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Base\CategoryQuery;
use Thelia\Model\Base\ProductCategoryQuery;
use Thelia\Model\Base\TaxRuleQuery;
use Thelia\Type\TypeCollection; use Thelia\Type\TypeCollection;
use Thelia\Type; use Thelia\Type;
use Thelia\Model\TaxRuleQuery;
/** /**
* *
@@ -57,7 +55,8 @@ class TaxRule extends BaseI18nLoop
{ {
return new ArgumentCollection( return new ArgumentCollection(
Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('id'),
new Argument( Argument::createIntListTypeArgument('exclude'),
new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(
new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse')) new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse'))
@@ -77,7 +76,7 @@ class TaxRule extends BaseI18nLoop
$search = TaxRuleQuery::create(); $search = TaxRuleQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search, 'TITLE', 'DESCRIPTION'); $locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION'));
$id = $this->getId(); $id = $this->getId();

View File

@@ -132,7 +132,7 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn); $this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn);
} }
public function baseTestSearchById($id) public function baseTestSearchById($id, $other_args = array())
{ {
$this->instance->initializeArgs(array_merge( $this->instance->initializeArgs(array_merge(
$this->getMandatoryArguments(), $this->getMandatoryArguments(),
@@ -140,7 +140,8 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
"type" => "foo", "type" => "foo",
"name" => "foo", "name" => "foo",
"id" => $id, "id" => $id,
) ),
$other_args
)); ));
$dummy = null; $dummy = null;

View File

@@ -58,32 +58,27 @@ class DocumentTest extends BaseLoopTestor
{ {
$document = ProductDocumentQuery::create()->findOne(); $document = ProductDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId()); $this->baseTestSearchById($document->getId(), array('source' => 'product'));
} }
public function testSearchByFolderId() public function testSearchByFolderId()
{ {
$document = FolderDocumentQuery::create()->findOne(); $document = FolderDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId()); $this->baseTestSearchById($document->getId(), array('source' => 'folder'));
} }
public function testSearchByContentId() public function testSearchByContentId()
{ {
$document = ContentDocumentQuery::create()->findOne(); $document = ContentDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId()); $this->baseTestSearchById($document->getId(), array('source' => 'content'));
} }
public function testSearchByCategoryId() public function testSearchByCategoryId()
{ {
$document = CategoryDocumentQuery::create()->findOne(); $document = CategoryDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId()); $this->baseTestSearchById($document->getId(), array('source' => 'category'));
}
public function testSearchLimit()
{
$this->baseTestSearchWithLimit(1);
} }
} }

View File

@@ -58,32 +58,27 @@ class ImageTest extends BaseLoopTestor
{ {
$image = ProductImageQuery::create()->findOne(); $image = ProductImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId()); $this->baseTestSearchById($image->getId(), array('source' => 'product'));
} }
public function testSearchByFolderId() public function testSearchByFolderId()
{ {
$image = FolderImageQuery::create()->findOne(); $image = FolderImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId()); $this->baseTestSearchById($image->getId(), array('source' => 'folder'));
} }
public function testSearchByContentId() public function testSearchByContentId()
{ {
$image = ContentImageQuery::create()->findOne(); $image = ContentImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId()); $this->baseTestSearchById($image->getId(), array('source' => 'content'));
} }
public function testSearchByCategoryId() public function testSearchByCategoryId()
{ {
$image = CategoryImageQuery::create()->findOne(); $image = CategoryImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId()); $this->baseTestSearchById($image->getId(), array('source' => 'category'));
}
public function testSearchLimit()
{
$this->baseTestSearchWithLimit(1);
} }
} }

View File

@@ -27,6 +27,7 @@ use Thelia\Model\ProductQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor; use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Product; use Thelia\Core\Template\Loop\Product;
use Propel\Runtime\ActiveQuery\Criteria;
/** /**
* *
@@ -52,7 +53,7 @@ class ProductTest extends BaseLoopTestor
public function testSearchById() public function testSearchById()
{ {
$product = ProductQuery::create()->findOne(); $product = ProductQuery::create()->orderById(Criteria::ASC)->findOne();
$this->baseTestSearchById($product->getId()); $this->baseTestSearchById($product->getId());
} }

View File

@@ -0,0 +1,60 @@
<?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\Core\Template\Loop;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\TaxRule;
use Thelia\Model\TaxRuleQuery;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class TaxRuleTest extends BaseLoopTestor
{
public function getTestedClassName()
{
return 'Thelia\Core\Template\Loop\TaxRule';
}
public function getTestedInstance()
{
return new TaxRule($this->container);
}
public function getMandatoryArguments()
{
return array();
}
public function testSearchById()
{
$tr = TaxRuleQuery::create()->findOne();
$this->baseTestSearchById($tr->getId());
}
}

View File

@@ -78,7 +78,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
public function testLoad() public function testLoad()
{ {
$productQuery = ProductQuery::create()->findOneById(1); $productQuery = ProductQuery::create()->findOne();
$countryQuery = CountryQuery::create()->findOneById(64); $countryQuery = CountryQuery::create()->findOneById(64);
$calculator = new Calculator(); $calculator = new Calculator();