Initial Commit
This commit is contained in:
294
tests/phpunit/Thelia/Tests/Core/Archiver/ArchiverManagerTest.php
Normal file
294
tests/phpunit/Thelia/Tests/Core/Archiver/ArchiverManagerTest.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Tests\Core\Archiver;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Core\Archiver\ArchiverManager as SUT;
|
||||
|
||||
/**
|
||||
* Class ArchiverManagerTest
|
||||
* @author Jérôme Billiras <jbilliras@openstudio.fr>
|
||||
*/
|
||||
class ArchiverManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Thelia\Core\Archiver\ArchiverManager
|
||||
*/
|
||||
protected $sut;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $stubArchiver;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->sut = new SUT;
|
||||
$this->stubArchiver = $this->getMock('Thelia\\Core\\Archiver\\ArchiverInterface');
|
||||
|
||||
new Translator(new Container);
|
||||
}
|
||||
|
||||
public function testGetArchivers()
|
||||
{
|
||||
$archivers = $this->sut->getArchivers();
|
||||
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
|
||||
$archivers = $this->sut->getArchivers(true);
|
||||
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
|
||||
$archivers = $this->sut->getArchivers(false);
|
||||
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
}
|
||||
|
||||
public function testAddArgs()
|
||||
{
|
||||
$reflectedParameters = (new \ReflectionMethod($this->sut, 'add'))->getParameters();
|
||||
|
||||
$this->assertCount(1, $reflectedParameters);
|
||||
$this->assertFalse($reflectedParameters[0]->allowsNull());
|
||||
$this->assertFalse($reflectedParameters[0]->isOptional());
|
||||
$this->assertEquals(
|
||||
'Thelia\\Core\\Archiver\\ArchiverInterface',
|
||||
$reflectedParameters[0]->getClass()->getName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3', 'archiver1'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount($i, $archivers);
|
||||
}
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(3, $archivers);
|
||||
}
|
||||
|
||||
public function testSetArchiversArgs()
|
||||
{
|
||||
$reflectedParameters = (new \ReflectionMethod($this->sut, 'setArchivers'))->getParameters();
|
||||
|
||||
$this->assertCount(1, $reflectedParameters);
|
||||
$this->assertFalse($reflectedParameters[0]->allowsNull());
|
||||
$this->assertFalse($reflectedParameters[0]->isOptional());
|
||||
$this->assertTrue($reflectedParameters[0]->isArray());
|
||||
}
|
||||
|
||||
public function testSetArchivers()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3', 'archiver4', 'archiver5'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
}
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(3, $archivers);
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertTrue($this->sut->has('archiver2'));
|
||||
$this->assertTrue($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
$this->assertFalse($this->sut->has('archiver5'));
|
||||
|
||||
$this->sut->setArchivers([$this->stubArchiver, $this->stubArchiver]);
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(2, $archivers);
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has('archiver3'));
|
||||
$this->assertTrue($this->sut->has('archiver4'));
|
||||
$this->assertTrue($this->sut->has('archiver5'));
|
||||
|
||||
$this->setExpectedException('Exception');
|
||||
|
||||
$this->sut->setArchivers(['notAnArchiverInterface']);
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$this->sut->reset();
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
}
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(3, $archivers);
|
||||
|
||||
$this->sut->reset();
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('archiver1'))
|
||||
;
|
||||
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has(-1));
|
||||
$this->assertFalse($this->sut->has(0));
|
||||
$this->assertFalse($this->sut->has(1));
|
||||
$this->assertFalse($this->sut->has(null));
|
||||
$this->assertFalse($this->sut->has(true));
|
||||
$this->assertFalse($this->sut->has(false));
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has(-1));
|
||||
$this->assertFalse($this->sut->has(0));
|
||||
$this->assertFalse($this->sut->has(1));
|
||||
$this->assertFalse($this->sut->has(null));
|
||||
$this->assertFalse($this->sut->has(true));
|
||||
$this->assertFalse($this->sut->has(false));
|
||||
}
|
||||
|
||||
public function testHasThrowException()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('archiver1'))
|
||||
;
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1', true));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->has('archiver2', true);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver3'))
|
||||
;
|
||||
$this->stubArchiver->expects($this->any())->method('isAvailable')->will($this->returnValue(true));
|
||||
|
||||
$unavailableMock = $this->getMock('Thelia\\Core\\Archiver\\ArchiverInterface');
|
||||
$unavailableMock->expects($this->any())->method('getId')->will($this->returnValue('archiver2'));
|
||||
$unavailableMock->expects($this->any())->method('isAvailable')->will($this->returnValue(false));
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
$this->sut->add($this->stubArchiver);
|
||||
$this->sut->add($unavailableMock);
|
||||
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver1'));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver2'));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver3'));
|
||||
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver1', true));
|
||||
$this->isNull('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver2', true));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver3', true));
|
||||
|
||||
$this->isNull('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver1', false));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver2', false));
|
||||
$this->isNull('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver3', false));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->get('archiver4');
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
}
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertTrue($this->sut->has('archiver2'));
|
||||
$this->assertTrue($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->sut->remove('archiver2');
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertTrue($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->sut->remove('archiver1');
|
||||
$this->sut->remove('archiver3');
|
||||
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->remove('archiver4');
|
||||
}
|
||||
}
|
||||
64
tests/phpunit/Thelia/Tests/Core/Event/ActionEventTest.php
Normal file
64
tests/phpunit/Thelia/Tests/Core/Event/ActionEventTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Event;
|
||||
|
||||
use Symfony\Component\Form\Forms;
|
||||
|
||||
/**
|
||||
* Class ActionEventTest
|
||||
* @package Thelia\Tests\Core\Event
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ActionEventTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Form\Form $form
|
||||
*/
|
||||
protected static $form;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$formBuilder = Forms::createFormFactoryBuilder()
|
||||
->getFormFactory()
|
||||
->createNamedBuilder(
|
||||
'test',
|
||||
'form',
|
||||
null,
|
||||
['attr' =>[
|
||||
'thelia_name' => 'test'
|
||||
]]
|
||||
);
|
||||
|
||||
$formBuilder
|
||||
->add('foo', 'text')
|
||||
->add('bar', 'text');
|
||||
|
||||
self::$form = $formBuilder->getForm();
|
||||
}
|
||||
|
||||
public function testBindForm()
|
||||
{
|
||||
$form = self::$form;
|
||||
|
||||
$form->bind([
|
||||
'foo' => 'fooValue',
|
||||
'bar' => 'barValue'
|
||||
]);
|
||||
|
||||
$event = new FooEvent();
|
||||
$event->bindForm($form);
|
||||
|
||||
$this->assertEquals('fooValue', $event->getFoo());
|
||||
$this->assertEquals('barValue', $event->getBar());
|
||||
}
|
||||
}
|
||||
64
tests/phpunit/Thelia/Tests/Core/Event/FooEvent.php
Normal file
64
tests/phpunit/Thelia/Tests/Core/Event/FooEvent.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Event;
|
||||
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
/**
|
||||
* Class FooEvent
|
||||
* @package Thelia\Tests\Core\Event
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class FooEvent extends ActionEvent
|
||||
{
|
||||
protected $foo;
|
||||
protected $bar;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBar()
|
||||
{
|
||||
return $this->bar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $bar
|
||||
* @return $this
|
||||
*/
|
||||
public function setBar($bar)
|
||||
{
|
||||
$this->bar = $bar;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFoo()
|
||||
{
|
||||
return $this->foo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $foo
|
||||
* @return $this
|
||||
*/
|
||||
public function setFoo($foo)
|
||||
{
|
||||
$this->foo = $foo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\EventListener;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Thelia\Core\EventListener\RequestListener;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Tests\WebTestCase;
|
||||
|
||||
/**
|
||||
* Class RequestListenerTest
|
||||
* @package Thelia\Tests\Core\EventListener
|
||||
* @author Gilles Bourgeat <gilles@thelia.net>
|
||||
*/
|
||||
class RequestListenerTest extends WebTestCase
|
||||
{
|
||||
public function testCheckCurrency()
|
||||
{
|
||||
$listener = $this->getRequestListener();
|
||||
|
||||
$event = $this->getGetResponseEvent();
|
||||
/** @var Session $session */
|
||||
$session = $event->getRequest()->getSession();
|
||||
|
||||
// Test with a session that has no currency
|
||||
$listener->checkCurrency($event);
|
||||
$currentCurrency = $session->getCurrency();
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $currentCurrency);
|
||||
|
||||
// Test change currency
|
||||
$newCurrency = CurrencyQuery::create()->filterById($currentCurrency->getId(), Criteria::NOT_IN)->findOne();
|
||||
$event->getRequest()->query->set('currency', $newCurrency->getCode());
|
||||
$listener->checkCurrency($event);
|
||||
$this->assertEquals($session->getCurrency()->getId(), $newCurrency->getId());
|
||||
}
|
||||
|
||||
protected function getGetResponseEvent()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setSession(new Session(new MockArraySessionStorage()));
|
||||
|
||||
/** @var HttpKernelInterface $kernelMock */
|
||||
$kernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
return new GetResponseEvent($kernelMock, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
}
|
||||
|
||||
protected function getRequestListener()
|
||||
{
|
||||
$translator = new Translator(new Container());
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
|
||||
return new RequestListener($translator, $eventDispatcher);
|
||||
}
|
||||
}
|
||||
114
tests/phpunit/Thelia/Tests/Core/Form/TheliaFormFactoryTest.php
Normal file
114
tests/phpunit/Thelia/Tests/Core/Form/TheliaFormFactoryTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Form;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
||||
use Symfony\Component\Form\FormFactoryBuilder;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\Validator\ValidatorBuilder;
|
||||
use Thelia\Core\Form\TheliaFormFactory;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Tests\Resources\Form\Type\TestType;
|
||||
|
||||
/**
|
||||
* Class TheliaFormFactoryTest
|
||||
* @package Thelia\Tests\Controller
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class TheliaFormFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var \Thelia\Core\Form\TheliaFormFactory */
|
||||
protected $factory;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
/**
|
||||
* Add the test type to the factory and
|
||||
* the form to the container
|
||||
*/
|
||||
$factory = new FormFactoryBuilder();
|
||||
$factory->addExtension(new CoreExtension());
|
||||
$factory->addType(new TestType());
|
||||
|
||||
/**
|
||||
* Construct the container
|
||||
*/
|
||||
$container = new Container();
|
||||
$container->set("thelia.form_factory_builder", $factory);
|
||||
$container->set("thelia.translator", new Translator($container));
|
||||
$container->setParameter(
|
||||
"thelia.parser.forms",
|
||||
$definition = array(
|
||||
"test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm",
|
||||
)
|
||||
);
|
||||
|
||||
$request = new Request();
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
$request->setSession(new Session(new MockArraySessionStorage()));
|
||||
$container->set("request", $request);
|
||||
$container->set("request_stack", $requestStack);
|
||||
$container->set("thelia.forms.validator_builder", new ValidatorBuilder());
|
||||
$container->set("event_dispatcher", new EventDispatcher());
|
||||
|
||||
$this->factory = new TheliaFormFactory($requestStack, $container, $definition);
|
||||
}
|
||||
|
||||
public function testCreateFormWithoutType()
|
||||
{
|
||||
/**
|
||||
* If we build the form without type, we only have
|
||||
* the defined fields
|
||||
*/
|
||||
$form = $this->factory->createForm("test_form");
|
||||
|
||||
$this->assertTrue(
|
||||
$form->getForm()->has("test_field")
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->getForm()->has("test_a")
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->getForm()->has("test_b")
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateFormWithType()
|
||||
{
|
||||
/**
|
||||
* If we use a type, we have that type's fields.
|
||||
* -> The implementation is correct.
|
||||
*/
|
||||
$form = $this->factory->createForm("test_form", "test_type");
|
||||
|
||||
$this->assertTrue(
|
||||
$form->getForm()->has("test_field")
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->getForm()->has("test_a")
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->getForm()->has("test_b")
|
||||
);
|
||||
}
|
||||
}
|
||||
291
tests/phpunit/Thelia/Tests/Core/Hook/HookTest.php
Normal file
291
tests/phpunit/Thelia/Tests/Core/Hook/HookTest.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Hook;
|
||||
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\Module;
|
||||
use Thelia\Tests\WebTestCase;
|
||||
|
||||
/**
|
||||
* Class HookTest
|
||||
* @package Thelia\Tests\Core\Hook
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class HookTest extends WebTestCase
|
||||
{
|
||||
public static $templateBackupPath;
|
||||
|
||||
public static $cache_dir;
|
||||
|
||||
/**
|
||||
* get the content of the test page with our test template and test module.
|
||||
* the content is used by all other test functions and saved under cache/test/hook.html
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function testHome()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/',
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = $client->getResponse()->getContent();
|
||||
|
||||
file_put_contents($this::$cache_dir . '/hook.html', $content);
|
||||
|
||||
$this->assertNotFalse(strpos($content, "TEMPLATE-TEST-HOOK"));
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testConfigTag($content)
|
||||
{
|
||||
$this->assertStringContains($content, "main.head-top test0");
|
||||
$this->assertStringContains($content, "main.head-top test1");
|
||||
$this->assertStringContains($content, "main.head-top test2");
|
||||
// tag with active="0", should not be present
|
||||
$this->assertStringNotContains($content, "main.head-top test3");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testHookFunction($content)
|
||||
{
|
||||
$this->assertStringContains($content, "main.body-top 1-1");
|
||||
$this->assertStringContains($content, "main.body-top 1-2");
|
||||
$this->assertStringContains($content, "main.body-top 2");
|
||||
$this->assertStringBefore($content, "main.body-top 1", "main.body-top 2");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testHookIfElse($content)
|
||||
{
|
||||
$this->assertStringContains($content, "main.navbar-secondary 1");
|
||||
$this->assertStringContains($content, "::main.navbar-secondary ifhook::");
|
||||
$this->assertStringNotContains($content, "::main.navbar-secondary elsehook::");
|
||||
|
||||
$this->assertStringContains($content, "::main.navbar-primary ifhook::");
|
||||
$this->assertStringNotContains($content, "::main.navbar-primary elsehook::");
|
||||
|
||||
// block
|
||||
$this->assertStringNotContains($content, "::product.additional ifhook::");
|
||||
$this->assertStringContains($content, "::product.additional elsehook::");
|
||||
|
||||
$this->assertStringContains($content, "::main.footer-body ifhook::");
|
||||
$this->assertStringNotContains($content, "::main.footer-body elsehook::");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testHookBlock($content)
|
||||
{
|
||||
$this->assertStringContains($content, "::main.footer-body id1 class1 content1::");
|
||||
$this->assertStringContains($content, "::main.footer-body id2 class2 content2::");
|
||||
$this->assertStringBefore($content, "::main.footer-body id1 class1 content1::", "::main.footer-body id2 class2 content2::");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testBaseHookGlobal($content)
|
||||
{
|
||||
$this->assertStringContains($content, ":: main.content-top ::");
|
||||
$this->assertStringContains($content, ":: request : GET / HTTP/1.1");
|
||||
$this->assertRegExp('/:: session : [a-f0-9]{40,} ::/', $content);
|
||||
$this->assertStringContains($content, ":: cart : not null ::");
|
||||
$this->assertStringContains($content, ":: order : not null ::");
|
||||
$this->assertStringContains($content, ":: currency : 1 ::");
|
||||
$this->assertStringContains($content, ":: customer : ::");
|
||||
$this->assertStringContains($content, ":: lang : 2 ::");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testBaseHookRender($content)
|
||||
{
|
||||
$this->assertStringContains($content, ":: function render ::");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testBaseHookDump($content)
|
||||
{
|
||||
$this->assertStringContains($content, ":: function dump ::");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testBaseHookAddCSS($content)
|
||||
{
|
||||
$this->assertRegExp('/<link\\s+rel="stylesheet"\\s+type="text\\/css"\\s+href="http:\\/\\/localhost\\/assets\\/frontOffice\\/hooktest\\/HookTest\\/assets\\/css\\/.*\\.css"\\s*\\/>/', $content);
|
||||
$this->assertRegExp('/<link\\s+rel="stylesheet"\\s+type="text\\/css"\\s+href="http:\\/\\/localhost\\/assets\\/frontOffice\\/hooktest\\/HookTest\\/assets\\/css\\/.*\\.css"\\s+media="print"\\s*\\/>/', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testBaseHookAddJS($content)
|
||||
{
|
||||
$this->assertRegExp('/<script\\s+type="text\\/javascript"\\s+src="http:\\/\\/localhost\\/assets\\/frontOffice\\/hooktest\\/HookTest\\/assets\\/js\\/.*\\.js"\\s*>/', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testBaseHookTrans($content)
|
||||
{
|
||||
$this->assertStringContains($content, ":: Hodor en_US Hodor ::");
|
||||
$this->assertStringContains($content, ":: Hello en_US World ::");
|
||||
$this->assertStringContains($content, ":: Hello Hodor ::");
|
||||
$this->assertStringContains($content, ":: Salut fr_FR Hodor ::");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @depends testHome
|
||||
*/
|
||||
public function testBaseHookAssetsOverride($content)
|
||||
{
|
||||
$this->assertStringContains($content, ":: file override1 from module/default ::");
|
||||
$this->assertStringContains($content, ":: file override2 from module/hooktest ::");
|
||||
$this->assertStringContains($content, ":: file override3 from template/hooktest ::");
|
||||
|
||||
// assets function
|
||||
preg_match('/asset file 1 : http:\/\/localhost\/([^\s]*)/', $content, $matches);
|
||||
$this->assertCount(2, $matches);
|
||||
$this->assertFileExists(THELIA_WEB_DIR . $matches[1]);
|
||||
$this->assertStringContains(file_get_contents(THELIA_WEB_DIR . $matches[1]), "/* style1 in module/default */");
|
||||
|
||||
preg_match('/asset file 2 : http:\/\/localhost\/([^\s]*)/', $content, $matches);
|
||||
$this->assertCount(2, $matches);
|
||||
$this->assertFileExists(THELIA_WEB_DIR . $matches[1]);
|
||||
$this->assertStringContains(file_get_contents(THELIA_WEB_DIR . $matches[1]), "/* style2 in module/hooktest */");
|
||||
|
||||
preg_match('/asset file 3 : http:\/\/localhost\/([^\s]*)/', $content, $matches);
|
||||
$this->assertCount(2, $matches);
|
||||
$this->assertFileExists(THELIA_WEB_DIR . $matches[1]);
|
||||
$this->assertStringContains(file_get_contents(THELIA_WEB_DIR . $matches[1]), "/* style3 in template/hooktest */");
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$cache_dir = THELIA_ROOT . "cache/test";
|
||||
self::$templateBackupPath = ConfigQuery::read('active-front-template', 'default');
|
||||
ConfigQuery::write('active-front-template', 'hooktest');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
ConfigQuery::write('active-front-template', self::$templateBackupPath);
|
||||
}
|
||||
|
||||
protected function assertStringContains($data, $needle, $message = "")
|
||||
{
|
||||
$this->assertTrue((false !== strpos($data, $needle)), $message);
|
||||
}
|
||||
|
||||
protected function assertStringNotContains($data, $needle, $message = "")
|
||||
{
|
||||
$this->assertTrue((false === strpos($data, $needle)), $message);
|
||||
}
|
||||
|
||||
protected function assertStringBefore($data, $string1, $string2, $message = "")
|
||||
{
|
||||
$this->assertTrue((strpos($data, $string1) < strpos($data, $string2)), $message);
|
||||
}
|
||||
|
||||
public function getKernel()
|
||||
{
|
||||
$kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface");
|
||||
|
||||
return $kernel;
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public static function deleteDirectory($dir)
|
||||
{
|
||||
if (!file_exists($dir)) {
|
||||
return true;
|
||||
}
|
||||
if (!is_dir($dir)) {
|
||||
return unlink($dir);
|
||||
}
|
||||
foreach (scandir($dir) as $item) {
|
||||
if ($item == '.' || $item == '..') {
|
||||
continue;
|
||||
}
|
||||
if (!self::deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return rmdir($dir);
|
||||
}
|
||||
|
||||
public static function copyDirectory($sourceDir, $targetDir)
|
||||
{
|
||||
if (!file_exists($sourceDir)) {
|
||||
return false;
|
||||
}
|
||||
if (!is_dir($sourceDir)) {
|
||||
return copy($sourceDir, $targetDir);
|
||||
}
|
||||
if (!mkdir($targetDir)) {
|
||||
return false;
|
||||
}
|
||||
foreach (scandir($sourceDir) as $item) {
|
||||
if ($item == '.' || $item == '..') {
|
||||
continue;
|
||||
}
|
||||
if (!self::copyDirectory($sourceDir.DIRECTORY_SEPARATOR.$item, $targetDir.DIRECTORY_SEPARATOR.$item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\HttpFoundation;
|
||||
|
||||
/**
|
||||
* the the helpers addinf in Request class
|
||||
*
|
||||
* Class RequestTest
|
||||
* @package Thelia\Tests\Core\HttpFoundation
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetUriAddingParameters()
|
||||
{
|
||||
$request = $this->getMock(
|
||||
"Thelia\Core\HttpFoundation\Request",
|
||||
array("getUri", "getQueryString")
|
||||
);
|
||||
|
||||
$request->expects($this->any())
|
||||
->method("getUri")
|
||||
->will($this->onConsecutiveCalls(
|
||||
"http://localhost/",
|
||||
"http://localhost/?test=fu"
|
||||
));
|
||||
|
||||
$request->expects($this->any())
|
||||
->method("getQueryString")
|
||||
->will($this->onConsecutiveCalls(
|
||||
"",
|
||||
"test=fu"
|
||||
));
|
||||
|
||||
$result = $request->getUriAddingParameters(array("foo" => "bar"));
|
||||
|
||||
$this->assertEquals("http://localhost/?foo=bar", $result);
|
||||
|
||||
$result = $request->getUriAddingParameters(array("foo" => "bar"));
|
||||
|
||||
$this->assertEquals("http://localhost/?test=fu&foo=bar", $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\HttpFoundation\Session;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\Cart;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Tools\TokenProvider;
|
||||
|
||||
/**
|
||||
* Test the helpers adding in Session class
|
||||
*
|
||||
* Class SessionTest
|
||||
* @package Thelia\Tests\Core\HttpFoundation\Session
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Session */
|
||||
protected $session;
|
||||
|
||||
/** @var RequestStack */
|
||||
protected $requestStack;
|
||||
|
||||
/** @var EventDispatcher */
|
||||
protected $dispatcher;
|
||||
|
||||
protected $dispatcherNull;
|
||||
|
||||
protected $cartToken;
|
||||
|
||||
protected $cartAction;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->requestStack = new RequestStack();
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$this->requestStack->push($request);
|
||||
|
||||
$this->session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request->setSession($this->session);
|
||||
|
||||
$this->dispatcher = new EventDispatcher();
|
||||
|
||||
$translator = new Translator($this->getMock('\Symfony\Component\DependencyInjection\ContainerInterface'));
|
||||
|
||||
$token = new TokenProvider($this->requestStack, $translator, 'test');
|
||||
|
||||
$this->dispatcher->addSubscriber(new \Thelia\Action\Cart($this->requestStack, $token));
|
||||
|
||||
$this->session->setSessionCart(null);
|
||||
|
||||
$request->setSession($this->session);
|
||||
|
||||
/** @var \Thelia\Action\Cart cartAction */
|
||||
$this->cartAction = new \Thelia\Action\Cart(
|
||||
$this->requestStack,
|
||||
new TokenProvider($this->requestStack, $translator, 'baba au rhum')
|
||||
);
|
||||
|
||||
$this->dispatcherNull = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
|
||||
$this->dispatcher = $this->getMock(
|
||||
'Symfony\Component\EventDispatcher\EventDispatcherInterface',
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
$this->dispatcher
|
||||
->expects($this->any())
|
||||
->method('dispatch')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function ($type, $event) {
|
||||
if ($type == TheliaEvents::CART_RESTORE_CURRENT) {
|
||||
$this->cartAction->restoreCurrentCart($event, null, $this->dispatcher);
|
||||
} elseif ($type == TheliaEvents::CART_CREATE_NEW) {
|
||||
$this->cartAction->createEmptyCart($event, null, $this->dispatcher);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testGetCartWithoutExistingCartAndNoDispatcher()
|
||||
{
|
||||
$session = $this->session;
|
||||
|
||||
$cart = $session->getSessionCart();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testGetCartWithoutExistingCartAndDeprecatedMethod()
|
||||
{
|
||||
$session = $this->session;
|
||||
|
||||
@$session->getSessionCart();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testGetCartUnableToCreateCart()
|
||||
{
|
||||
$session = $this->session;
|
||||
|
||||
$session->getSessionCart($this->dispatcherNull);
|
||||
}
|
||||
|
||||
public function testGetCartWithoutExistingCartNoCustomer()
|
||||
{
|
||||
$session = $this->session;
|
||||
|
||||
$cart = $session->getSessionCart($this->dispatcher);
|
||||
|
||||
$this->assertNotNull($cart);
|
||||
$this->assertInstanceOf("\Thelia\Model\Cart", $cart, '$cart must be an instance of Thelia\Model\Cart');
|
||||
}
|
||||
|
||||
public function testGetCartWithExistingCustomerButNoCart()
|
||||
{
|
||||
$session = $this->session;
|
||||
|
||||
//create a fake customer just for test. If not persists test fails !
|
||||
$customer = new Customer();
|
||||
$customer->setFirstname("john test session");
|
||||
$customer->setLastname("doe");
|
||||
$customer->setTitleId(1);
|
||||
$customer->save();
|
||||
|
||||
$session->setCustomerUser($customer);
|
||||
|
||||
$cart = $session->getSessionCart($this->dispatcher);
|
||||
|
||||
$this->assertNotNull($cart);
|
||||
$this->assertEquals($customer->getId(), $cart->getCustomerId());
|
||||
$this->assertInstanceOf("\Thelia\Model\Cart", $cart, '$cart must be an instance of Thelia\Model\Cart');
|
||||
}
|
||||
|
||||
public function testGetCartWithExistingCartAndCustomerButWithoutReferenceToCustomerInCart()
|
||||
{
|
||||
$session = $this->session;
|
||||
|
||||
// create a fake customer just for test. If not persists test fails !
|
||||
$customer = new Customer();
|
||||
$customer->setFirstname("john test session");
|
||||
$customer->setLastname("doe");
|
||||
$customer->setTitleId(1);
|
||||
$customer->save();
|
||||
|
||||
$session->setCustomerUser($customer);
|
||||
|
||||
$testCart = new Cart();
|
||||
$testCart->setToken(uniqid("testSessionGetCart2", true));
|
||||
$testCart->save();
|
||||
|
||||
$this->requestStack->getCurrentRequest()->cookies->set(ConfigQuery::read("cart.cookie_name", 'thelia_cart'), $testCart->getToken());
|
||||
|
||||
$cart = $session->getSessionCart($this->dispatcher);
|
||||
|
||||
$this->assertNotNull($cart);
|
||||
$this->assertEquals($customer->getId(), $cart->getCustomerId());
|
||||
$this->assertInstanceOf("\Thelia\Model\Cart", $cart, '$cart must be an instance of Thelia\Model\Cart');
|
||||
}
|
||||
|
||||
public function testGetCartWithExistingCartAndCustomerAndReferencesEachOther()
|
||||
{
|
||||
$session = $this->session;
|
||||
|
||||
//create a fake customer just for test. If not persists test fails !
|
||||
$customer = new Customer();
|
||||
$customer->setFirstname("john test session");
|
||||
$customer->setLastname("doe");
|
||||
$customer->setTitleId(1);
|
||||
$customer->save();
|
||||
|
||||
$session->setCustomerUser($customer);
|
||||
|
||||
$testCart = new Cart();
|
||||
$testCart->setToken(uniqid("testSessionGetCart3", true));
|
||||
$testCart->setCustomerId($customer->getId());
|
||||
$testCart->save();
|
||||
|
||||
$this->requestStack->getCurrentRequest()->cookies->set(ConfigQuery::read("cart.cookie_name", 'thelia_cart'), $testCart->getToken());
|
||||
|
||||
$cart = $session->getSessionCart($this->dispatcher);
|
||||
|
||||
$this->assertNotNull($cart);
|
||||
$this->assertInstanceOf("\Thelia\Model\Cart", $cart, '$cart must be an instance of Thelia\Model\Cart');
|
||||
}
|
||||
|
||||
public function testSetCurrency()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$currentCurrency = (new Currency())->setId(99);
|
||||
$session->setCurrency($currentCurrency);
|
||||
$this->assertEquals($currentCurrency->getId(), $session->getCurrency()->getId());
|
||||
}
|
||||
|
||||
public function testGetCurrencyWithParameterForceDefault()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$this->assertNull($session->getCurrency(false));
|
||||
}
|
||||
|
||||
public function testGetCurrency()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $session->getCurrency());
|
||||
}
|
||||
|
||||
public function testGetAdminEditionCurrencyWithCurrencyInSession()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$currentCurrency = (new Currency())->setId(99);
|
||||
$session->setAdminEditionCurrency($currentCurrency);
|
||||
$this->assertEquals($currentCurrency->getId(), $session->getAdminEditionCurrency()->getId());
|
||||
}
|
||||
|
||||
public function testGetAdminEditionCurrencyWithNoCurrencyInSession()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $session->getAdminEditionCurrency());
|
||||
}
|
||||
}
|
||||
209
tests/phpunit/Thelia/Tests/Core/Routing/RewritingRouterTest.php
Normal file
209
tests/phpunit/Thelia/Tests/Core/Routing/RewritingRouterTest.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Routing;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\HttpKernel\Exception\RedirectException;
|
||||
use Thelia\Core\Routing\RewritingRouter;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\RewritingUrlQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class RewritingRouterTest
|
||||
* @package Thelia\Tests\Core\Routing
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class RewritingRouterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$url = new URL();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
|
||||
* @covers RewritingRouter::generate
|
||||
*/
|
||||
public function testGenerate()
|
||||
{
|
||||
$rewritingRouter = new RewritingRouter();
|
||||
$rewritingRouter->generate('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
|
||||
* @covers RewritingRouter::match
|
||||
*/
|
||||
public function testMatch()
|
||||
{
|
||||
$rewritingRouter = new RewritingRouter();
|
||||
$rewritingRouter->match('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
|
||||
* covers RewritingRouter::matchRequest
|
||||
*/
|
||||
public function testMatchRequestWithNoRewriting()
|
||||
{
|
||||
ConfigQuery::write('rewriting_enable', 0);
|
||||
$request = new Request();
|
||||
|
||||
$rewritingRouter = new RewritingRouter();
|
||||
$rewritingRouter->matchRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
|
||||
* covers RewritingRouter::matchRequest
|
||||
*/
|
||||
public function testMatchRequestWithNonExistingUrl()
|
||||
{
|
||||
ConfigQuery::write('rewriting_enable', 1);
|
||||
$request = Request::create('http://test.com/foo');
|
||||
|
||||
$rewritingRouter = new RewritingRouter();
|
||||
$rewritingRouter->matchRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* covers RewritingRouter::matchRequest
|
||||
*/
|
||||
public function testMatchRequestWithSameLocale()
|
||||
{
|
||||
ConfigQuery::write('rewriting_enable', 1);
|
||||
ConfigQuery::write('one_domain_foreach_lang', 0);
|
||||
|
||||
$defaultLang = LangQuery::create()->findOneByByDefault(1);
|
||||
$product = ProductQuery::create()->findOne();
|
||||
$product->setLocale($defaultLang->getLocale());
|
||||
|
||||
$rewriting = RewritingUrlQuery::create()
|
||||
->filterByView('product')
|
||||
->filterByViewId($product->getId())
|
||||
->filterByViewLocale($defaultLang->getLocale())
|
||||
->filterByRedirected(null)
|
||||
->findOne();
|
||||
|
||||
$request = Request::create('http://test.com/'.$rewriting->getUrl());
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$session->setLang($defaultLang);
|
||||
$request->setSession($session);
|
||||
$url = new URL();
|
||||
$requestContext = new RequestContext();
|
||||
$requestContext->fromRequest($request);
|
||||
$url->setRequestContext($requestContext);
|
||||
|
||||
$rewritingRouter = new RewritingRouter();
|
||||
$parameters = $rewritingRouter->matchRequest($request);
|
||||
|
||||
$this->assertEquals('Thelia\\Controller\\Front\\DefaultController::noAction', $parameters['_controller']);
|
||||
$this->assertEquals('rewrite', $parameters['_route']);
|
||||
$this->assertTrue($parameters['_rewritten']);
|
||||
|
||||
$this->assertEquals($product->getId(), $request->query->get('product_id'));
|
||||
$this->assertEquals('product', $request->attributes->get('_view'));
|
||||
}
|
||||
|
||||
/**
|
||||
* covers RewritingRouter::matchRequest
|
||||
*/
|
||||
public function testMatchRequestWithDifferentLocale()
|
||||
{
|
||||
ConfigQuery::write('rewriting_enable', 1);
|
||||
ConfigQuery::write('one_domain_foreach_lang', 0);
|
||||
|
||||
$defaultLang = LangQuery::create()->findOneByLocale('en_US');
|
||||
$product = ProductQuery::create()->findOne();
|
||||
$product->setLocale($defaultLang->getLocale());
|
||||
|
||||
$rewriting = RewritingUrlQuery::create()
|
||||
->filterByView('product')
|
||||
->filterByViewId($product->getId())
|
||||
->filterByViewLocale('fr_FR')
|
||||
->filterByRedirected(null)
|
||||
->findOne();
|
||||
|
||||
$request = Request::create('http://test.com/'.$rewriting->getUrl());
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$session->setLang($defaultLang);
|
||||
$request->setSession($session);
|
||||
$url = new URL();
|
||||
$requestContext = new RequestContext();
|
||||
$requestContext->fromRequest($request);
|
||||
$url->setRequestContext($requestContext);
|
||||
|
||||
$rewritingRouter = new RewritingRouter();
|
||||
$parameters = $rewritingRouter->matchRequest($request);
|
||||
|
||||
$this->assertEquals('Thelia\\Controller\\Front\\DefaultController::noAction', $parameters['_controller']);
|
||||
$this->assertEquals('rewrite', $parameters['_route']);
|
||||
$this->assertTrue($parameters['_rewritten']);
|
||||
|
||||
$this->assertEquals($product->getId(), $request->query->get('product_id'));
|
||||
$this->assertEquals('product', $request->attributes->get('_view'));
|
||||
$this->assertNotEquals($defaultLang, $request->getSession()->getLang());
|
||||
}
|
||||
|
||||
/**
|
||||
* covers RewritingRouter::matchRequest
|
||||
*/
|
||||
public function testMatchRequestWithDifferentLocaleAndDomain()
|
||||
{
|
||||
ConfigQuery::write('rewriting_enable', 1);
|
||||
ConfigQuery::write('one_domain_foreach_lang', 1);
|
||||
|
||||
$defaultLang = LangQuery::create()->findOneByLocale('en_US');
|
||||
$defaultLang->setUrl('http://test_en.com');
|
||||
|
||||
$frenchLang = LangQuery::create()->findOneByLocale('fr_FR');
|
||||
$saveUrl = $frenchLang->getUrl();
|
||||
$frenchLang->setUrl('http://test.com')->save();
|
||||
|
||||
$product = ProductQuery::create()->findOne();
|
||||
$product->setLocale($defaultLang->getLocale());
|
||||
|
||||
$rewriting = RewritingUrlQuery::create()
|
||||
->filterByView('product')
|
||||
->filterByViewId($product->getId())
|
||||
->filterByViewLocale('fr_FR')
|
||||
->filterByRedirected(null)
|
||||
->findOne();
|
||||
|
||||
$request = Request::create('http://test_en.com/'.$rewriting->getUrl());
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$session->setLang($defaultLang);
|
||||
$request->setSession($session);
|
||||
$url = new URL();
|
||||
$requestContext = new RequestContext();
|
||||
$requestContext->fromRequest($request);
|
||||
$url->setRequestContext($requestContext);
|
||||
|
||||
try {
|
||||
$rewritingRouter = new RewritingRouter();
|
||||
$parameters = $rewritingRouter->matchRequest($request);
|
||||
} catch (RedirectException $e) {
|
||||
$this->assertRegExp("/http:\/\/test\.com\/.*/", $e->getUrl());
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fail('->matchRequest must throw a RedirectException');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Tests\Core\Serializer\Serializer;
|
||||
|
||||
use Thelia\Core\Serializer\Serializer\JSONSerializer as SUT;
|
||||
|
||||
/**
|
||||
* Class JSONSerializerTest
|
||||
* @author Jérôme Billiras <jbilliras@openstudio.fr>
|
||||
*/
|
||||
class JSONSerializerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Thelia\Core\Serializer\Serializer\JSONSerializer
|
||||
*/
|
||||
protected $sut;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $stubArchiver;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->sut = new SUT;
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
$this->assertInternalType('string', $this->sut->getId());
|
||||
$this->assertEquals('thelia.json', $this->sut->getId());
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertInternalType('string', $this->sut->getName());
|
||||
$this->assertEquals('JSON', $this->sut->getName());
|
||||
}
|
||||
|
||||
public function testGetExtension()
|
||||
{
|
||||
$this->assertInternalType('string', $this->sut->getExtension());
|
||||
$this->assertEquals('json', $this->sut->getExtension());
|
||||
}
|
||||
|
||||
public function testGetMimeType()
|
||||
{
|
||||
$this->assertInternalType('string', $this->sut->getMimeType());
|
||||
$this->assertEquals('application/json', $this->sut->getMimeType());
|
||||
}
|
||||
|
||||
public function testSerialize()
|
||||
{
|
||||
$stdClass = new \stdClass;
|
||||
$stdClass->key = 'value';
|
||||
|
||||
$dataSet = [
|
||||
['simple string', '"simple string"'],
|
||||
['-1', '"-1"'],
|
||||
['0', '"0"'],
|
||||
['1', '"1"'],
|
||||
['-1.0', '"-1.0"'],
|
||||
['0.0', '"0.0"'],
|
||||
['1.0', '"1.0"'],
|
||||
[-1, '-1'],
|
||||
[0, '0'],
|
||||
[1, '1'],
|
||||
[-1.0, '-1.0'],
|
||||
[0.0, '0.0'],
|
||||
[1.0, '1.0'],
|
||||
[[], '[]'],
|
||||
[['simple string'], '["simple string"]'],
|
||||
[['simple string', 'simple string'], '["simple string","simple string"]'],
|
||||
[['key' => 'value'], '{"key":"value"}'],
|
||||
[$stdClass, '{"key":"value"}']
|
||||
];
|
||||
|
||||
foreach ($dataSet as $data) {
|
||||
$this->assertEquals($data[1], $this->sut->serialize($data[0]));
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeparator()
|
||||
{
|
||||
$this->assertInternalType('string', $this->sut->separator());
|
||||
$this->assertEquals(',' . PHP_EOL, $this->sut->separator());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Tests\Core\Serializer;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Core\Serializer\SerializerManager as SUT;
|
||||
|
||||
/**
|
||||
* Class SerializerManagerTest
|
||||
* @author Jérôme Billiras <jbilliras@openstudio.fr>
|
||||
*/
|
||||
class SerializerManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Thelia\Core\Serializer\SerializerManager
|
||||
*/
|
||||
protected $sut;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $stubSerializer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->sut = new SUT;
|
||||
$this->stubSerializer = $this->getMock('Thelia\\Core\\Serializer\\SerializerInterface');
|
||||
|
||||
new Translator(new Container);
|
||||
}
|
||||
|
||||
public function testGetSerializers()
|
||||
{
|
||||
$serializers = $this->sut->getSerializers();
|
||||
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount(0, $serializers);
|
||||
}
|
||||
|
||||
public function testAddArgs()
|
||||
{
|
||||
$reflectedParameters = (new \ReflectionMethod($this->sut, 'add'))->getParameters();
|
||||
|
||||
$this->assertCount(1, $reflectedParameters);
|
||||
$this->assertFalse($reflectedParameters[0]->allowsNull());
|
||||
$this->assertFalse($reflectedParameters[0]->isOptional());
|
||||
$this->assertEquals(
|
||||
'Thelia\\Core\\Serializer\\SerializerInterface',
|
||||
$reflectedParameters[0]->getClass()->getName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$this->stubSerializer
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('serializer1', 'serializer2', 'serializer3', 'serializer1'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubSerializer);
|
||||
|
||||
$serializers = $this->sut->getSerializers();
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount($i, $serializers);
|
||||
}
|
||||
|
||||
$this->sut->add($this->stubSerializer);
|
||||
|
||||
$serializers = $this->sut->getSerializers();
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount(3, $serializers);
|
||||
}
|
||||
|
||||
public function testSetSerializersArgs()
|
||||
{
|
||||
$reflectedParameters = (new \ReflectionMethod($this->sut, 'setSerializers'))->getParameters();
|
||||
|
||||
$this->assertCount(1, $reflectedParameters);
|
||||
$this->assertFalse($reflectedParameters[0]->allowsNull());
|
||||
$this->assertFalse($reflectedParameters[0]->isOptional());
|
||||
$this->assertTrue($reflectedParameters[0]->isArray());
|
||||
}
|
||||
|
||||
public function testSetSerializers()
|
||||
{
|
||||
$this->stubSerializer
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('serializer1', 'serializer2', 'serializer3', 'serializer4', 'serializer5'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubSerializer);
|
||||
}
|
||||
|
||||
$serializers = $this->sut->getSerializers();
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount(3, $serializers);
|
||||
$this->assertTrue($this->sut->has('serializer1'));
|
||||
$this->assertTrue($this->sut->has('serializer2'));
|
||||
$this->assertTrue($this->sut->has('serializer3'));
|
||||
$this->assertFalse($this->sut->has('serializer4'));
|
||||
$this->assertFalse($this->sut->has('serializer5'));
|
||||
|
||||
$this->sut->setSerializers([$this->stubSerializer, $this->stubSerializer]);
|
||||
|
||||
$serializers = $this->sut->getSerializers();
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount(2, $serializers);
|
||||
$this->assertFalse($this->sut->has('serializer1'));
|
||||
$this->assertFalse($this->sut->has('serializer2'));
|
||||
$this->assertFalse($this->sut->has('serializer3'));
|
||||
$this->assertTrue($this->sut->has('serializer4'));
|
||||
$this->assertTrue($this->sut->has('serializer5'));
|
||||
|
||||
$this->setExpectedException('Exception');
|
||||
|
||||
$this->sut->setSerializers(['notASerializerInterface']);
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$this->sut->reset();
|
||||
|
||||
$serializers = $this->sut->getSerializers();
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount(0, $serializers);
|
||||
|
||||
$this->stubSerializer
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('serializer1', 'serializer2', 'serializer3'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubSerializer);
|
||||
}
|
||||
|
||||
$serializers = $this->sut->getSerializers();
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount(3, $serializers);
|
||||
|
||||
$this->sut->reset();
|
||||
|
||||
$serializers = $this->sut->getSerializers();
|
||||
$this->assertInternalType('array', $serializers);
|
||||
$this->assertCount(0, $serializers);
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->stubSerializer
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('serializer1'))
|
||||
;
|
||||
|
||||
$this->assertFalse($this->sut->has('serializer1'));
|
||||
$this->assertFalse($this->sut->has('serializer2'));
|
||||
$this->assertFalse($this->sut->has(-1));
|
||||
$this->assertFalse($this->sut->has(0));
|
||||
$this->assertFalse($this->sut->has(1));
|
||||
$this->assertFalse($this->sut->has(null));
|
||||
$this->assertFalse($this->sut->has(true));
|
||||
$this->assertFalse($this->sut->has(false));
|
||||
|
||||
$this->sut->add($this->stubSerializer);
|
||||
|
||||
$this->assertTrue($this->sut->has('serializer1'));
|
||||
$this->assertFalse($this->sut->has('serializer2'));
|
||||
$this->assertFalse($this->sut->has(-1));
|
||||
$this->assertFalse($this->sut->has(0));
|
||||
$this->assertFalse($this->sut->has(1));
|
||||
$this->assertFalse($this->sut->has(null));
|
||||
$this->assertFalse($this->sut->has(true));
|
||||
$this->assertFalse($this->sut->has(false));
|
||||
}
|
||||
|
||||
public function testHasThrowException()
|
||||
{
|
||||
$this->stubSerializer
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('serializer1'))
|
||||
;
|
||||
|
||||
$this->sut->add($this->stubSerializer);
|
||||
|
||||
$this->assertTrue($this->sut->has('serializer1', true));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->has('serializer2', true);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->stubSerializer
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('serializer1', 'serializer2', 'serializer3'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubSerializer);
|
||||
}
|
||||
|
||||
$this->assertInstanceOf('Thelia\\Core\\Serializer\\SerializerInterface', $this->sut->get('serializer1'));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Serializer\\SerializerInterface', $this->sut->get('serializer2'));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Serializer\\SerializerInterface', $this->sut->get('serializer3'));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->get('serializer4');
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->assertFalse($this->sut->has('serializer1'));
|
||||
$this->assertFalse($this->sut->has('serializer2'));
|
||||
$this->assertFalse($this->sut->has('serializer3'));
|
||||
$this->assertFalse($this->sut->has('serializer4'));
|
||||
|
||||
$this->stubSerializer
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('serializer1', 'serializer2', 'serializer3'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubSerializer);
|
||||
}
|
||||
|
||||
$this->assertTrue($this->sut->has('serializer1'));
|
||||
$this->assertTrue($this->sut->has('serializer2'));
|
||||
$this->assertTrue($this->sut->has('serializer3'));
|
||||
$this->assertFalse($this->sut->has('serializer4'));
|
||||
|
||||
$this->sut->remove('serializer2');
|
||||
|
||||
$this->assertTrue($this->sut->has('serializer1'));
|
||||
$this->assertFalse($this->sut->has('serializer2'));
|
||||
$this->assertTrue($this->sut->has('serializer3'));
|
||||
$this->assertFalse($this->sut->has('serializer4'));
|
||||
|
||||
$this->sut->remove('serializer1');
|
||||
$this->sut->remove('serializer3');
|
||||
|
||||
$this->assertFalse($this->sut->has('serializer1'));
|
||||
$this->assertFalse($this->sut->has('serializer2'));
|
||||
$this->assertFalse($this->sut->has('serializer3'));
|
||||
$this->assertFalse($this->sut->has('serializer4'));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->remove('serializer4');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Element;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\TaxEngine\TaxEngine;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $container;
|
||||
|
||||
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->container = new ContainerBuilder();
|
||||
|
||||
$this->container->setParameter(
|
||||
"thelia.parser.loops",
|
||||
[
|
||||
"tested-loop" => $this->getTestedClassName()
|
||||
]
|
||||
);
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = new Request();
|
||||
$requestStack = new RequestStack();
|
||||
|
||||
$request->setSession($session);
|
||||
|
||||
/*$stubEventdispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcher')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubSecurityContext = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();*/
|
||||
|
||||
/*$stubAdapter->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));*/
|
||||
|
||||
/*$this->request = new Request();
|
||||
$this->request->setSession(new Session(new MockArraySessionStorage()));
|
||||
|
||||
$this->dispatcher = new EventDispatcher();
|
||||
|
||||
$this->securityContext = new SecurityContext($this->request);*/
|
||||
|
||||
$stubRouterAdmin = $this->getMockBuilder('\Symfony\Component\Routing\Router')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getContext'))
|
||||
->getMock();
|
||||
|
||||
$stubRequestContext = $this->getMockBuilder('\Symfony\Component\Routing\RequestContext')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getHost'))
|
||||
->getMock();
|
||||
|
||||
$stubRequestContext->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('localhost'));
|
||||
|
||||
$stubRouterAdmin->expects($this->any())
|
||||
->method('getContext')
|
||||
->will($this->returnValue(
|
||||
$stubRequestContext
|
||||
));
|
||||
|
||||
$requestStack->push($request);
|
||||
$this->container->set('request', $request);
|
||||
$this->container->set('request_stack', $requestStack);
|
||||
$this->container->set('event_dispatcher', new EventDispatcher());
|
||||
$this->container->set('thelia.translator', new Translator($this->container));
|
||||
$this->container->set('thelia.securityContext', new SecurityContext($requestStack));
|
||||
$this->container->set('router.admin', $stubRouterAdmin);
|
||||
$this->container->set('thelia.url.manager', new URL($this->container));
|
||||
$this->container->set('thelia.taxEngine', new TaxEngine($requestStack));
|
||||
|
||||
$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');
|
||||
$page = 0;
|
||||
$methodReturn = $method->invokeArgs($this->instance, array(&$page));
|
||||
|
||||
$this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn);
|
||||
}
|
||||
|
||||
public function baseTestSearchById($id, $other_args = array())
|
||||
{
|
||||
$this->instance->initializeArgs(array_merge(
|
||||
$this->getMandatoryArguments(),
|
||||
array(
|
||||
"type" => "foo",
|
||||
"name" => "foo",
|
||||
"id" => $id,
|
||||
),
|
||||
$other_args
|
||||
));
|
||||
|
||||
$dummy = null;
|
||||
$loopResults = $this->instance->exec($dummy);
|
||||
|
||||
$this->assertEquals(1, $loopResults->getCount());
|
||||
|
||||
$substitutions = $loopResults->current()->getVarVal();
|
||||
|
||||
$this->assertEquals($id, $substitutions['ID']);
|
||||
}
|
||||
|
||||
public function baseTestSearchWithLimit($limit)
|
||||
{
|
||||
$this->instance->initializeArgs(array_merge(
|
||||
$this->getMandatoryArguments(),
|
||||
array(
|
||||
"type" => "foo",
|
||||
"name" => "foo",
|
||||
"limit" => $limit,
|
||||
)
|
||||
));
|
||||
|
||||
$dummy = null;
|
||||
$loopResults = $this->instance->exec($dummy);
|
||||
|
||||
$this->assertEquals($limit, $loopResults->getCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Accessory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AccessoryTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Accessory';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Accessory($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array('product' => 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Address;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AddressTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Address';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Address($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop\Argument;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Type;
|
||||
use Thelia\Type\TypeCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ArgumentCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testArgumentCollectionCreateAndWalk()
|
||||
{
|
||||
$collection = new ArgumentCollection(
|
||||
new Argument(
|
||||
'arg0',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'arg1',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$collection->addArgument(
|
||||
new Argument(
|
||||
'arg2',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testArgumentCollectionFetch()
|
||||
{
|
||||
$collection = new ArgumentCollection(
|
||||
new Argument(
|
||||
'arg0',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'arg1',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'arg2',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$arguments = \PHPUnit_Framework_Assert::readAttribute($collection, 'arguments');
|
||||
|
||||
foreach ($collection as $key => $argument) {
|
||||
$this->assertEquals(
|
||||
$argument,
|
||||
$arguments[$key]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\AssociatedContent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AssociatedContentTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\AssociatedContent';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new AssociatedContent($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array('product' => 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\AttributeAvailability;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AttributeAvailabilityTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\AttributeAvailability';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new AttributeAvailability($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\AttributeCombination;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AttributeCombinationTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\AttributeCombination';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new AttributeCombination($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array('product_sale_elements' => 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Attribute;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AttributeTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Attribute';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Attribute($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
62
tests/phpunit/Thelia/Tests/Core/Template/Loop/BrandTest.php
Normal file
62
tests/phpunit/Thelia/Tests/Core/Template/Loop/BrandTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Model\BrandQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Brand;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class BrandTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Brand';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Brand($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$brand = BrandQuery::create()->findOne();
|
||||
if (null === $brand) {
|
||||
$brand = new \Thelia\Model\Brand();
|
||||
$brand->setVisible(1);
|
||||
$brand->setTitle('foo');
|
||||
$brand->save();
|
||||
}
|
||||
|
||||
$otherParameters = array(
|
||||
"visible" => "*",
|
||||
);
|
||||
|
||||
$this->baseTestSearchById($brand->getId(), $otherParameters);
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Category;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CategoryTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Category';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Category($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$category = CategoryQuery::create()->findOne();
|
||||
if (null === $category) {
|
||||
$category = new \Thelia\Model\Category();
|
||||
$category->setParent(0);
|
||||
$category->setVisible(1);
|
||||
$category->setTitle('foo');
|
||||
$category->save();
|
||||
}
|
||||
|
||||
$otherParameters = array(
|
||||
"visible" => "*",
|
||||
);
|
||||
|
||||
$this->baseTestSearchById($category->getId(), $otherParameters);
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Content;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ContentTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Content';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Content($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$content = ContentQuery::create()->findOne();
|
||||
if (null === $content) {
|
||||
$content = new \Thelia\Model\Content();
|
||||
$content->setVisible(1);
|
||||
$content->setTitle('foo');
|
||||
$content->save();
|
||||
}
|
||||
|
||||
$otherParameters = array(
|
||||
"visible" => "*",
|
||||
);
|
||||
|
||||
$this->baseTestSearchById($content->getId(), $otherParameters);
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Country;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CountryTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Country';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Country($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Currency;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CurrencyTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Currency';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Currency($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Customer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CustomerTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Customer';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Customer($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Document;
|
||||
use Thelia\Model\ProductDocumentQuery;
|
||||
use Thelia\Model\CategoryDocumentQuery;
|
||||
use Thelia\Model\ContentDocumentQuery;
|
||||
use Thelia\Model\FolderDocumentQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class DocumentTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Document';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Document($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array('source' => 'product', 'id' => 1);
|
||||
}
|
||||
|
||||
public function testSearchByProductId()
|
||||
{
|
||||
$document = ProductDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'product'));
|
||||
}
|
||||
|
||||
public function testSearchByFolderId()
|
||||
{
|
||||
$document = FolderDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'folder'));
|
||||
}
|
||||
|
||||
public function testSearchByContentId()
|
||||
{
|
||||
$document = ContentDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'content'));
|
||||
}
|
||||
|
||||
public function testSearchByCategoryId()
|
||||
{
|
||||
$document = CategoryDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'category'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\FeatureAvailability;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class FeatureAvailabilityTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\FeatureAvailability';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new FeatureAvailability($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Feature;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class FeatureTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Feature';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Feature($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\FeatureValue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class FeatureValueTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\FeatureValue';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new FeatureValue($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array('product' => 1, 'feature' => 1);
|
||||
}
|
||||
}
|
||||
63
tests/phpunit/Thelia/Tests/Core/Template/Loop/FolderTest.php
Normal file
63
tests/phpunit/Thelia/Tests/Core/Template/Loop/FolderTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Folder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class FolderTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Folder';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Folder($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$folder = FolderQuery::create()->findOne();
|
||||
if (null === $folder) {
|
||||
$folder = new \Thelia\Model\Folder();
|
||||
$folder->setParent(0);
|
||||
$folder->setVisible(1);
|
||||
$folder->setTitle('foo');
|
||||
$folder->save();
|
||||
}
|
||||
|
||||
$otherParameters = array(
|
||||
"visible" => "*",
|
||||
);
|
||||
|
||||
$this->baseTestSearchById($folder->getId(), $otherParameters);
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(3);
|
||||
}
|
||||
}
|
||||
47
tests/phpunit/Thelia/Tests/Core/Template/Loop/HookTest.php
Normal file
47
tests/phpunit/Thelia/Tests/Core/Template/Loop/HookTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Core\Template\Loop\Hook;
|
||||
use Thelia\Model\HookQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
|
||||
/**
|
||||
* Class HookTest
|
||||
* @package Thelia\Tests\Core\Template\Loop
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class HookTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Hook';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Hook($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array("backend_context" => 1);
|
||||
}
|
||||
|
||||
public function testSearchByHookId()
|
||||
{
|
||||
$hook = HookQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($hook->getId());
|
||||
}
|
||||
}
|
||||
71
tests/phpunit/Thelia/Tests/Core/Template/Loop/ImageTest.php
Normal file
71
tests/phpunit/Thelia/Tests/Core/Template/Loop/ImageTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Image;
|
||||
use Thelia\Model\ProductImageQuery;
|
||||
use Thelia\Model\CategoryImageQuery;
|
||||
use Thelia\Model\ContentImageQuery;
|
||||
use Thelia\Model\FolderImageQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ImageTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Image';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Image($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array('source' => 'product', 'id' => 1);
|
||||
}
|
||||
|
||||
public function testSearchByProductId()
|
||||
{
|
||||
$image = ProductImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'product'));
|
||||
}
|
||||
|
||||
public function testSearchByFolderId()
|
||||
{
|
||||
$image = FolderImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'folder'));
|
||||
}
|
||||
|
||||
public function testSearchByContentId()
|
||||
{
|
||||
$image = ContentImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'content'));
|
||||
}
|
||||
|
||||
public function testSearchByCategoryId()
|
||||
{
|
||||
$image = CategoryImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'category'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Cheque\Cheque;
|
||||
use Thelia\Core\Template\Loop\ModuleConfig;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class ModuleConfigTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\ModuleConfig';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new ModuleConfig($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return [
|
||||
"module" => "cheque",
|
||||
"variable" => "test"
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetVariable()
|
||||
{
|
||||
Cheque::setConfigValue('test', 'test-value', null, true);
|
||||
|
||||
$this->instance->initializeArgs([
|
||||
"type" => "module-config",
|
||||
"name" => "testGetVariable",
|
||||
"module" => "cheque",
|
||||
"variable" => "test"
|
||||
]);
|
||||
|
||||
$dummy = null;
|
||||
|
||||
$loopResults = $this->instance->exec($dummy);
|
||||
|
||||
$this->assertEquals(1, $loopResults->getCount());
|
||||
|
||||
$substitutions = $loopResults->current()->getVarVal();
|
||||
|
||||
$this->assertEquals('test-value', $substitutions['VALUE']);
|
||||
}
|
||||
|
||||
public function testGetVariableWithDefault()
|
||||
{
|
||||
$this->instance->initializeArgs([
|
||||
"type" => "module-config",
|
||||
"name" => "testGetVariable",
|
||||
"module" => "cheque",
|
||||
"variable" => "nonexistent",
|
||||
"default_value" => "a default value"
|
||||
]);
|
||||
|
||||
$dummy = null;
|
||||
|
||||
$loopResults = $this->instance->exec($dummy);
|
||||
|
||||
$this->assertEquals(1, $loopResults->getCount());
|
||||
|
||||
$substitutions = $loopResults->current()->getVarVal();
|
||||
|
||||
$this->assertEquals('a default value', $substitutions['VALUE']);
|
||||
}
|
||||
|
||||
public function testGetI18nVariable()
|
||||
{
|
||||
Cheque::setConfigValue('testI18N', 'test-value-i18n', 'fr_FR', true);
|
||||
|
||||
$this->instance->initializeArgs(
|
||||
array(
|
||||
"type" => "foo",
|
||||
"name" => "foo",
|
||||
"module" => "cheque",
|
||||
"variable" => "testI18N",
|
||||
"locale" => "fr_FR"
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
$dummy = null;
|
||||
|
||||
$loopResults = $this->instance->exec($dummy);
|
||||
|
||||
$this->assertEquals(1, $loopResults->getCount());
|
||||
|
||||
$substitutions = $loopResults->current()->getVarVal();
|
||||
|
||||
$this->assertEquals('test-value-i18n', $substitutions['VALUE']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testNonExistentModule()
|
||||
{
|
||||
$this->instance->initializeArgs(
|
||||
array(
|
||||
"type" => "foo",
|
||||
"name" => "foo",
|
||||
"module" => "tagapouet",
|
||||
"variable" => "xdes"
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
$dummy = null;
|
||||
|
||||
$loopResults = $this->instance->exec($dummy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Core\Template\Loop\ModuleHook;
|
||||
use Thelia\Model\ModuleHookQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
|
||||
/**
|
||||
* Class ModuleHookTest
|
||||
* @package Thelia\Tests\Core\Template\Loop
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class ModuleHookTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\ModuleHook';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new ModuleHook($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array("backend_context" => 1);
|
||||
}
|
||||
|
||||
public function testSearchByHookId()
|
||||
{
|
||||
$moduleHook = ModuleHookQuery::create()->findOne();
|
||||
if (null !== $moduleHook) {
|
||||
$this->baseTestSearchById($moduleHook->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\ProductSaleElements;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ProductSaleElementTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\ProductSaleElements';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new ProductSaleElements($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array('product' => 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Product;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ProductTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Product';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Product($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$product = ProductQuery::create()->orderById(Criteria::ASC)->findOne();
|
||||
|
||||
// ensure translation
|
||||
$product->getTranslation()
|
||||
->setTitle("foo")
|
||||
->save()
|
||||
;
|
||||
|
||||
if (null === $product) {
|
||||
$product = new \Thelia\Model\Product();
|
||||
$product->setDefaultCategory(0);
|
||||
$product->setVisible(1);
|
||||
$product->setTitle('foo');
|
||||
$product->save();
|
||||
}
|
||||
|
||||
$otherParameters = array(
|
||||
"visible" => "*",
|
||||
);
|
||||
|
||||
$this->baseTestSearchById($product->getId(), $otherParameters);
|
||||
}
|
||||
|
||||
public function testSearchByIdComplex()
|
||||
{
|
||||
$product = ProductQuery::create()->orderById(Criteria::ASC)->findOne();
|
||||
|
||||
if (null === $product) {
|
||||
$product = new \Thelia\Model\Product();
|
||||
$product->setDefaultCategory(0);
|
||||
$product->setVisible(1);
|
||||
$product->setTitle('foo');
|
||||
$product->save();
|
||||
}
|
||||
|
||||
$otherParameters = array(
|
||||
"visible" => "*",
|
||||
"complex" => 1
|
||||
);
|
||||
|
||||
$this->baseTestSearchById($product->getId(), $otherParameters);
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(3);
|
||||
}
|
||||
}
|
||||
52
tests/phpunit/Thelia/Tests/Core/Template/Loop/SaleTest.php
Normal file
52
tests/phpunit/Thelia/Tests/Core/Template/Loop/SaleTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Model\SaleQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Sale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class SaleTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Sale';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Sale($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return ["active" => "*"];
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$sale = SaleQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($sale->getId());
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
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();
|
||||
if (null === $tr) {
|
||||
$tr = new \Thelia\Model\TaxRule();
|
||||
$tr->setTitle('foo');
|
||||
$tr->save();
|
||||
}
|
||||
|
||||
$this->baseTestSearchById($tr->getId(), array('force_return' => true));
|
||||
}
|
||||
}
|
||||
39
tests/phpunit/Thelia/Tests/Core/Template/Loop/TitleTest.php
Normal file
39
tests/phpunit/Thelia/Tests/Core/Template/Loop/TitleTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
use Thelia\Core\Template\Loop\Title;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class TitleTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Title';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Title($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user