Merge branch 'master' into loops

Conflicts:
	core/lib/Thelia/Core/Template/Loop/Category.php
	core/lib/Thelia/Core/Template/Loop/FeatureValue.php
	core/lib/Thelia/Core/Template/Loop/Folder.php
	core/lib/Thelia/Core/Template/Loop/Product.php
	core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php
	install/faker.php
This commit is contained in:
Etienne Roudeix
2013-08-21 09:19:56 +02:00
3275 changed files with 929970 additions and 274940 deletions

View File

@@ -0,0 +1,372 @@
<?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\Action\ImageTest;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Action\Image;
use Thelia\Core\Event\ImageEvent;
use Thelia\Model\ConfigQuery;
/**
* Class ImageTest
*
* @package Thelia\Tests\Action\ImageTest
*/
class ImageTest extends \PHPUnit_Framework_TestCase
{
protected $request;
protected $session;
public function getContainer()
{
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
$container->set("event_dispatcher", $dispatcher);
return $container;
}
public function setUp()
{
$this->session = new Session(new MockArraySessionStorage());
$this->request = new Request();
$this->request->setSession($this->session);
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('image_cache_dir_from_web_root')->findOne();
if ($config != null) {
$this->cache_dir_from_web_root = $config->getValue();
$config->setValue(__DIR__."/assets/images/cache");
$config->setValue($this->cache_dir_from_web_root)->save();
}
}
public static function setUpBeforeClass() {
$dir = THELIA_WEB_DIR."/cache/tests";
if ($dh = @opendir($dir)) {
while ($file = readdir($dh)) {
if ($file == '.' || $file == '..') continue;
unlink(sprintf("%s/%s", $dir, $file));
}
closedir($dh);
}
}
public function tearDown() {
// restore cache configuration.
$config = ConfigQuery::create()->filterByName('image_cache_dir_from_web_root')->findOne();
if ($config != null) {
$config->setValue($this->cache_dir_from_web_root)->save();
}
}
/**
*
* Imageevent is empty, mandatory parameters not specified.
*
* @expectedException \InvalidArgumentException
*/
public function testProcessEmptyImageEvent()
{
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$image->processImage($event);
}
/**
*
* Try to process a non-existent file
*
* @expectedException \InvalidArgumentException
*/
public function testProcessNonExistentImage()
{
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$event->setCacheFilepath("blablabla.png");
$event->setCacheSubdirectory("tests");
$image->processImage($event);
}
/**
*
* Try to process a file outside of the cache
*
* @expectedException \InvalidArgumentException
*/
public function testProcessImageOutsideValidPath()
{
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$event->setCacheFilepath("blablabla.png");
$event->setCacheSubdirectory("../../../");
$image->processImage($event);
}
/**
* No operation done on source file -> copie !
*/
public function testProcessImageWithoutAnyTransformationsCopy()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-1.png");
$event->setCacheSubdirectory("tests");
$image = new Image($this->getContainer());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
if ($config != null) {
$oldval = $config->getValue();
$config->setValue('copy')->save();
}
$image->processImage($event);
if ($config != null) $config->setValue($oldval)->save();
$imgdir = ConfigQuery::read('image_cache_dir_from_web_root');
$this->assertFileExists(THELIA_WEB_DIR."/$imgdir/tests/test-image-1.png");
}
/**
* No operation done on source file -> copie !
*/
public function testProcessImageWithoutAnyTransformationsSymlink()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-9.png");
$event->setCacheSubdirectory("tests");
$image = new Image($this->getContainer());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
if ($config != null) {
$oldval = $config->getValue();
$config->setValue('symlink')->save();
}
$image->processImage($event);
if ($config != null) $config->setValue($oldval)->save();
$imgdir = ConfigQuery::read('image_cache_dir_from_web_root');
$this->assertFileExists(THELIA_WEB_DIR."/$imgdir/tests/test-image-9.png");
}
/**
* Resize image with bands width > height
*/
public function testProcessImageResizeHorizWithBands()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-2.png");
$event->setCacheSubdirectory("tests");
$event->setBackgroundColor('#ff0000');
$event->setWidth(100);
$event->setHeight(100);
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
$image = new Image($this->getContainer());
$image->processImage($event);
}
/**
* Resize image with bands height > width
*/
public function testProcessImageResizeVertWithBands()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-3.png");
$event->setCacheSubdirectory("tests");
$event->setBackgroundColor('#ff0000');
$event->setWidth(100);
$event->setHeight(100);
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
$image = new Image($this->getContainer());
$image->processImage($event);
}
/**
* Apply all transformations
*/
public function testProcessImageWithTransformations()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-4.png");
$event->setCacheSubdirectory("tests");
$event->setEffects(array("grayscale", "vertical_flip", "horizontal_flip", 'colorize:#00ff00', 'gamma: 0.2'));
$image = new Image($this->getContainer());
$image->processImage($event);
}
/**
* Resize image with crop width > height
*/
public function testProcessImageResizeHorizWithCrop()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-5.png");
$event->setCacheSubdirectory("tests");
$event->setBackgroundColor('#ff0000');
$event->setWidth(180);
$event->setHeight(100);
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
$image = new Image($this->getContainer());
$image->processImage($event);
}
/**
* Resize image with crop height > width
*/
public function testProcessImageResizeVertWithCrop()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-6.png");
$event->setCacheSubdirectory("tests");
$event->setBackgroundColor('#ff0000');
$event->setWidth(100);
$event->setHeight(150);
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
$image = new Image($this->getContainer());
$image->processImage($event);
}
/**
* Resize image keeping image ration
*/
public function testProcessImageResizeHorizKeepRatio()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-7.png");
$event->setCacheSubdirectory("tests");
$event->setWidth(100);
$event->setHeight(100);
$image = new Image($this->getContainer());
$image->processImage($event);
}
/**
* Resize image with crop height > width
*/
public function testProcessImageResizeVertKeepRatio()
{
$event = new ImageEvent($this->request);
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-8.png");
$event->setCacheSubdirectory("tests");
$event->setWidth(100);
$event->setHeight(100);
$image = new Image($this->getContainer());
$image->processImage($event);
}
public function testClearTestsCache() {
$event = new ImageEvent($this->request);
$event->setCacheSubdirectory('tests');
$image = new Image($this->getContainer());
$image->clearCache($event);
}
public function testClearWholeCache() {
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$image->clearCache($event);
}
/**
* Try to clear directory ouside of the cache
*
* @expectedException \InvalidArgumentException
*/
public function testClearUnallowedPathCache() {
$event = new ImageEvent($this->request);
$event->setCacheSubdirectory('../../../..');
$image = new Image($this->getContainer());
$image->clearCache($event);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

7
core/lib/Thelia/Tests/Cart/CartTraitTest.php Normal file → Executable file
View File

@@ -23,13 +23,10 @@
namespace Thelia\Tests\Cart\CartTraitTest;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Thelia\Core\Event\DefaultActionEvent;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Model\Cart;
use Thelia\Model\Customer;
use Thelia\Model\ProductQuery;
use Thelia\Model\ProductSaleElementsQuery;
/**
* phpunit 3.8 needed for mcking a Trait and there is conflict with php version.
@@ -180,7 +177,6 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase
$request = $this->request;
//create a fake customer just for test. If not persists test fails !
$customer = new Customer();
$customer->setFirstname("john");
@@ -219,7 +215,6 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase
$request = $this->request;
//create a fake customer just for test. If not persists test fails !
$customer = new Customer();
$customer->setFirstname("john");
@@ -278,4 +273,4 @@ class MockCartTrait
return $this->container->get("event_dispatcher");
}
}
}

6
core/lib/Thelia/Tests/Command/BaseCommandTest.php Normal file → Executable file
View File

@@ -22,12 +22,12 @@
/*************************************************************************************/
namespace Thelia\Tests\Command;
abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase {
abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
{
public function getKernel()
{
$kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface");
return $kernel;
}
}
}

View File

@@ -44,25 +44,26 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase
public function testCacheClear()
{
$application = new Application($this->getKernel());
// Fails on windows - do not execute this test on windows
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$application = new Application($this->getKernel());
$cacheClear = new CacheClear();
$cacheClear->setContainer($this->getContainer());
$cacheClear = new CacheClear();
$cacheClear->setContainer($this->getContainer());
$application->add($cacheClear);
$application->add($cacheClear);
$command = $application->find("cache:clear");
$commandTester = new CommandTester($command);
$commandTester->execute(array(
"command" => $command->getName(),
"--env" => "test"
));
$fs = new Filesystem();
$this->assertFalse($fs->exists($this->cache_dir));
$command = $application->find("cache:clear");
$commandTester = new CommandTester($command);
$commandTester->execute(array(
"command" => $command->getName(),
"--env" => "test"
));
$fs = new Filesystem();
$this->assertFalse($fs->exists($this->cache_dir));
}
}
/**
@@ -70,22 +71,28 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase
*/
public function testCacheClearWithoutWritePermission()
{
$fs = new Filesystem();
$fs->chmod($this->cache_dir,0100);
// Fails on windows - mock this test on windows
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$fs = new Filesystem();
$fs->chmod($this->cache_dir,0100);
$application = new Application($this->getKernel());
$application = new Application($this->getKernel());
$cacheClear = new CacheClear();
$cacheClear->setContainer($this->getContainer());
$cacheClear = new CacheClear();
$cacheClear->setContainer($this->getContainer());
$application->add($cacheClear);
$application->add($cacheClear);
$command = $application->find("cache:clear");
$commandTester = new CommandTester($command);
$commandTester->execute(array(
"command" => $command->getName(),
"--env" => "test"
));
$command = $application->find("cache:clear");
$commandTester = new CommandTester($command);
$commandTester->execute(array(
"command" => $command->getName(),
"--env" => "test"
));
}
else {
throw new \RuntimeException("");
}
}
public function getKernel()
@@ -104,4 +111,4 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase
return $container;
}
}
}

View File

@@ -22,14 +22,13 @@
/*************************************************************************************/
namespace Thelia\Tests\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
use Thelia\Core\Application;
use Thelia\Command\ModuleGenerateCommand;
class ModuleGenerateCommandTest extends BaseCommandTest {
class ModuleGenerateCommandTest extends BaseCommandTest
{
protected $command;
protected $commandTester;
@@ -105,4 +104,4 @@ class ModuleGenerateCommandTest extends BaseCommandTest {
"name" => "thelia"
));
}
}
}

View File

@@ -24,41 +24,41 @@
namespace Thelia\Tests\Controller;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Controller\DefaultController;
use Thelia\Controller\Front\DefaultController;
class DefaultControllerTest extends \PHPUnit_Framework_TestCase
{
public function testNoAction()
{
$defaultController = new DefaultController();
$request = new Request();
$defaultController->noAction($request);
$this->assertEquals($request->attributes->get('_view'), "index");
}
public function testNoActionWithQuery()
{
$defaultController = new DefaultController();
$request = new Request(array(
"view" => "foo"
));
$defaultController->noAction($request);
$this->assertEquals($request->attributes->get('_view'), 'foo');
}
public function testNoActionWithRequest()
{
$defaultController = new DefaultController();
$request = new Request(array(), array(
"view" => "foo"
));
$defaultController->noAction($request);
$this->assertEquals($request->attributes->get('_view'), 'foo');
}
}
}

View File

@@ -4,7 +4,6 @@ namespace Thelia\Tests\Core\HttpFoundation;
use Thelia\Core\HttpFoundation\Request;
class RequestTest extends \PHPUnit_Framework_TestCase
{
@@ -37,7 +36,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("http://localhost/?test=fu&foo=bar", $result);
}
}
}

View File

@@ -133,4 +133,4 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf("\Thelia\Model\Cart", $cart, '$cart must be an instance of Thelia\Model\Cart');
}
}
}

View File

@@ -46,10 +46,12 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
abstract public function getTestedInstance();
abstract public function getMandatoryArguments();
protected function getMethod($name) {
protected function getMethod($name)
{
$class = new \ReflectionClass($this->getTestedClassName());
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}

View File

@@ -99,10 +99,9 @@ class ArgumentTest extends \PHPUnit_Framework_TestCase
)
);
$arguments = \PHPUnit_Framework_Assert::readAttribute($collection, 'arguments');
foreach($collection as $key => $argument) {
foreach ($collection as $key => $argument) {
$this->assertEquals(
$argument,
$arguments[$key]

View File

@@ -22,4 +22,4 @@ class TpexConfig
{
return array();
}
}
}

3
core/lib/Thelia/Tests/Form/CartAddTest.php Normal file → Executable file
View File

@@ -22,7 +22,6 @@
/*************************************************************************************/
namespace Thelia\Tests\Form;
class CartAddTest extends \PHPUnit_Framework_TestCase
{
@@ -30,4 +29,4 @@ class CartAddTest extends \PHPUnit_Framework_TestCase
{
}
}
}

View File

@@ -32,11 +32,10 @@ class TlogTest extends \PHPUnit_Framework_TestCase
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]{1,2}:[0-9]{2}:[0-9]{2}:[\s](%s).*$/is";
public static function setUpBeforeClass()
{
{
self::$logger = Tlog::getInstance();
self::$logger->setDestinations("Thelia\Log\Destination\TlogDestinationText");
self::$logger->setLevel(Tlog::DEBUG);
self::$logger->setFiles("*");
@@ -61,7 +60,7 @@ class TlogTest extends \PHPUnit_Framework_TestCase
$this->expectOutputRegex("/^$/");
$logger->debug("foo");
}
public function testDebugWithInfoLevel()
{
@@ -81,7 +80,7 @@ class TlogTest extends \PHPUnit_Framework_TestCase
$this->expectOutputRegex("/^$/");
$logger->info("foo");
}
public function testDebugWithNoticeLevel()
{
@@ -141,7 +140,7 @@ class TlogTest extends \PHPUnit_Framework_TestCase
$this->expectOutputRegex("/^$/");
$logger->error("foo");
}
public function testErrorWithCriticalLevel()
{
@@ -161,7 +160,7 @@ class TlogTest extends \PHPUnit_Framework_TestCase
$this->expectOutputRegex("/^$/");
$logger->critical("foo");
}
public function testErrorWithAlertLevel()
{
@@ -181,7 +180,7 @@ class TlogTest extends \PHPUnit_Framework_TestCase
$this->expectOutputRegex("/^$/");
$logger->alert("foo");
}
public function testErrorWithEmergencyLevel()
{

View File

@@ -63,10 +63,9 @@ class TypeTest extends \PHPUnit_Framework_TestCase
new Type\FloatType()
);
$types = \PHPUnit_Framework_Assert::readAttribute($collection, 'types');
foreach($collection as $key => $type) {
foreach ($collection as $key => $type) {
$this->assertEquals(
$type,
$types[$key]

View File

@@ -11,7 +11,3 @@ require_once __DIR__ . '/../../../bootstrap.php';
use Thelia\Core\Thelia;
$thelia = new Thelia("test", true);