Inital commit
184
tests/phpunit/Thelia/Tests/Action/AddressTest.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?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\Action;
|
||||
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Action\Address;
|
||||
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* test address eventListener
|
||||
*
|
||||
* Class AddressTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AddressTest extends BaseAction
|
||||
{
|
||||
public function testCreatedAddress()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
|
||||
$AddressCreateOrUpdateEvent = new AddressCreateOrUpdateEvent(
|
||||
"test address",
|
||||
1,
|
||||
"Thelia",
|
||||
"Thelia",
|
||||
"5 rue rochon",
|
||||
"",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
""
|
||||
);
|
||||
$AddressCreateOrUpdateEvent->setCustomer($customer);
|
||||
|
||||
$actionAddress = new Address();
|
||||
$actionAddress->create($AddressCreateOrUpdateEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdAddress = $AddressCreateOrUpdateEvent->getAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $createdAddress);
|
||||
$this->assertFalse($createdAddress->isNew());
|
||||
$this->assertSame($customer, $createdAddress->getCustomer());
|
||||
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getLabel(), $createdAddress->getLabel());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getTitle(), $createdAddress->getTitleId());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getFirstname(), $createdAddress->getFirstname());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getLastname(), $createdAddress->getLastname());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress1(), $createdAddress->getAddress1());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress2(), $createdAddress->getAddress2());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress3(), $createdAddress->getAddress3());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getZipcode(), $createdAddress->getZipcode());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCity(), $createdAddress->getCity());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCountry(), $createdAddress->getCountryId());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getPhone(), $createdAddress->getPhone());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCellphone(), $createdAddress->getCellphone());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCompany(), $createdAddress->getCompany());
|
||||
}
|
||||
|
||||
public function testUpdatedAddress()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
$address = $customer->getAddresses()->getFirst();
|
||||
|
||||
$addressEvent = new AddressCreateOrUpdateEvent(
|
||||
"",
|
||||
1,
|
||||
"Thelia modif",
|
||||
"Thelia modif",
|
||||
"cour des étoiles",
|
||||
"rue des miracles",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
""
|
||||
);
|
||||
$addressEvent->setAddress($address);
|
||||
|
||||
$actionAddress = new Address();
|
||||
$actionAddress->update($addressEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAddress = $addressEvent->getAddress();
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $updatedAddress);
|
||||
$this->assertFalse($updatedAddress->isNew());
|
||||
$this->assertSame($customer, $updatedAddress->getCustomer());
|
||||
|
||||
$this->assertEquals($address->getLabel(), $updatedAddress->getLabel());
|
||||
$this->assertEquals($addressEvent->getTitle(), $updatedAddress->getTitleId());
|
||||
$this->assertEquals($addressEvent->getFirstname(), $updatedAddress->getFirstname());
|
||||
$this->assertEquals($addressEvent->getLastname(), $updatedAddress->getLastname());
|
||||
$this->assertEquals($addressEvent->getAddress1(), $updatedAddress->getAddress1());
|
||||
$this->assertEquals($addressEvent->getAddress2(), $updatedAddress->getAddress2());
|
||||
$this->assertEquals($addressEvent->getAddress3(), $updatedAddress->getAddress3());
|
||||
$this->assertEquals($addressEvent->getZipcode(), $updatedAddress->getZipcode());
|
||||
$this->assertEquals($addressEvent->getCity(), $updatedAddress->getCity());
|
||||
$this->assertEquals($addressEvent->getCountry(), $updatedAddress->getCountryId());
|
||||
$this->assertEquals($addressEvent->getPhone(), $updatedAddress->getPhone());
|
||||
$this->assertEquals($addressEvent->getCellphone(), $updatedAddress->getCellphone());
|
||||
$this->assertEquals($addressEvent->getCompany(), $updatedAddress->getCompany());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug found in Thelia 2.0.2
|
||||
*/
|
||||
public function testUpdateDefaultAddress()
|
||||
{
|
||||
/**
|
||||
* Disable propel cache in order to get a new instance of the
|
||||
* active record in $updatedAddress
|
||||
*/
|
||||
Propel::disableInstancePooling();
|
||||
|
||||
/**
|
||||
* Get a customer and it's default address
|
||||
*/
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
$defaultAddress = $customer->getDefaultAddress();
|
||||
$addressId = $defaultAddress->getId();
|
||||
|
||||
/**
|
||||
* Try to update the address, and set the isDefault argument,
|
||||
* that should keep this address as the default one.
|
||||
*/
|
||||
$addressEvent = new AddressCreateOrUpdateEvent(
|
||||
"",
|
||||
1,
|
||||
"Thelia modif",
|
||||
"Thelia modif",
|
||||
"cour des étoiles",
|
||||
"rue des miracles",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
"",
|
||||
1
|
||||
);
|
||||
|
||||
$addressEvent->setAddress($defaultAddress);
|
||||
|
||||
/**
|
||||
* Do the update
|
||||
*/
|
||||
$actionAddress = new Address();
|
||||
$actionAddress->update($addressEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAddress = AddressQuery::create()
|
||||
->findPk($addressId);
|
||||
|
||||
/**
|
||||
* This address should still be the default address
|
||||
*/
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$updatedAddress->getIsDefault()
|
||||
);
|
||||
|
||||
/**
|
||||
* Renable it after
|
||||
*/
|
||||
Propel::enableInstancePooling();
|
||||
}
|
||||
}
|
||||
178
tests/phpunit/Thelia/Tests/Action/AdministratorTest.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Administrator;
|
||||
use Thelia\Core\Event\Administrator\AdministratorEvent;
|
||||
use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\AdminQuery;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Tools\TokenProvider;
|
||||
|
||||
/**
|
||||
* Class AdministratorTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AdministratorTest extends BaseAction
|
||||
{
|
||||
protected $mailerFactory;
|
||||
protected $tokenProvider;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
$this->mailerFactory = $this->getMockBuilder("Thelia\\Mailer\\MailerFactory")
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
|
||||
$translator = new Translator(new Container());
|
||||
|
||||
$this->tokenProvider = new TokenProvider($requestStack, $translator, 'test');
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$login = 'thelia'.uniqid();
|
||||
$locale = LangQuery::create()->findOne()->getLocale();
|
||||
$adminEvent = new AdministratorEvent();
|
||||
$adminEvent
|
||||
->setFirstname('thelia')
|
||||
->setLastname('thelia')
|
||||
->setLogin($login)
|
||||
->setPassword('azerty')
|
||||
->setLocale($locale)
|
||||
->setEmail(uniqid().'@example.com')
|
||||
;
|
||||
|
||||
$admin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$admin->create($adminEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $createdAdmin);
|
||||
$this->assertFalse($createdAdmin->isNew());
|
||||
|
||||
$this->assertEquals($adminEvent->getFirstname(), $createdAdmin->getFirstname());
|
||||
$this->assertEquals($adminEvent->getLastname(), $createdAdmin->getLastname());
|
||||
$this->assertEquals($adminEvent->getLogin(), $createdAdmin->getLogin());
|
||||
$this->assertEquals($adminEvent->getLocale(), $createdAdmin->getLocale());
|
||||
$this->assertEquals($adminEvent->getProfile(), $createdAdmin->getProfileId());
|
||||
$this->assertTrue(password_verify($adminEvent->getPassword(), $createdAdmin->getPassword()));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
|
||||
$login = 'thelia'.uniqid();
|
||||
$locale = LangQuery::create()->findOne()->getLocale();
|
||||
$adminEvent = new AdministratorEvent();
|
||||
$adminEvent
|
||||
->setId($admin->getId())
|
||||
->setFirstname('thelia_update')
|
||||
->setLastname('thelia_update')
|
||||
->setLogin($login)
|
||||
->setPassword('azertyuiop')
|
||||
->setLocale($locale)
|
||||
->setEmail(uniqid().'@example.com')
|
||||
->setDispatcher($this->getMockEventDispatcher())
|
||||
;
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$actionAdmin->update($adminEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin);
|
||||
$this->assertFalse($updatedAdmin->isNew());
|
||||
|
||||
$this->assertEquals($adminEvent->getFirstname(), $updatedAdmin->getFirstname());
|
||||
$this->assertEquals($adminEvent->getLastname(), $updatedAdmin->getLastname());
|
||||
$this->assertEquals($adminEvent->getLogin(), $updatedAdmin->getLogin());
|
||||
$this->assertEquals($adminEvent->getLocale(), $updatedAdmin->getLocale());
|
||||
$this->assertEquals($adminEvent->getProfile(), $updatedAdmin->getProfileId());
|
||||
$this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
|
||||
$adminEvent = new AdministratorEvent();
|
||||
|
||||
$adminEvent
|
||||
->setId($admin->getId())
|
||||
;
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$actionAdmin->delete($adminEvent);
|
||||
|
||||
$deletedAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $deletedAdmin);
|
||||
$this->assertTrue($deletedAdmin->isDeleted());
|
||||
}
|
||||
|
||||
public function testUpdatePassword()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
|
||||
$adminEvent = new AdministratorUpdatePasswordEvent($admin);
|
||||
$adminEvent
|
||||
->setPassword('toto');
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$actionAdmin->updatePassword($adminEvent);
|
||||
|
||||
$updatedAdmin = $adminEvent->getAdmin();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin);
|
||||
$this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
|
||||
}
|
||||
|
||||
public function testRenewPassword()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
$admin->setPasswordRenewToken(null)->setEmail('no_reply@thelia.net')->save();
|
||||
|
||||
$adminEvent = new AdministratorEvent($admin);
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
$actionAdmin->createPassword($adminEvent);
|
||||
|
||||
$updatedAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin);
|
||||
$this->assertNotEmpty($admin->getPasswordRenewToken());
|
||||
}
|
||||
}
|
||||
142
tests/phpunit/Thelia/Tests/Action/AreaTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Area;
|
||||
use Thelia\Core\Event\Area\AreaAddCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaCreateEvent;
|
||||
use Thelia\Core\Event\Area\AreaDeleteEvent;
|
||||
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
|
||||
use Thelia\Model\Area as AreaModel;
|
||||
use Thelia\Model\CountryAreaQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
|
||||
/**
|
||||
* Class AreaTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AreaTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new AreaCreateEvent();
|
||||
$event
|
||||
->setAreaName('foo');
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $createdArea);
|
||||
$this->assertFalse($createdArea->isNew());
|
||||
$this->assertTrue($event->hasArea());
|
||||
|
||||
$this->assertEquals('foo', $createdArea->getName());
|
||||
|
||||
return $createdArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testCreate
|
||||
* @return AreaModel
|
||||
*/
|
||||
public function testUpdatePostage(AreaModel $area)
|
||||
{
|
||||
$event = new AreaUpdatePostageEvent($area->getId());
|
||||
$event
|
||||
->setPostage(20);
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->updatePostage($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
|
||||
$this->assertEquals(20, $updatedArea->getPostage());
|
||||
|
||||
return $updatedArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testUpdatePostage
|
||||
* @return AreaModel
|
||||
*/
|
||||
public function testAddCountry(AreaModel $area)
|
||||
{
|
||||
$country = CountryQuery::create()->findOne();
|
||||
|
||||
$event = new AreaAddCountryEvent($area->getId(), [ $country->getId() ]);
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->addCountry($event);
|
||||
|
||||
$updatedArea = $event->getArea();
|
||||
|
||||
$updatedCountry = CountryAreaQuery::create()->findOneByAreaId($updatedArea->getId());
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
|
||||
$this->assertEquals($country->getId(), $updatedCountry->getCountryId());
|
||||
|
||||
return $updatedArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testAddCountry
|
||||
* @return AreaModel
|
||||
*/
|
||||
public function testRemoveCountry(AreaModel $area)
|
||||
{
|
||||
$country = CountryQuery::create()->filterByArea($area)->find()->getFirst();
|
||||
|
||||
$event = new AreaRemoveCountryEvent($area->getId(), $country->getId());
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->removeCountry($event);
|
||||
|
||||
$updatedCountry = CountryAreaQuery::create()
|
||||
->filterByCountryId($country->getId())
|
||||
->filterByStateId(null)
|
||||
->filterByAreaId($area->getId())
|
||||
->findOne();
|
||||
|
||||
$updatedArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
|
||||
$this->assertNull($updatedCountry);
|
||||
|
||||
return $event->getArea();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testRemoveCountry
|
||||
*/
|
||||
public function testDelete(AreaModel $area)
|
||||
{
|
||||
$event = new AreaDeleteEvent($area->getId());
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $deletedArea);
|
||||
$this->assertTrue($deletedArea->isDeleted());
|
||||
}
|
||||
}
|
||||
105
tests/phpunit/Thelia/Tests/Action/AttributeAvTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\AttributeAv;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvCreateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvDeleteEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent;
|
||||
use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Model\AttributeAv as AttributeAvModel;
|
||||
|
||||
/**
|
||||
* Class AttributeAvTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AttributeAvTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$attribute = AttributeQuery::create()->findOne();
|
||||
|
||||
$event = new AttributeAvCreateEvent();
|
||||
|
||||
$event
|
||||
->setAttributeId($attribute->getId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('foo');
|
||||
|
||||
$action = new AttributeAv();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$attributeAvCreated = $event->getAttributeAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\AttributeAv', $attributeAvCreated);
|
||||
|
||||
$this->assertEquals('en_US', $attributeAvCreated->getLocale());
|
||||
$this->assertEquals('foo', $attributeAvCreated->getTitle());
|
||||
$this->assertNull($attributeAvCreated->getDescription());
|
||||
$this->assertNull($attributeAvCreated->getPostscriptum());
|
||||
$this->assertNull($attributeAvCreated->getChapo());
|
||||
$this->assertEquals($attribute, $attributeAvCreated->getAttribute());
|
||||
|
||||
return $attributeAvCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeAvModel $attributeAv
|
||||
* @depends testCreate
|
||||
* @return AttributeAvModel
|
||||
*/
|
||||
public function testUpdate(AttributeAvModel $attributeAv)
|
||||
{
|
||||
$event = new AttributeAvUpdateEvent($attributeAv->getId());
|
||||
|
||||
$event
|
||||
->setLocale($attributeAv->getLocale())
|
||||
->setTitle('bar')
|
||||
->setDescription('bar description')
|
||||
->setChapo('bar chapo')
|
||||
->setPostscriptum('bar postscriptum')
|
||||
;
|
||||
|
||||
$action = new AttributeAv();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAttributeAv = $event->getAttributeAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\AttributeAv', $updatedAttributeAv);
|
||||
|
||||
$this->assertEquals('bar', $updatedAttributeAv->getTitle());
|
||||
$this->assertEquals('bar description', $updatedAttributeAv->getDescription());
|
||||
$this->assertEquals('bar chapo', $updatedAttributeAv->getChapo());
|
||||
$this->assertEquals('bar postscriptum', $updatedAttributeAv->getPostscriptum());
|
||||
|
||||
return $updatedAttributeAv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeAvModel $attributeAv
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(AttributeAvModel $attributeAv)
|
||||
{
|
||||
$event = new AttributeAvDeleteEvent($attributeAv->getId());
|
||||
|
||||
$action = new AttributeAv();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedAttributeAv = $event->getAttributeAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\AttributeAv', $deletedAttributeAv);
|
||||
$this->assertTrue($deletedAttributeAv->isDeleted());
|
||||
}
|
||||
}
|
||||
95
tests/phpunit/Thelia/Tests/Action/AttributeTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Attribute;
|
||||
use Thelia\Core\Event\Attribute\AttributeDeleteEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeUpdateEvent;
|
||||
use Thelia\Model\Attribute as AttributeModel;
|
||||
use Thelia\Core\Event\Attribute\AttributeCreateEvent;
|
||||
|
||||
/**
|
||||
* Class AttributeTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AttributeTest extends BaseAction
|
||||
{
|
||||
public function testCreateSimple()
|
||||
{
|
||||
$event = new AttributeCreateEvent();
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('foo');
|
||||
|
||||
$action = new Attribute($this->getMockEventDispatcher());
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdAttribute = $event->getAttribute();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Attribute', $createdAttribute);
|
||||
$this->assertEquals($createdAttribute->getLocale(), 'en_US');
|
||||
$this->assertEquals($createdAttribute->getTitle(), 'foo');
|
||||
|
||||
return $createdAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeModel $attribute
|
||||
* @depends testCreateSimple
|
||||
* @return AttributeModel
|
||||
*/
|
||||
public function testUpdate(AttributeModel $attribute)
|
||||
{
|
||||
$event = new AttributeUpdateEvent($attribute->getId());
|
||||
|
||||
$event
|
||||
->setLocale($attribute->getLocale())
|
||||
->setTitle('bar')
|
||||
->setDescription('bar description')
|
||||
->setChapo('bar chapo')
|
||||
->setPostscriptum('bar postscriptum');
|
||||
|
||||
$action = new Attribute();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAttribute = $event->getAttribute();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Attribute', $updatedAttribute);
|
||||
$this->assertEquals('en_US', $updatedAttribute->getLocale());
|
||||
$this->assertEquals('bar', $updatedAttribute->getTitle());
|
||||
$this->assertEquals('bar description', $updatedAttribute->getDescription());
|
||||
$this->assertEquals('bar chapo', $updatedAttribute->getChapo());
|
||||
$this->assertEquals('bar postscriptum', $updatedAttribute->getPostscriptum());
|
||||
|
||||
return $updatedAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeModel $attribute
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(AttributeModel $attribute)
|
||||
{
|
||||
$event = new AttributeDeleteEvent($attribute->getId());
|
||||
|
||||
$action = new Attribute();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedAttribute = $event->getAttribute();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Attribute', $deletedAttribute);
|
||||
$this->assertTrue($deletedAttribute->isDeleted());
|
||||
}
|
||||
}
|
||||
50
tests/phpunit/Thelia/Tests/Action/BaseAction.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
|
||||
/**
|
||||
* Class BaseAction
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class BaseAction extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ParserInterface
|
||||
*/
|
||||
protected function getMockParserInterface()
|
||||
{
|
||||
return $this->getMock("Thelia\\Core\\Template\\ParserInterface");
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->set("event_dispatcher", $this->getMockEventDispatcher());
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
251
tests/phpunit/Thelia/Tests/Action/BrandTest.php
Normal file
@@ -0,0 +1,251 @@
|
||||
<?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\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Action\Brand;
|
||||
use Thelia\Core\Event\Brand\BrandCreateEvent;
|
||||
use Thelia\Core\Event\Brand\BrandDeleteEvent;
|
||||
use Thelia\Core\Event\Brand\BrandToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Brand\BrandUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\BrandQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class BrandTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class BrandTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
public function getUpdateEvent(&$brand)
|
||||
{
|
||||
if (!$brand instanceof \Thelia\Model\Brand) {
|
||||
$brand = $this->getRandomBrand();
|
||||
}
|
||||
|
||||
$event = new BrandUpdateEvent($brand->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale($brand->getLocale())
|
||||
->setTitle($brand->getTitle())
|
||||
->setChapo($brand->getChapo())
|
||||
->setDescription($brand->getDescription())
|
||||
->setPostscriptum($brand->getPostscriptum())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BrandUpdateEvent $event
|
||||
* @return Brand
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$brandAction = new Brand();
|
||||
$brandAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getBrand();
|
||||
}
|
||||
|
||||
public function testCreateBrand()
|
||||
{
|
||||
$event = new BrandCreateEvent();
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test create brand')
|
||||
;
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $createdBrand);
|
||||
$this->assertEquals(1, $createdBrand->getVisible());
|
||||
$this->assertEquals('test create brand', $createdBrand->getTitle());
|
||||
}
|
||||
|
||||
public function testUpdateBrand()
|
||||
{
|
||||
$brand = $this->getRandomBrand();
|
||||
|
||||
$event = new BrandUpdateEvent($brand->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update brand title')
|
||||
->setChapo('test update brand short description')
|
||||
->setDescription('test update brand description')
|
||||
->setPostscriptum('test update brand postscriptum')
|
||||
;
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $updatedBrand);
|
||||
$this->assertEquals(1, $updatedBrand->getVisible());
|
||||
$this->assertEquals('test update brand title', $updatedBrand->getTitle());
|
||||
$this->assertEquals('test update brand short description', $updatedBrand->getChapo());
|
||||
$this->assertEquals('test update brand description', $updatedBrand->getDescription());
|
||||
$this->assertEquals('test update brand postscriptum', $updatedBrand->getPostscriptum());
|
||||
}
|
||||
|
||||
public function testDeleteBrand()
|
||||
{
|
||||
$brand = $this->getRandomBrand();
|
||||
|
||||
$event = new BrandDeleteEvent($brand->getId());
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $deletedBrand);
|
||||
$this->assertTrue($deletedBrand->isDeleted());
|
||||
}
|
||||
|
||||
public function testBrandToggleVisibility()
|
||||
{
|
||||
$brand = $this->getRandomBrand();
|
||||
|
||||
$visibility = $brand->getVisible();
|
||||
|
||||
$event = new BrandToggleVisibilityEvent($brand);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $updatedBrand);
|
||||
$this->assertEquals(!$visibility, $updatedBrand->getVisible());
|
||||
}
|
||||
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$this->resetBrandPosition();
|
||||
|
||||
$brand = BrandQuery::create()
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
$newPosition = $brand->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent($brand->getId(), UpdatePositionEvent::POSITION_UP);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = BrandQuery::create()->findPk($brand->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedBrand->getPosition(), sprintf("new position is %d, new position expected is %d for brand %d", $newPosition, $updatedBrand->getPosition(), $updatedBrand->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionDown()
|
||||
{
|
||||
$this->resetBrandPosition();
|
||||
|
||||
$brand = BrandQuery::create()
|
||||
->filterByPosition(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
$newPosition = $brand->getPosition()+1;
|
||||
|
||||
$event = new UpdatePositionEvent($brand->getId(), UpdatePositionEvent::POSITION_DOWN);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = BrandQuery::create()->findPk($brand->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedBrand->getPosition(), sprintf("new position is %d, new position expected is %d for brand %d", $newPosition, $updatedBrand->getPosition(), $updatedBrand->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionWithSpecificPosition()
|
||||
{
|
||||
$this->resetBrandPosition();
|
||||
|
||||
$brand = BrandQuery::create()
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
$event = new UpdatePositionEvent($brand->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = BrandQuery::create()->findPk($brand->getId());
|
||||
|
||||
$this->assertEquals(1, $updatedBrand->getPosition(), sprintf("new position is 1, new position expected is %d for brand %d", $updatedBrand->getPosition(), $updatedBrand->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder brand to have proper position
|
||||
*/
|
||||
protected function resetBrandPosition()
|
||||
{
|
||||
$brands = BrandQuery::create()->find();
|
||||
$counter = 1;
|
||||
|
||||
/** @var \Thelia\Model\Brand $brand */
|
||||
foreach ($brands as $brand) {
|
||||
$brand->setPosition($counter);
|
||||
$brand->save();
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Brand
|
||||
*/
|
||||
protected function getRandomBrand()
|
||||
{
|
||||
$brand = BrandQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
return $brand;
|
||||
}
|
||||
}
|
||||
48
tests/phpunit/Thelia/Tests/Action/CacheTest.php
Normal file
@@ -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\Action;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Thelia\Action\Cache;
|
||||
use Thelia\Core\Event\Cache\CacheEvent;
|
||||
|
||||
/**
|
||||
* Class CacheTest
|
||||
* @package Thelia\Tests\Action\assets
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CacheTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $dir;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->dir = __DIR__ . '/test';
|
||||
|
||||
$fs = new Filesystem();
|
||||
$fs->mkdir($this->dir);
|
||||
}
|
||||
|
||||
public function testCacheClear()
|
||||
{
|
||||
$event = new CacheEvent($this->dir);
|
||||
|
||||
$adapter = new ArrayAdapter();
|
||||
$action = new Cache($adapter);
|
||||
$action->cacheClear($event);
|
||||
|
||||
$fs = new Filesystem();
|
||||
$this->assertFalse($fs->exists($this->dir));
|
||||
}
|
||||
}
|
||||
189
tests/phpunit/Thelia/Tests/Action/CategoryTest.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Action\Category;
|
||||
use Thelia\Core\Event\Category\CategoryCreateEvent;
|
||||
use Thelia\Core\Event\Category\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\Category\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Category\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteEvent;
|
||||
use Thelia\Model\Category as CategoryModel;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\Template;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class CategoryTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CategoryTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Category
|
||||
*/
|
||||
protected function getRandomCategory()
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $category) {
|
||||
$this->fail('use fixtures before launching test, there is no category in database');
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new CategoryCreateEvent();
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setParent(0)
|
||||
->setTitle('foo')
|
||||
->setVisible(1);
|
||||
|
||||
$action = new Category();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $createdCategory);
|
||||
|
||||
$this->assertFalse($createdCategory->isNew());
|
||||
|
||||
$this->assertEquals('en_US', $createdCategory->getLocale());
|
||||
$this->assertEquals('foo', $createdCategory->getTitle());
|
||||
$this->assertEquals(1, $createdCategory->getVisible());
|
||||
$this->assertEquals(0, $createdCategory->getParent());
|
||||
$this->assertNull($createdCategory->getDescription());
|
||||
$this->assertNull($createdCategory->getChapo());
|
||||
$this->assertNull($createdCategory->getPostscriptum());
|
||||
|
||||
return $createdCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryModel $category
|
||||
* @depends testCreate
|
||||
* @return CategoryModel
|
||||
*/
|
||||
public function testUpdate(CategoryModel $category)
|
||||
{
|
||||
$template = new Template();
|
||||
$template->setName('A sample template')->save();
|
||||
|
||||
$event = new CategoryUpdateEvent($category->getId());
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('bar')
|
||||
->setDescription('bar description')
|
||||
->setChapo('bar chapo')
|
||||
->setPostscriptum('bar postscriptum')
|
||||
->setVisible(0)
|
||||
->setParent(0)
|
||||
->setDefaultTemplateId($template->getId())
|
||||
;
|
||||
|
||||
$action = new Category();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $updatedCategory);
|
||||
|
||||
$this->assertEquals('en_US', $updatedCategory->getLocale());
|
||||
$this->assertEquals('bar', $updatedCategory->getTitle());
|
||||
$this->assertEquals('bar description', $updatedCategory->getDescription());
|
||||
$this->assertEquals('bar chapo', $updatedCategory->getChapo());
|
||||
$this->assertEquals('bar postscriptum', $updatedCategory->getPostscriptum());
|
||||
$this->assertEquals(0, $updatedCategory->getVisible());
|
||||
$this->assertEquals($template->getId(), $updatedCategory->getDefaultTemplateId());
|
||||
$this->assertEquals(0, $updatedCategory->getParent());
|
||||
|
||||
return [ $updatedCategory, $template ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $argArray
|
||||
* @depends testUpdate
|
||||
* @return CategoryModel
|
||||
*/
|
||||
public function testRemoveTemplate($argArray)
|
||||
{
|
||||
/** @var CategoryModel $category */
|
||||
$category = $argArray[0];
|
||||
|
||||
/** @var Template $template */
|
||||
$template = $argArray[1];
|
||||
|
||||
$event = new TemplateDeleteEvent($template->getId());
|
||||
|
||||
$action = new \Thelia\Action\Template();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Template', $event->getTemplate());
|
||||
|
||||
$theCat = CategoryQuery::create()->findPk($category->getId());
|
||||
|
||||
$this->assertNull($theCat->getDefaultTemplateId());
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryModel $category
|
||||
* @depends testRemoveTemplate
|
||||
*/
|
||||
public function testDelete(CategoryModel $category)
|
||||
{
|
||||
$event = new CategoryDeleteEvent($category->getId());
|
||||
|
||||
$action = new Category();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $deletedCategory);
|
||||
$this->assertTrue($deletedCategory->isDeleted());
|
||||
}
|
||||
|
||||
public function testToggleVisibility()
|
||||
{
|
||||
$category = $this->getRandomCategory();
|
||||
$expectedVisibility = !$category->getVisible();
|
||||
|
||||
$event = new CategoryToggleVisibilityEvent($category);
|
||||
|
||||
$action = new Category();
|
||||
$action->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $updatedCategory);
|
||||
$this->assertEquals($expectedVisibility, $updatedCategory->getVisible());
|
||||
}
|
||||
}
|
||||
152
tests/phpunit/Thelia/Tests/Action/ConfigTest.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Config;
|
||||
use Thelia\Core\Event\Config\ConfigCreateEvent;
|
||||
use Thelia\Core\Event\Config\ConfigDeleteEvent;
|
||||
use Thelia\Core\Event\Config\ConfigUpdateEvent;
|
||||
use Thelia\Model\Config as ConfigModel;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* Class ConfigTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ConfigTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ConfigQuery::create()
|
||||
->filterByName('foo')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new ConfigCreateEvent();
|
||||
|
||||
$event
|
||||
->setEventName('foo')
|
||||
->setValue('bar')
|
||||
->setLocale('en_US')
|
||||
->setTitle('test config foo bar')
|
||||
->setHidden(true)
|
||||
->setSecured(true)
|
||||
;
|
||||
|
||||
$action = new Config();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $createdConfig);
|
||||
|
||||
$this->assertFalse($createdConfig->isNew());
|
||||
|
||||
$this->assertEquals('foo', $createdConfig->getName());
|
||||
$this->assertEquals('bar', $createdConfig->getValue());
|
||||
$this->assertEquals('en_US', $createdConfig->getLocale());
|
||||
$this->assertEquals('test config foo bar', $createdConfig->getTitle());
|
||||
$this->assertEquals(1, $createdConfig->getHidden());
|
||||
$this->assertEquals(1, $createdConfig->getSecured());
|
||||
|
||||
return $createdConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigModel $config
|
||||
* @depends testCreate
|
||||
* @return ConfigModel
|
||||
*/
|
||||
public function testSetValue(ConfigModel $config)
|
||||
{
|
||||
$event = new ConfigUpdateEvent($config->getId());
|
||||
$event
|
||||
->setValue('baz');
|
||||
|
||||
$action = new Config();
|
||||
$action->setValue($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $updatedConfig);
|
||||
|
||||
$this->assertEquals($config->getName(), $updatedConfig->getName());
|
||||
$this->assertEquals('baz', $updatedConfig->getValue());
|
||||
$this->assertEquals($config->getLocale(), $updatedConfig->getLocale());
|
||||
$this->assertEquals($config->getTitle(), $updatedConfig->getTitle());
|
||||
$this->assertEquals($config->getHidden(), $updatedConfig->getHidden());
|
||||
$this->assertEquals($config->getSecured(), $updatedConfig->getSecured());
|
||||
|
||||
return $updatedConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigModel $config
|
||||
* @depends testSetValue
|
||||
* @return ConfigModel
|
||||
*/
|
||||
public function testModify(ConfigModel $config)
|
||||
{
|
||||
$event = new ConfigUpdateEvent($config->getId());
|
||||
$event
|
||||
->setEventName('foo')
|
||||
->setValue('update baz')
|
||||
->setLocale('en_US')
|
||||
->setTitle('config title')
|
||||
->setDescription('config description')
|
||||
->setChapo('config chapo')
|
||||
->setPostscriptum('config postscriptum')
|
||||
->setHidden(0)
|
||||
->setSecured(0)
|
||||
;
|
||||
|
||||
$action = new Config();
|
||||
$action->modify($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $updatedConfig);
|
||||
|
||||
$this->assertEquals('foo', $updatedConfig->getName());
|
||||
$this->assertEquals('update baz', $updatedConfig->getValue());
|
||||
$this->assertEquals('en_US', $updatedConfig->getLocale());
|
||||
$this->assertEquals('config title', $updatedConfig->getTitle());
|
||||
$this->assertEquals('config description', $updatedConfig->getDescription());
|
||||
$this->assertEquals('config chapo', $updatedConfig->getChapo());
|
||||
$this->assertEquals('config postscriptum', $updatedConfig->getPostscriptum());
|
||||
$this->assertEquals(0, $updatedConfig->getHidden());
|
||||
$this->assertEquals(0, $updatedConfig->getSecured());
|
||||
|
||||
return $updatedConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigModel $config
|
||||
* @depends testModify
|
||||
*/
|
||||
public function testDelete(ConfigModel $config)
|
||||
{
|
||||
$event = new ConfigDeleteEvent($config->getId());
|
||||
|
||||
$action = new Config();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $deletedConfig);
|
||||
$this->assertTrue($deletedConfig->isDeleted());
|
||||
}
|
||||
}
|
||||
373
tests/phpunit/Thelia/Tests/Action/ContentTest.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?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\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Collection\Collection;
|
||||
use Thelia\Action\Content;
|
||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentDeleteEvent;
|
||||
use Thelia\Core\Event\Content\ContentRemoveFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\ContentFolder;
|
||||
use Thelia\Model\ContentFolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\Folder;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\Content as ContentModel;
|
||||
|
||||
/**
|
||||
* Class ContentTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ContentTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
use I18nTestTrait;
|
||||
|
||||
protected static $folderForPositionTest = null;
|
||||
|
||||
public function getUpdateEvent(&$content)
|
||||
{
|
||||
if (!$content instanceof ContentModel) {
|
||||
$content = $this->getRandomContent();
|
||||
}
|
||||
|
||||
$event = new ContentUpdateEvent($content->getId());
|
||||
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale($content->getLocale())
|
||||
->setTitle($content->getTitle())
|
||||
->setChapo($content->getChapo())
|
||||
->setDescription($content->getDescription())
|
||||
->setPostscriptum($content->getPostscriptum())
|
||||
->setDefaultFolder($content->getDefaultFolderId())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContentUpdateEvent$event
|
||||
* @return ContentModel
|
||||
* @throws \Exception
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$contentAction = new Content();
|
||||
$contentAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getContent();
|
||||
}
|
||||
|
||||
public function testCreateContent()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$event = new ContentCreateEvent();
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test create content')
|
||||
->setDefaultFolder($folder->getId())
|
||||
;
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $createdContent);
|
||||
$this->assertEquals(1, $createdContent->getVisible());
|
||||
$this->assertEquals('test create content', $createdContent->getTitle());
|
||||
$this->assertEquals($folder->getId(), $createdContent->getDefaultFolderId());
|
||||
}
|
||||
|
||||
public function testUpdateContent()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$event = new ContentUpdateEvent($content->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update content title')
|
||||
->setChapo('test update content short description')
|
||||
->setDescription('test update content description')
|
||||
->setPostscriptum('test update content postscriptum')
|
||||
->setDefaultFolder($folder->getId())
|
||||
;
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $updatedContent);
|
||||
$this->assertEquals(1, $updatedContent->getVisible());
|
||||
$this->assertEquals('test update content title', $updatedContent->getTitle());
|
||||
$this->assertEquals('test update content short description', $updatedContent->getChapo());
|
||||
$this->assertEquals('test update content description', $updatedContent->getDescription());
|
||||
$this->assertEquals('test update content postscriptum', $updatedContent->getPostscriptum());
|
||||
$this->assertEquals($folder->getId(), $updatedContent->getDefaultFolderId());
|
||||
}
|
||||
|
||||
public function testDeleteContent()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
|
||||
$event = new ContentDeleteEvent($content->getId());
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $deletedContent);
|
||||
$this->assertTrue($deletedContent->isDeleted());
|
||||
}
|
||||
|
||||
public function testContentToggleVisibility()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
|
||||
$visibility = $content->getVisible();
|
||||
|
||||
$event = new ContentToggleVisibilityEvent($content);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $updatedContent);
|
||||
$this->assertEquals(!$visibility, $updatedContent->getVisible());
|
||||
}
|
||||
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$contentFolderQuery = ContentFolderQuery::create()
|
||||
->filterByFolder($this->getFolderForPositionTest())
|
||||
->filterByPosition(2, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $contentFolderQuery) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
$newPosition = $contentFolderQuery->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent(
|
||||
$contentFolderQuery->getContentId(),
|
||||
UpdatePositionEvent::POSITION_UP,
|
||||
null,
|
||||
$contentFolderQuery->getFolderId()
|
||||
);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = ContentFolderQuery::create()
|
||||
->filterByFolderId($contentFolderQuery->getFolderId())
|
||||
->filterByContentId($contentFolderQuery->getContentId())
|
||||
->findOne();
|
||||
|
||||
$this->assertEquals($newPosition, $updatedContent->getPosition(), sprintf("new position is %d, new position expected is %d for content %d", $newPosition, $updatedContent->getPosition(), $updatedContent->getContentId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionDown()
|
||||
{
|
||||
$contentFolderQuery = ContentFolderQuery::create()
|
||||
->filterByFolder($this->getFolderForPositionTest())
|
||||
->filterByPosition(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $contentFolderQuery) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
$newPosition = $contentFolderQuery->getPosition()+1;
|
||||
|
||||
$event = new UpdatePositionEvent(
|
||||
$contentFolderQuery->getContentId(),
|
||||
UpdatePositionEvent::POSITION_DOWN,
|
||||
null,
|
||||
$contentFolderQuery->getFolderId()
|
||||
);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = ContentFolderQuery::create()
|
||||
->filterByFolderId($contentFolderQuery->getFolderId())
|
||||
->filterByContentId($contentFolderQuery->getContentId())
|
||||
->findOne();
|
||||
;
|
||||
|
||||
$this->assertEquals($newPosition, $updatedContent->getPosition(), sprintf("new position is %d, new position expected is %d for content %d", $newPosition, $updatedContent->getPosition(), $updatedContent->getContentId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionWithSpecificPosition()
|
||||
{
|
||||
$contentFolderQuery = ContentFolderQuery::create()
|
||||
->filterByFolder($this->getFolderForPositionTest())
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $contentFolderQuery) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
$event = new UpdatePositionEvent(
|
||||
$contentFolderQuery->getContentId(),
|
||||
UpdatePositionEvent::POSITION_ABSOLUTE,
|
||||
1,
|
||||
$contentFolderQuery->getFolderId()
|
||||
);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = ContentFolderQuery::create()
|
||||
->filterByFolderId($contentFolderQuery->getFolderId())
|
||||
->filterByContentId($contentFolderQuery->getContentId())
|
||||
->findOne();
|
||||
;
|
||||
|
||||
$this->assertEquals(1, $updatedContent->getPosition(), sprintf("new position is 1, new position expected is %d for content %d", $updatedContent->getPosition(), $updatedContent->getContentId()));
|
||||
}
|
||||
|
||||
public function testAddFolderToContent()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
|
||||
do {
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$test = ContentFolderQuery::create()
|
||||
->filterByContent($content)
|
||||
->filterByFolder($folder);
|
||||
} while ($test->count() > 0);
|
||||
|
||||
$event = new ContentAddFolderEvent($content, $folder->getId());
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->addFolder($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$testAddFolder = ContentFolderQuery::create()
|
||||
->filterByContent($content)
|
||||
->filterByFolder($folder)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
$this->assertNotNull($testAddFolder);
|
||||
$this->assertEquals($content->getId(), $testAddFolder->getContentId(), 'check if content id are equals');
|
||||
$this->assertEquals($folder->getId(), $testAddFolder->getFolderId(), 'check if folder id are equals');
|
||||
|
||||
return $testAddFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContentFolder $association
|
||||
* @depends testAddFolderToContent
|
||||
*/
|
||||
public function testRemoveFolder(ContentFolder $association)
|
||||
{
|
||||
$event = new ContentRemoveFolderEvent($association->getContent(), $association->getFolder()->getId());
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->removeFolder($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$testAssociation = ContentFolderQuery::create()
|
||||
->filterByContent($association->getContent())
|
||||
->filterByFolder($association->getFolder())
|
||||
->findOne();
|
||||
|
||||
$this->assertNull($testAssociation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Content
|
||||
*/
|
||||
protected function getRandomContent()
|
||||
{
|
||||
$content = ContentQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $content) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a folder and its contents to be used in Position tests
|
||||
*
|
||||
* @return Folder the parent folder
|
||||
*/
|
||||
protected function getFolderForPositionTest()
|
||||
{
|
||||
if (null === self::$folderForPositionTest) {
|
||||
$folder = new Folder();
|
||||
|
||||
$folder->setParent(0);
|
||||
$folder->setVisible(1);
|
||||
$folder->setPosition(1);
|
||||
|
||||
$this->setI18n($folder);
|
||||
|
||||
$folder->save();
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$content = new ContentModel();
|
||||
|
||||
$content->setVisible(1);
|
||||
|
||||
$content->addFolder($folder);
|
||||
|
||||
$this->setI18n($content);
|
||||
|
||||
$content->save();
|
||||
}
|
||||
|
||||
self::$folderForPositionTest = $folder;
|
||||
}
|
||||
|
||||
return self::$folderForPositionTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Folder
|
||||
*/
|
||||
protected function getRandomFolder()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
return $folder;
|
||||
}
|
||||
}
|
||||
138
tests/phpunit/Thelia/Tests/Action/CountryTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Country;
|
||||
use Thelia\Core\Event\Country\CountryCreateEvent;
|
||||
use Thelia\Core\Event\Country\CountryDeleteEvent;
|
||||
use Thelia\Core\Event\Country\CountryToggleDefaultEvent;
|
||||
use Thelia\Core\Event\Country\CountryUpdateEvent;
|
||||
use Thelia\Model\Country as CountryModel;
|
||||
use Thelia\Model\CountryQuery;
|
||||
|
||||
/**
|
||||
* Class CountryTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CountryTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new CountryCreateEvent();
|
||||
|
||||
$event
|
||||
->setIsocode('001')
|
||||
->setIsoAlpha2('AA')
|
||||
->setIsoAlpha3('AAA')
|
||||
->setVisible(1)
|
||||
->setHasStates(0)
|
||||
->setLocale('en_US')
|
||||
->setTitle('Test')
|
||||
;
|
||||
|
||||
$action = new Country();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $createdCountry);
|
||||
$this->assertFalse($createdCountry->isNew());
|
||||
|
||||
$this->assertEquals('001', $createdCountry->getIsocode());
|
||||
$this->assertEquals('AA', $createdCountry->getIsoalpha2());
|
||||
$this->assertEquals('AAA', $createdCountry->getIsoalpha3());
|
||||
$this->assertEquals(1, $createdCountry->getVisible());
|
||||
$this->assertEquals(0, $createdCountry->getHasStates());
|
||||
$this->assertEquals('AAA', $createdCountry->getIsoalpha3());
|
||||
$this->assertEquals('en_US', $createdCountry->getLocale());
|
||||
$this->assertEquals('Test', $createdCountry->getTitle());
|
||||
|
||||
return $createdCountry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CountryModel $country
|
||||
* @depends testCreate
|
||||
* @return CountryModel
|
||||
*/
|
||||
public function testUpdate(CountryModel $country)
|
||||
{
|
||||
$event = new CountryUpdateEvent($country->getId());
|
||||
|
||||
$event
|
||||
->setIsocode('002')
|
||||
->setIsoAlpha2('BB')
|
||||
->setIsoAlpha3('BBB')
|
||||
->setVisible(1)
|
||||
->setHasStates(0)
|
||||
->setLocale('en_US')
|
||||
->setTitle('Test')
|
||||
;
|
||||
|
||||
$action = new Country();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $updatedCountry);
|
||||
|
||||
$this->assertEquals('002', $updatedCountry->getIsocode());
|
||||
$this->assertEquals('BB', $updatedCountry->getIsoalpha2());
|
||||
$this->assertEquals('BBB', $updatedCountry->getIsoalpha3());
|
||||
$this->assertEquals(1, $updatedCountry->getVisible());
|
||||
$this->assertEquals(0, $updatedCountry->getHasStates());
|
||||
$this->assertEquals('en_US', $updatedCountry->getLocale());
|
||||
$this->assertEquals('Test', $updatedCountry->getTitle());
|
||||
|
||||
return $updatedCountry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CountryModel $country
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(CountryModel $country)
|
||||
{
|
||||
$event = new CountryDeleteEvent($country->getId());
|
||||
|
||||
$action = new Country();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $deletedCountry);
|
||||
$this->assertTrue($deletedCountry->isDeleted());
|
||||
}
|
||||
|
||||
public function testToggleDefault()
|
||||
{
|
||||
/** @var CountryModel $country */
|
||||
$country = CountryQuery::create()
|
||||
->filterByByDefault(0)
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
$event = new CountryToggleDefaultEvent($country->getId());
|
||||
|
||||
$action = new Country($this->getMockEventDispatcher());
|
||||
$action->toggleDefault($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $updatedCountry);
|
||||
$this->assertEquals(1, $updatedCountry->getByDefault());
|
||||
|
||||
$this->assertEquals(1, CountryQuery::create()->filterByByDefault(1)->count());
|
||||
}
|
||||
}
|
||||
195
tests/phpunit/Thelia/Tests/Action/CurrencyTest.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Action\Currency;
|
||||
use Thelia\Core\Event\Currency\CurrencyDeleteEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyUpdateEvent;
|
||||
use Thelia\CurrencyConverter\CurrencyConverter;
|
||||
use Thelia\CurrencyConverter\Provider\ECBProvider;
|
||||
use Thelia\Model\Currency as CurrencyModel;
|
||||
use Thelia\Core\Event\Currency\CurrencyCreateEvent;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class CurrencyTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CurrencyTest extends ContainerAwareTestCase
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new CurrencyCreateEvent();
|
||||
|
||||
$event
|
||||
->setCurrencyName('test')
|
||||
->setCode('AZE')
|
||||
->setRate('1.35')
|
||||
->setLocale('en_US')
|
||||
->setSymbol('ù')
|
||||
->setFormat('%n %c')
|
||||
;
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $createdCurrency);
|
||||
$this->assertFalse($createdCurrency->isNew());
|
||||
|
||||
$this->assertEquals('test', $createdCurrency->getName());
|
||||
$this->assertEquals('AZE', $createdCurrency->getCode());
|
||||
$this->assertEquals('1.35', $createdCurrency->getRate());
|
||||
$this->assertEquals('en_US', $createdCurrency->getLocale());
|
||||
$this->assertEquals('ù', $createdCurrency->getSymbol());
|
||||
$this->assertEquals('%n %c', $createdCurrency->getFormat());
|
||||
|
||||
return $createdCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyModel $currency
|
||||
* @depends testCreate
|
||||
* @return CurrencyModel
|
||||
*/
|
||||
public function testUpdate(CurrencyModel $currency)
|
||||
{
|
||||
$event = new CurrencyUpdateEvent($currency->getId());
|
||||
|
||||
$event
|
||||
->setCurrencyName('test update')
|
||||
->setCode('AZER')
|
||||
->setRate('2.35')
|
||||
->setLocale('en_US')
|
||||
->setSymbol('ù')
|
||||
->setFormat('%n %c')
|
||||
;
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $updatedCurrency);
|
||||
$this->assertEquals('test update', $updatedCurrency->getName());
|
||||
$this->assertEquals('AZER', $updatedCurrency->getCode());
|
||||
$this->assertEquals('2.35', $updatedCurrency->getRate());
|
||||
$this->assertEquals('en_US', $updatedCurrency->getLocale());
|
||||
$this->assertEquals('ù', $updatedCurrency->getSymbol());
|
||||
$this->assertEquals('%n %c', $updatedCurrency->getFormat());
|
||||
|
||||
return $updatedCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyModel $currency
|
||||
* @depends testUpdate
|
||||
* @return CurrencyModel
|
||||
*/
|
||||
public function testSetDefault(CurrencyModel $currency)
|
||||
{
|
||||
$event = new CurrencyUpdateEvent($currency->getId());
|
||||
$event
|
||||
->setIsDefault(1);
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->setDefault($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $updatedCurrency);
|
||||
|
||||
$this->assertEquals(1, $updatedCurrency->getByDefault());
|
||||
$this->assertEquals(1, CurrencyQuery::create()->filterByByDefault(true)->count());
|
||||
|
||||
return $updatedCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyModel $currency
|
||||
* @depends testSetDefault
|
||||
*/
|
||||
public function testDelete(CurrencyModel $currency)
|
||||
{
|
||||
$currency->setByDefault(0)
|
||||
->save();
|
||||
|
||||
$event = new CurrencyDeleteEvent($currency->getId());
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $deletedCurrency);
|
||||
|
||||
$this->assertTrue($deletedCurrency->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage It is not allowed to delete the default currency
|
||||
*/
|
||||
public function testDeleteDefault()
|
||||
{
|
||||
CurrencyQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->limit(1)
|
||||
->update(array('ByDefault' => true));
|
||||
|
||||
$currency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||
|
||||
$event = new CurrencyDeleteEvent($currency->getId());
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
CurrencyQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->limit(1)
|
||||
->update(array('ByDefault' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
// TODO: Implement buildContainer() method.
|
||||
}
|
||||
|
||||
protected function getCurrencyConverter()
|
||||
{
|
||||
$ecbProvider = new ECBProvider();
|
||||
$currencyConverter = new CurrencyConverter($ecbProvider);
|
||||
|
||||
return $currencyConverter;
|
||||
}
|
||||
}
|
||||
187
tests/phpunit/Thelia/Tests/Action/CustomerTest.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Customer;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
* Class CustomerTest
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CustomerTest extends BaseAction
|
||||
{
|
||||
/**
|
||||
* @var SecurityContext
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $customerAction;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
CustomerQuery::create()
|
||||
->filterByRef('testRef')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$this->request = new Request();
|
||||
$this->request->setSession($session);
|
||||
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($this->request);
|
||||
|
||||
$this->securityContext = new SecurityContext($requestStack);
|
||||
|
||||
$this->customerAction = new Customer(
|
||||
$this->securityContext,
|
||||
new MailerFactory($this->getMockEventDispatcher(), $this->getMockParserInterface()),
|
||||
$this->getMockEventDispatcher()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreatedCustomer()
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
1,
|
||||
"thelia",
|
||||
"thelia",
|
||||
"street address 1",
|
||||
"street address 2",
|
||||
"street address 3",
|
||||
"0102030405",
|
||||
"0607080910",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
sprintf("%s@thelia.fr", uniqid()),
|
||||
uniqid(),
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'My super company',
|
||||
null
|
||||
);
|
||||
|
||||
/** @var Customer $customerAction */
|
||||
$customerAction = $this->customerAction;
|
||||
|
||||
$customerAction->create($customerCreateEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$customerCreated = $customerCreateEvent->getCustomer();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Customer", $customerCreated, "new customer created must be an instance of Thelia\Model\Customer");
|
||||
$this->assertFalse($customerCreated->isNew());
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $customerCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
|
||||
$this->assertEquals($customerCreateEvent->getReseller(), $customerCreated->getReseller());
|
||||
$this->assertEquals($customerCreateEvent->getSponsor(), $customerCreated->getSponsor());
|
||||
$this->assertEquals($customerCreateEvent->getDiscount(), $customerCreated->getDiscount());
|
||||
|
||||
$addressCreated = $customerCreated->getDefaultAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $addressCreated);
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getAddress1(), $addressCreated->getAddress1());
|
||||
$this->assertEquals($customerCreateEvent->getAddress2(), $addressCreated->getAddress2());
|
||||
$this->assertEquals($customerCreateEvent->getAddress3(), $addressCreated->getAddress3());
|
||||
$this->assertEquals($customerCreateEvent->getZipcode(), $addressCreated->getZipcode());
|
||||
$this->assertEquals($customerCreateEvent->getCity(), $addressCreated->getCity());
|
||||
$this->assertEquals($customerCreateEvent->getCountry(), $addressCreated->getCountryId());
|
||||
$this->assertEquals($customerCreateEvent->getPhone(), $addressCreated->getPhone());
|
||||
$this->assertEquals($customerCreateEvent->getCellphone(), $addressCreated->getCellphone());
|
||||
$this->assertEquals($customerCreateEvent->getCompany(), $addressCreated->getCompany());
|
||||
}
|
||||
|
||||
public function testCreatedCustomerWithSpecifiedRef()
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
1,
|
||||
"thelia",
|
||||
"thelia",
|
||||
"street address 1",
|
||||
"street address 2",
|
||||
"street address 3",
|
||||
"0102030405",
|
||||
"0607080910",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
sprintf("%s@thelia.fr", uniqid()),
|
||||
uniqid(),
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'My super company',
|
||||
'testRef'
|
||||
);
|
||||
|
||||
/** @var Customer $customerAction */
|
||||
$customerAction = $this->customerAction;
|
||||
|
||||
$customerAction->create($customerCreateEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$customerCreated = $customerCreateEvent->getCustomer();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Customer", $customerCreated, "new customer created must be an instance of Thelia\Model\Customer");
|
||||
$this->assertFalse($customerCreated->isNew());
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $customerCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
|
||||
$this->assertEquals($customerCreateEvent->getReseller(), $customerCreated->getReseller());
|
||||
$this->assertEquals($customerCreateEvent->getSponsor(), $customerCreated->getSponsor());
|
||||
$this->assertEquals($customerCreateEvent->getDiscount(), $customerCreated->getDiscount());
|
||||
$this->assertEquals($customerCreateEvent->getRef(), $customerCreated->getRef());
|
||||
|
||||
$addressCreated = $customerCreated->getDefaultAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $addressCreated);
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getAddress1(), $addressCreated->getAddress1());
|
||||
$this->assertEquals($customerCreateEvent->getAddress2(), $addressCreated->getAddress2());
|
||||
$this->assertEquals($customerCreateEvent->getAddress3(), $addressCreated->getAddress3());
|
||||
$this->assertEquals($customerCreateEvent->getZipcode(), $addressCreated->getZipcode());
|
||||
$this->assertEquals($customerCreateEvent->getCity(), $addressCreated->getCity());
|
||||
$this->assertEquals($customerCreateEvent->getCountry(), $addressCreated->getCountryId());
|
||||
$this->assertEquals($customerCreateEvent->getPhone(), $addressCreated->getPhone());
|
||||
$this->assertEquals($customerCreateEvent->getCellphone(), $addressCreated->getCellphone());
|
||||
$this->assertEquals($customerCreateEvent->getCompany(), $addressCreated->getCompany());
|
||||
}
|
||||
}
|
||||
280
tests/phpunit/Thelia/Tests/Action/DocumentTest.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Action\Document;
|
||||
use Thelia\Core\Event\Document\DocumentEvent;
|
||||
use Thelia\Files\FileManager;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class DocumentTest
|
||||
*
|
||||
* @package Thelia\Tests\Action\DocumentTest
|
||||
*/
|
||||
class DocumentTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $cache_dir_from_web_root;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $session;
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
|
||||
$fileManager = new FileManager([
|
||||
"document.product" => "Thelia\\Model\\ProductDocument",
|
||||
"image.product" => "Thelia\\Model\\ProductImage",
|
||||
"document.category" => "Thelia\\Model\\CategoryDocument",
|
||||
"image.category" => "Thelia\\Model\\CategoryImage",
|
||||
"document.content" => "Thelia\\Model\\ContentDocument",
|
||||
"image.content" => "Thelia\\Model\\ContentImage",
|
||||
"document.folder" => "Thelia\\Model\\FolderDocument",
|
||||
"image.folder" => "Thelia\\Model\\FolderImage",
|
||||
"document.brand" => "Thelia\\Model\\BrandDocument",
|
||||
"image.brand" => "Thelia\\Model\\BrandImage",
|
||||
]);
|
||||
|
||||
$container->set("thelia.file_manager", $this->getFileManager());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($this->session);
|
||||
|
||||
$container->set("request", $request);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function getFileManager()
|
||||
{
|
||||
$fileManager = new FileManager([
|
||||
"document.product" => "Thelia\\Model\\ProductDocument",
|
||||
"image.product" => "Thelia\\Model\\ProductImage",
|
||||
"document.category" => "Thelia\\Model\\CategoryDocument",
|
||||
"image.category" => "Thelia\\Model\\CategoryImage",
|
||||
"document.content" => "Thelia\\Model\\ContentDocument",
|
||||
"image.content" => "Thelia\\Model\\ContentImage",
|
||||
"document.folder" => "Thelia\\Model\\FolderDocument",
|
||||
"image.folder" => "Thelia\\Model\\FolderImage",
|
||||
"document.brand" => "Thelia\\Model\\BrandDocument",
|
||||
"image.brand" => "Thelia\\Model\\BrandImage",
|
||||
]);
|
||||
|
||||
return $fileManager;
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->session = new Session(new MockArraySessionStorage());
|
||||
$this->request = new Request();
|
||||
|
||||
$this->request->setSession($this->session);
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('document_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$this->cache_dir_from_web_root = $config->getValue();
|
||||
|
||||
$config->setValue(__DIR__ . "/assets/documents/cache");
|
||||
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$dir = THELIA_WEB_DIR . "/cache/tests";
|
||||
if ($dh = @opendir($dir)) {
|
||||
while ($file = readdir($dh)) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
unlink(sprintf("%s/%s", $dir, $file));
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
// restore cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('document_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Documentevent is empty, mandatory parameters not specified.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessEmptyDocumentEvent()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->processDocument($event);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a non-existent file
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessNonExistentDocument()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.txt");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$document->processDocument($event);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a file outside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessDocumentOutsideValidPath()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.pdf");
|
||||
$event->setCacheSubdirectory("../../../");
|
||||
|
||||
$document->processDocument($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> copie !
|
||||
*/
|
||||
public function testProcessDocumentCopy()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/documents/sources/test-document-1.txt");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName(Document::CONFIG_DELIVERY_MODE)->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('copy')->save();
|
||||
}
|
||||
|
||||
$document->processDocument($event);
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('document_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-document-1.txt");
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> link !
|
||||
*/
|
||||
public function testProcessDocumentSymlink()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/documents/sources/test-document-2.txt");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName(Document::CONFIG_DELIVERY_MODE)->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('symlink')->save();
|
||||
}
|
||||
|
||||
$document->processDocument($event);
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('document_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-document-2.txt");
|
||||
}
|
||||
|
||||
public function testClearTestsCache()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('tests');
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->clearCache($event);
|
||||
}
|
||||
|
||||
public function testClearWholeCache()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->clearCache($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to clear directory ouside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testClearUnallowedPathCache()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('../../../..');
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->clearCache($event);
|
||||
}
|
||||
}
|
||||
119
tests/phpunit/Thelia/Tests/Action/FeatureAvTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\FeatureAv;
|
||||
use Thelia\Core\Event\Feature\FeatureAvCreateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvDeleteEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvUpdateEvent;
|
||||
use Thelia\Model\FeatureAv as FeatureAvModel;
|
||||
use Thelia\Model\FeatureQuery;
|
||||
|
||||
/**
|
||||
* Class FeatureAvTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class FeatureAvTest extends BaseAction
|
||||
{
|
||||
/**
|
||||
* @return \Thelia\Model\Feature
|
||||
*/
|
||||
protected function getRandomFeature()
|
||||
{
|
||||
$feature = FeatureQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $feature) {
|
||||
$this->fail('use fixtures before launching test, there is no feature in database');
|
||||
}
|
||||
|
||||
return $feature;
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$feature = $this->getRandomFeature();
|
||||
|
||||
$event = new FeatureAvCreateEvent();
|
||||
$event
|
||||
->setFeatureId($feature->getId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('test');
|
||||
|
||||
$action = new FeatureAv();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdFeatureAv = $event->getFeatureAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\FeatureAv', $createdFeatureAv);
|
||||
|
||||
$this->assertFalse($createdFeatureAv->isNew());
|
||||
|
||||
$this->assertEquals('en_US', $createdFeatureAv->getLocale());
|
||||
$this->assertEquals('test', $createdFeatureAv->getTitle());
|
||||
$this->assertEquals($feature->getId(), $createdFeatureAv->getFeatureId());
|
||||
|
||||
return $createdFeatureAv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureAvModel $featureAv
|
||||
* @depends testCreate
|
||||
* @return FeatureAvModel
|
||||
*/
|
||||
public function testUpdate(FeatureAvModel $featureAv)
|
||||
{
|
||||
$event = new FeatureAvUpdateEvent($featureAv->getId());
|
||||
$event
|
||||
->setLocale('en_uS')
|
||||
->setTitle('test update')
|
||||
->setDescription('test description')
|
||||
->setChapo('test chapo')
|
||||
->setPostscriptum('test postscriptum');
|
||||
|
||||
$action = new FeatureAv();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFeatureAv = $event->getFeatureAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\FeatureAv', $updatedFeatureAv);
|
||||
|
||||
$this->assertEquals('en_US', $updatedFeatureAv->getLocale());
|
||||
$this->assertEquals('test update', $updatedFeatureAv->getTitle());
|
||||
$this->assertEquals('test chapo', $updatedFeatureAv->getChapo());
|
||||
$this->assertEquals('test description', $updatedFeatureAv->getDescription());
|
||||
$this->assertEquals('test postscriptum', $updatedFeatureAv->getPostscriptum());
|
||||
|
||||
return $updatedFeatureAv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureAvModel $featureAv
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(FeatureAvModel $featureAv)
|
||||
{
|
||||
$event = new FeatureAvDeleteEvent($featureAv->getId());
|
||||
|
||||
$action = new FeatureAv();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedFeatureAv = $event->getFeatureAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\FeatureAv', $deletedFeatureAv);
|
||||
|
||||
$this->assertTrue($deletedFeatureAv->isDeleted());
|
||||
}
|
||||
}
|
||||
99
tests/phpunit/Thelia/Tests/Action/FeatureTest.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Feature;
|
||||
use Thelia\Core\Event\Feature\FeatureDeleteEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureUpdateEvent;
|
||||
use Thelia\Model\Feature as FeatureModel;
|
||||
use Thelia\Core\Event\Feature\FeatureCreateEvent;
|
||||
|
||||
/**
|
||||
* Class FeatureTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class FeatureTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new FeatureCreateEvent();
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test feature');
|
||||
|
||||
$action = new Feature();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdFeature = $event->getFeature();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Feature', $createdFeature);
|
||||
|
||||
$this->assertFalse($createdFeature->isNew());
|
||||
|
||||
$this->assertEquals("en_US", $createdFeature->getLocale());
|
||||
$this->assertEquals("test feature", $createdFeature->getTitle());
|
||||
|
||||
return $createdFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureModel $feature
|
||||
* @depends testCreate
|
||||
* @return FeatureModel
|
||||
*/
|
||||
public function testUpdate(FeatureModel $feature)
|
||||
{
|
||||
$event = new FeatureUpdateEvent($feature->getId());
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update')
|
||||
->setChapo('test chapo')
|
||||
->setDescription('test description')
|
||||
->setPostscriptum('test postscriptum');
|
||||
|
||||
$action = new Feature();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFeature = $event->getFeature();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Feature', $updatedFeature);
|
||||
|
||||
$this->assertEquals('test update', $updatedFeature->getTitle());
|
||||
$this->assertEquals('test chapo', $updatedFeature->getChapo());
|
||||
$this->assertEquals('test description', $updatedFeature->getDescription());
|
||||
$this->assertEquals('test postscriptum', $updatedFeature->getPostscriptum());
|
||||
$this->assertEquals('en_US', $updatedFeature->getLocale());
|
||||
|
||||
return $updatedFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureModel $feature
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(FeatureModel $feature)
|
||||
{
|
||||
$event = new FeatureDeleteEvent($feature->getId());
|
||||
|
||||
$action = new Feature();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedFeature = $event->getFeature();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Feature', $deletedFeature);
|
||||
|
||||
$this->assertTrue($deletedFeature->isDeleted());
|
||||
}
|
||||
}
|
||||
319
tests/phpunit/Thelia/Tests/Action/FolderTest.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?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\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Action\Folder;
|
||||
use Thelia\Core\Event\Folder\FolderCreateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Folder\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\UpdateSeoEvent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\Folder as FolderModel;
|
||||
|
||||
/**
|
||||
* Class FolderTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class FolderTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
use RewrittenUrlTestTrait;
|
||||
use I18nTestTrait;
|
||||
|
||||
/** @var int folder id used in position tests */
|
||||
protected static $folderIdForPositionTest = null;
|
||||
|
||||
public function getUpdateEvent(&$folder)
|
||||
{
|
||||
if (!$folder instanceof FolderModel) {
|
||||
$folder = $this->getRandomFolder();
|
||||
}
|
||||
|
||||
$event = new FolderUpdateEvent($folder->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale($folder->getLocale())
|
||||
->setTitle($folder->getTitle())
|
||||
->setChapo($folder->getChapo())
|
||||
->setDescription($folder->getDescription())
|
||||
->setPostscriptum($folder->getPostscriptum())
|
||||
->setParent($folder->getParent())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function getUpdateSeoEvent(&$folder)
|
||||
{
|
||||
if (!$folder instanceof FolderModel) {
|
||||
$folder = $this->getRandomFolder();
|
||||
}
|
||||
|
||||
$event = new UpdateSeoEvent($folder->getId());
|
||||
$event
|
||||
->setLocale($folder->getLocale())
|
||||
->setMetaTitle($folder->getMetaTitle())
|
||||
->setMetaDescription($folder->getMetaDescription())
|
||||
->setMetaKeywords($folder->getMetaKeywords());
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function processUpdateSeoAction($event)
|
||||
{
|
||||
$contentAction = new Folder();
|
||||
|
||||
return $contentAction->updateSeo($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FolderUpdateEvent $event
|
||||
* @return FolderModel
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$contentAction = new Folder();
|
||||
$contentAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getFolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* test folder creation
|
||||
* @covers Thelia\Action\Folder::create
|
||||
*/
|
||||
public function testCreateFolder()
|
||||
{
|
||||
$event = new FolderCreateEvent();
|
||||
$event
|
||||
->setParent(0)
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('folder creation test');
|
||||
|
||||
$folderAction = new Folder();
|
||||
|
||||
$folderAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$folder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $folder);
|
||||
$this->assertEquals('folder creation test', $folder->getTitle());
|
||||
$this->assertEquals(1, $folder->getVisible());
|
||||
$this->assertEquals(0, $folder->getParent());
|
||||
}
|
||||
|
||||
/**
|
||||
* test update creation
|
||||
* @covers Thelia\Action\Folder::update
|
||||
*/
|
||||
public function testUpdateFolder()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$visible = !$folder->getVisible();
|
||||
$event = new FolderUpdateEvent($folder->getId());
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update folder')
|
||||
->setVisible($visible)
|
||||
->setChapo('test folder update chapo')
|
||||
->setDescription('update folder description')
|
||||
->setPostscriptum('update folder postscriptum')
|
||||
->setParent(0)
|
||||
;
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $updatedFolder);
|
||||
$this->assertEquals('test update folder', $updatedFolder->getTitle());
|
||||
$this->assertEquals('test folder update chapo', $updatedFolder->getChapo());
|
||||
$this->assertEquals('update folder description', $updatedFolder->getDescription());
|
||||
$this->assertEquals('update folder postscriptum', $updatedFolder->getPostscriptum());
|
||||
$this->assertEquals(0, $updatedFolder->getParent());
|
||||
$this->assertEquals($visible, $updatedFolder->getVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* test folder removal
|
||||
* @covers Thelia\Action\Folder::delete
|
||||
*/
|
||||
public function testDeleteFolder()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$event = new FolderDeleteEvent($folder->getId());
|
||||
$folderAction = new Folder();
|
||||
$folderAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedFolder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $deletedFolder);
|
||||
$this->assertTrue($deletedFolder->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* test folder toggle visibility
|
||||
* @covers Thelia\Action\Folder::toggleVisibility
|
||||
*/
|
||||
public function testToggleVisibility()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
$visible = $folder->getVisible();
|
||||
|
||||
$event = new FolderToggleVisibilityEvent($folder);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $updatedFolder);
|
||||
$this->assertEquals(!$visible, $updatedFolder->getVisible());
|
||||
}
|
||||
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->filterByParent($this->getFolderIdForPositionTest())
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
$newPosition = $folder->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_UP);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = FolderQuery::create()->findPk($folder->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedFolder->getPosition(), sprintf("new position is %d, new position expected is %d for folder %d", $newPosition, $updatedFolder->getPosition(), $updatedFolder->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionDown()
|
||||
{
|
||||
$nextFolder = FolderQuery::create()
|
||||
->filterByParent($this->getFolderIdForPositionTest())
|
||||
->filterByPosition(2)
|
||||
->findOne();
|
||||
|
||||
if (null === $nextFolder) {
|
||||
$this->fail('use fixtures before launching test, there is not enough folder in database');
|
||||
}
|
||||
|
||||
$folder = FolderQuery::create()
|
||||
->filterByPosition(1)
|
||||
->filterByParent($nextFolder->getParent())
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is not enough folder in database');
|
||||
}
|
||||
|
||||
$newPosition = $folder->getPosition()+1;
|
||||
|
||||
$event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_DOWN);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = FolderQuery::create()->findPk($folder->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedFolder->getPosition(), sprintf("new position is %d, new position expected is %d for folder %d", $newPosition, $updatedFolder->getPosition(), $updatedFolder->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionWithSpecificPosition()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->filterByParent($this->getFolderIdForPositionTest())
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
$event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = FolderQuery::create()->findPk($folder->getId());
|
||||
|
||||
$this->assertEquals(1, $updatedFolder->getPosition(), sprintf("new position is 1, new position expected is %d for folder %d", $updatedFolder->getPosition(), $updatedFolder->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a folder and its sub folders to be used in Position tests
|
||||
*
|
||||
* @return int the parent folder id
|
||||
*/
|
||||
protected function getFolderIdForPositionTest()
|
||||
{
|
||||
if (null === self::$folderIdForPositionTest) {
|
||||
$folder = new FolderModel();
|
||||
|
||||
$folder->setParent(0);
|
||||
$folder->setVisible(1);
|
||||
$folder->setPosition(1);
|
||||
|
||||
$this->setI18n($folder);
|
||||
|
||||
$folder->save();
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$subFolder = new FolderModel();
|
||||
|
||||
$subFolder->setParent($folder->getId());
|
||||
$subFolder->setVisible(1);
|
||||
$subFolder->setPosition($i + 1);
|
||||
|
||||
$this->setI18n($subFolder);
|
||||
|
||||
$subFolder->save();
|
||||
}
|
||||
|
||||
self::$folderIdForPositionTest = $folder->getId();
|
||||
}
|
||||
|
||||
return self::$folderIdForPositionTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Folder
|
||||
*/
|
||||
protected function getRandomFolder()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
return $folder;
|
||||
}
|
||||
}
|
||||
224
tests/phpunit/Thelia/Tests/Action/HookTest.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Hook;
|
||||
use Thelia\Core\Event\Hook\HookCreateAllEvent;
|
||||
use Thelia\Core\Event\Hook\HookDeactivationEvent;
|
||||
use Thelia\Core\Event\Hook\HookDeleteEvent;
|
||||
use Thelia\Core\Event\Hook\HookToggleActivationEvent;
|
||||
use Thelia\Core\Event\Hook\HookUpdateEvent;
|
||||
use Thelia\Model\Hook as HookModel;
|
||||
use Thelia\Core\Event\Hook\HookCreateEvent;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
/**
|
||||
* Class HookTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class HookTest extends BaseAction
|
||||
{
|
||||
/** @var Hook $action */
|
||||
protected $action;
|
||||
|
||||
protected $locale;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->locale = LangQuery::create()->findOne()->getLocale();
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->action = new Hook($stubContainer, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new HookCreateEvent();
|
||||
$event
|
||||
->setCode('test.hook-' . uniqid())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(true)
|
||||
->setNative(true)
|
||||
->setTitle("Hook Test");
|
||||
|
||||
$this->action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdHook = $event->getHook();
|
||||
|
||||
$this->assertInstanceOf('\Thelia\Model\Hook', $createdHook);
|
||||
$this->assertFalse($createdHook->isNew());
|
||||
$this->assertTrue($event->hasHook());
|
||||
|
||||
$this->assertEquals($event->getCode(), $createdHook->getCode());
|
||||
$this->assertEquals($event->getType(), $createdHook->getType());
|
||||
$this->assertEquals($event->getLocale(), $createdHook->getLocale());
|
||||
$this->assertEquals($event->getActive(), $createdHook->getActivate());
|
||||
$this->assertEquals($event->getNative(), $createdHook->getNative());
|
||||
$this->assertEquals($event->getTitle(), $createdHook->getTitle());
|
||||
|
||||
return $createdHook;
|
||||
}
|
||||
|
||||
public function createAll(HookCreateAllEvent $event)
|
||||
{
|
||||
$event = new HookCreateAllEvent();
|
||||
$event
|
||||
->setCode('test.hook-' . uniqid())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(true)
|
||||
->setNative(true)
|
||||
->setTitle("Hook Test")
|
||||
->setDescription("Hook Description")
|
||||
->setChapo("Hook Chapo")
|
||||
->setBlock(false)
|
||||
->setByModule(false);
|
||||
|
||||
$this->action->createAll($event);
|
||||
|
||||
$createdHook = $event->getHook();
|
||||
|
||||
$this->assertInstanceOf('\Thelia\Model\Hook', $createdHook);
|
||||
$this->assertFalse($createdHook->isNew());
|
||||
$this->assertTrue($event->hasHook());
|
||||
|
||||
$this->assertEquals($event->getCode(), $createdHook->getCode());
|
||||
$this->assertEquals($event->getType(), $createdHook->getType());
|
||||
$this->assertEquals($event->getLocale(), $createdHook->getLocale());
|
||||
$this->assertEquals($event->getActive(), $createdHook->getActivate());
|
||||
$this->assertEquals($event->getNative(), $createdHook->getNative());
|
||||
$this->assertEquals($event->getTitle(), $createdHook->getTitle());
|
||||
$this->assertEquals($event->getDescription(), $createdHook->getDescription());
|
||||
$this->assertEquals($event->getChapo(), $createdHook->getChapo());
|
||||
$this->assertEquals($event->getBlock(), $createdHook->getBlock());
|
||||
$this->assertEquals($event->getByModule(), $createdHook->getByModule());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testCreate
|
||||
* @expectedException \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function testCreateDuplicate(HookModel $hook)
|
||||
{
|
||||
$event = new HookCreateEvent();
|
||||
$event
|
||||
->setCode($hook->getCode())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(true)
|
||||
->setNative(true)
|
||||
->setTitle("Hook Test");
|
||||
|
||||
$this->action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdHook = $event->getHook();
|
||||
|
||||
$this->assertNull($createdHook);
|
||||
$this->assertFalse($event->hasHook());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testCreate
|
||||
* @return HookModel
|
||||
*/
|
||||
public function testDeactivation(HookModel $hook)
|
||||
{
|
||||
$event = new HookDeactivationEvent($hook->getId());
|
||||
|
||||
$this->action->deactivation($event);
|
||||
$updatedHook = $event->getHook();
|
||||
|
||||
$this->assertFalse($updatedHook->getActivate());
|
||||
|
||||
return $hook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testDeactivation
|
||||
* @return HookModel
|
||||
*/
|
||||
public function testToggleActivation(HookModel $hook)
|
||||
{
|
||||
$event = new HookToggleActivationEvent($hook->getId());
|
||||
|
||||
$this->action->toggleActivation($event, null, $this->getMockEventDispatcher());
|
||||
$updatedHook = $event->getHook();
|
||||
|
||||
$this->assertTrue($updatedHook->getActivate());
|
||||
|
||||
return $hook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testToggleActivation
|
||||
* @return HookModel
|
||||
*/
|
||||
public function testUpdate(HookModel $hook)
|
||||
{
|
||||
$event = new HookUpdateEvent($hook->getId());
|
||||
|
||||
$event
|
||||
->setCode('test.hook.' . uniqid())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(false)
|
||||
->setNative(false)
|
||||
->setTitle("Updated Hook Test")
|
||||
->setDescription("Updated Hook Description")
|
||||
->setChapo("Updated Hook Chapo")
|
||||
->setBlock(false)
|
||||
->setByModule(false);
|
||||
|
||||
$this->action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedHook = $event->getHook();
|
||||
|
||||
$this->assertEquals($event->getCode(), $updatedHook->getCode());
|
||||
$this->assertEquals($event->getType(), $updatedHook->getType());
|
||||
$this->assertEquals($event->getLocale(), $updatedHook->getLocale());
|
||||
$this->assertEquals($event->getActive(), $updatedHook->getActivate());
|
||||
$this->assertEquals($event->getNative(), $updatedHook->getNative());
|
||||
$this->assertEquals($event->getTitle(), $updatedHook->getTitle());
|
||||
$this->assertEquals($event->getDescription(), $updatedHook->getDescription());
|
||||
$this->assertEquals($event->getChapo(), $updatedHook->getChapo());
|
||||
$this->assertEquals($event->getBlock(), $updatedHook->getBlock());
|
||||
$this->assertEquals($event->getByModule(), $updatedHook->getByModule());
|
||||
|
||||
return $updatedHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(HookModel $hook)
|
||||
{
|
||||
$event = new HookDeleteEvent($hook->getId());
|
||||
|
||||
$this->action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedHook = $event->getHook();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Hook', $deletedHook);
|
||||
$this->assertTrue($deletedHook->isDeleted());
|
||||
}
|
||||
}
|
||||
53
tests/phpunit/Thelia/Tests/Action/I18nTestTrait.php
Normal file
@@ -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\Action;
|
||||
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
/**
|
||||
* Class I18NTestTrait
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
trait I18nTestTrait
|
||||
{
|
||||
/** @var array list of available locale */
|
||||
protected static $localeList = null;
|
||||
|
||||
/**
|
||||
* populate a list of field for each locale for an object
|
||||
*
|
||||
* @param mixed $object the object to populate
|
||||
* @param array $fields list of field to populate
|
||||
* @param array $localeList list of locale to use populate the object
|
||||
*/
|
||||
protected function setI18n(&$object, $fields = array("Title"), $localeList = null)
|
||||
{
|
||||
if (null === $localeList) {
|
||||
if (null === self::$localeList) {
|
||||
self::$localeList = LangQuery::create()
|
||||
->select("Locale")
|
||||
->find()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
$localeList = self::$localeList;
|
||||
}
|
||||
|
||||
foreach ($localeList as $locale) {
|
||||
foreach ($fields as $name) {
|
||||
$object->getTranslation($locale)->setByName($name, $locale . ' : ' . $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
396
tests/phpunit/Thelia/Tests/Action/ImageTest.php
Executable file
@@ -0,0 +1,396 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Action\Image;
|
||||
use Thelia\Core\Event\Image\ImageEvent;
|
||||
use Thelia\Files\FileManager;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class ImageTest
|
||||
*
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
*/
|
||||
class ImageTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $cache_dir_from_web_root;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $session;
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->set("event_dispatcher", $this->getDispatcher());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($this->session);
|
||||
|
||||
$container->set("request", $request);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function getFileManager()
|
||||
{
|
||||
$fileManager = new FileManager([
|
||||
"document.product" => "Thelia\\Model\\ProductDocument",
|
||||
"image.product" => "Thelia\\Model\\ProductImage",
|
||||
"document.category" => "Thelia\\Model\\CategoryDocument",
|
||||
"image.category" => "Thelia\\Model\\CategoryImage",
|
||||
"document.content" => "Thelia\\Model\\ContentDocument",
|
||||
"image.content" => "Thelia\\Model\\ContentImage",
|
||||
"document.folder" => "Thelia\\Model\\FolderDocument",
|
||||
"image.folder" => "Thelia\\Model\\FolderImage",
|
||||
"document.brand" => "Thelia\\Model\\BrandDocument",
|
||||
"image.brand" => "Thelia\\Model\\BrandImage",
|
||||
]);
|
||||
|
||||
return $fileManager;
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->session = new Session(new MockArraySessionStorage());
|
||||
$this->request = new Request();
|
||||
|
||||
$this->request->setSession($this->session);
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('image_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$this->cache_dir_from_web_root = $config->getValue();
|
||||
|
||||
$config->setValue(__DIR__ . "/assets/images/cache");
|
||||
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$dir = THELIA_WEB_DIR . "/cache/tests";
|
||||
if ($dh = @opendir($dir)) {
|
||||
while ($file = readdir($dh)) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
unlink(sprintf("%s/%s", $dir, $file));
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
// restore cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('image_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Imageevent is empty, mandatory parameters not specified.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessEmptyImageEvent()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a non-existent file
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessNonExistentImage()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a file outside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessImageOutsideValidPath()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.png");
|
||||
$event->setCacheSubdirectory("../../../");
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> copie !
|
||||
*/
|
||||
public function testProcessImageWithoutAnyTransformationsCopy()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-1.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('copy')->save();
|
||||
}
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('image_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-image-1.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> copie !
|
||||
*/
|
||||
public function testProcessImageWithoutAnyTransformationsSymlink()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-9.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('symlink')->save();
|
||||
}
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('image_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-image-9.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with bands width > height
|
||||
*/
|
||||
public function testProcessImageResizeHorizWithBands()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-2.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with bands height > width
|
||||
*/
|
||||
public function testProcessImageResizeVertWithBands()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-3.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply all transformations
|
||||
*/
|
||||
public function testProcessImageWithTransformations()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-4.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setEffects(array("grayscale", "vertical_flip", "horizontal_flip", 'colorize:#00ff00', 'gamma: 0.2'));
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with crop width > height
|
||||
*/
|
||||
public function testProcessImageResizeHorizWithCrop()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-5.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(180);
|
||||
$event->setHeight(100);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with crop height > width
|
||||
*/
|
||||
public function testProcessImageResizeVertWithCrop()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-6.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(150);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image keeping image ration
|
||||
*/
|
||||
public function testProcessImageResizeHorizKeepRatio()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-7.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with crop height > width
|
||||
*/
|
||||
public function testProcessImageResizeVertKeepRatio()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-8.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public function testClearTestsCache()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('tests');
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->clearCache($event);
|
||||
}
|
||||
|
||||
public function testClearWholeCache()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->clearCache($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to clear directory ouside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testClearUnallowedPathCache()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('../../../..');
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->clearCache($event);
|
||||
}
|
||||
}
|
||||
231
tests/phpunit/Thelia/Tests/Action/LangTest.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?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\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Lang;
|
||||
use Thelia\Core\Event\Lang\LangDeleteEvent;
|
||||
use Thelia\Core\Event\Lang\LangToggleDefaultEvent;
|
||||
use Thelia\Core\Event\Lang\LangUpdateEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Template\TheliaTemplateHelper;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Model\Lang as LangModel;
|
||||
use Thelia\Core\Event\Lang\LangCreateEvent;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class LangTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class LangTest extends ContainerAwareTestCase
|
||||
{
|
||||
protected static $defaultId;
|
||||
|
||||
protected $requestStack;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$lang = LangQuery::create()
|
||||
->filterByByDefault(1)
|
||||
->findOne();
|
||||
|
||||
self::$defaultId = $lang->getId();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
$this->requestStack = new RequestStack();
|
||||
$this->requestStack->push($request);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new LangCreateEvent();
|
||||
|
||||
$event
|
||||
->setLocale('te_TE')
|
||||
->setTitle('test')
|
||||
->setCode('TES')
|
||||
->setDateFormat('Y-m-d')
|
||||
->setTimeFormat('H:i:s')
|
||||
->setDecimalSeparator(".")
|
||||
->setThousandsSeparator(" ")
|
||||
->setDecimals("2")
|
||||
;
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $createdLang);
|
||||
|
||||
$this->assertFalse($createdLang->isNew());
|
||||
|
||||
$this->assertEquals('te_TE', $createdLang->getLocale());
|
||||
$this->assertEquals('test', $createdLang->getTitle());
|
||||
$this->assertEquals('TES', $createdLang->getCode());
|
||||
$this->assertEquals('Y-m-d H:i:s', $createdLang->getDatetimeFormat());
|
||||
$this->assertEquals('Y-m-d', $createdLang->getDateFormat());
|
||||
$this->assertEquals('H:i:s', $createdLang->getTimeFormat());
|
||||
$this->assertEquals('.', $createdLang->getDecimalSeparator());
|
||||
$this->assertEquals(' ', $createdLang->getThousandsSeparator());
|
||||
$this->assertEquals('2', $createdLang->getDecimals());
|
||||
|
||||
return $createdLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LangModel $lang
|
||||
* @depends testCreate
|
||||
* @return LangModel
|
||||
*/
|
||||
public function testUpdate(LangModel $lang)
|
||||
{
|
||||
$event = new LangUpdateEvent($lang->getId());
|
||||
|
||||
$event
|
||||
->setLocale('te_TE')
|
||||
->setTitle('test update')
|
||||
->setCode('TEST')
|
||||
->setDateFormat('d-m-Y')
|
||||
->setTimeFormat('H-i-s')
|
||||
->setDecimalSeparator(",")
|
||||
->setThousandsSeparator(".")
|
||||
->setDecimals("1")
|
||||
;
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $updatedLang);
|
||||
|
||||
$this->assertEquals('te_TE', $updatedLang->getLocale());
|
||||
$this->assertEquals('TEST', $updatedLang->getCode());
|
||||
$this->assertEquals('test update', $updatedLang->getTitle());
|
||||
$this->assertEquals('d-m-Y', $updatedLang->getDateFormat());
|
||||
$this->assertEquals('H-i-s', $updatedLang->getTimeFormat());
|
||||
$this->assertEquals(',', $updatedLang->getDecimalSeparator());
|
||||
$this->assertEquals('.', $updatedLang->getThousandsSeparator());
|
||||
$this->assertEquals('1', $updatedLang->getDecimals());
|
||||
$this->assertEquals('d-m-Y H-i-s', $updatedLang->getDatetimeFormat());
|
||||
|
||||
// set a specific date/time format
|
||||
$event->setDateTimeFormat('d/m/Y H:i:s');
|
||||
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $updatedLang);
|
||||
$this->assertEquals('d/m/Y H:i:s', $updatedLang->getDatetimeFormat());
|
||||
|
||||
return $updatedLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LangModel $lang
|
||||
* @depends testUpdate
|
||||
* @return LangModel
|
||||
*/
|
||||
public function testToggleDefault(LangModel $lang)
|
||||
{
|
||||
$event = new LangToggleDefaultEvent($lang->getId());
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->toggleDefault($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $updatedLang);
|
||||
|
||||
$this->assertEquals('1', $updatedLang->getByDefault());
|
||||
|
||||
$this->assertEquals('1', LangQuery::create()->filterByByDefault(1)->count());
|
||||
|
||||
return $updatedLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LangModel $lang
|
||||
* @depends testToggleDefault
|
||||
*/
|
||||
public function testDelete(LangModel $lang)
|
||||
{
|
||||
$lang->setByDefault(0)
|
||||
->save();
|
||||
|
||||
self::tearDownAfterClass();
|
||||
|
||||
$event = new LangDeleteEvent($lang->getId());
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $deletedLang);
|
||||
|
||||
$this->assertTrue($deletedLang->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage It is not allowed to delete the default language
|
||||
*/
|
||||
public function testDeleteDefault()
|
||||
{
|
||||
$lang = LangQuery::create()->findOneByByDefault(1);
|
||||
|
||||
$event = new LangDeleteEvent($lang->getId());
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
LangQuery::create()
|
||||
->filterById(self::$defaultId)
|
||||
->update(array('ByDefault' => true));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
@unlink(THELIA_TEMPLATE_DIR . "backOffice/default/assets/img/flags/TEST.png");
|
||||
@unlink(THELIA_TEMPLATE_DIR . "backOffice/default/assets/img/flags/TES.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
// TODO: Implement buildContainer() method.
|
||||
}
|
||||
}
|
||||
121
tests/phpunit/Thelia/Tests/Action/MessageTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Message;
|
||||
use Thelia\Core\Event\Message\MessageDeleteEvent;
|
||||
use Thelia\Core\Event\Message\MessageUpdateEvent;
|
||||
use Thelia\Model\Message as MessageModel;
|
||||
use Thelia\Core\Event\Message\MessageCreateEvent;
|
||||
use Thelia\Model\MessageQuery;
|
||||
|
||||
/**
|
||||
* Class MessageTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class MessageTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$lang = MessageQuery::create()
|
||||
->filterByName('test')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new MessageCreateEvent();
|
||||
$event
|
||||
->setMessageName('test')
|
||||
->setLocale('en_US')
|
||||
->setTitle('test title')
|
||||
->setSecured(0)
|
||||
;
|
||||
|
||||
$action = new Message();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdMessage = $event->getMessage();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Message', $createdMessage);
|
||||
$this->assertFalse($createdMessage->isNew());
|
||||
|
||||
$this->assertEquals('test', $createdMessage->getName());
|
||||
$this->assertEquals('en_US', $createdMessage->getLocale());
|
||||
$this->assertEquals('test title', $createdMessage->getTitle());
|
||||
$this->assertEquals(0, $createdMessage->getSecured());
|
||||
|
||||
return $createdMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MessageModel $message
|
||||
* @depends testCreate
|
||||
* @return MessageModel
|
||||
*/
|
||||
public function testModify(MessageModel $message)
|
||||
{
|
||||
$event = new MessageUpdateEvent($message->getId());
|
||||
|
||||
$event
|
||||
->setMessageName('test')
|
||||
->setLocale('en_us')
|
||||
->setTitle('test update title')
|
||||
->setSubject('test subject')
|
||||
->setHtmlMessage('my html message')
|
||||
->setTextMessage('my text message')
|
||||
->setHtmlLayoutFileName(null)
|
||||
->setHtmlTemplateFileName(null)
|
||||
->setTextLayoutFileName(null)
|
||||
->setTextTemplateFileName(null)
|
||||
;
|
||||
|
||||
$action = new Message();
|
||||
$action->modify($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedMessage = $event->getMessage();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Message', $updatedMessage);
|
||||
|
||||
$this->assertEquals('test', $updatedMessage->getName());
|
||||
$this->assertEquals('en_US', $updatedMessage->getLocale());
|
||||
$this->assertEquals('test update title', $updatedMessage->getTitle());
|
||||
$this->assertEquals('test subject', $updatedMessage->getSubject());
|
||||
$this->assertEquals('my html message', $updatedMessage->getHtmlMessage());
|
||||
$this->assertEquals('my text message', $updatedMessage->getTextMessage());
|
||||
$this->assertNull($updatedMessage->getHtmlLayoutFileName());
|
||||
$this->assertNull($updatedMessage->getHtmlTemplateFileName());
|
||||
$this->assertNull($updatedMessage->getTextLayoutFileName());
|
||||
$this->assertNull($updatedMessage->getTextTemplateFileName());
|
||||
|
||||
return $updatedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MessageModel $message
|
||||
* @depends testModify
|
||||
*/
|
||||
public function testDelete(MessageModel $message)
|
||||
{
|
||||
$event = new MessageDeleteEvent($message->getId());
|
||||
|
||||
$action = new Message();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedMessage = $event->getMessage();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Message', $deletedMessage);
|
||||
$this->assertTrue($deletedMessage->isDeleted());
|
||||
}
|
||||
}
|
||||
189
tests/phpunit/Thelia/Tests/Action/MetaDataTest.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Core\Event\MetaData\MetaDataDeleteEvent;
|
||||
use Thelia\Model\MetaDataQuery;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Action\MetaData;
|
||||
use Thelia\Core\Event\MetaData\MetaDataCreateOrUpdateEvent;
|
||||
use Thelia\Model\ProductQuery;
|
||||
|
||||
/**
|
||||
* Class MetaDataTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class MetaDataTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$boom = MetaDataQuery::create()
|
||||
->deleteAll();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
// get a product
|
||||
$product = ProductQuery::create()->findOne();
|
||||
|
||||
// simple
|
||||
$event = new MetaDataCreateOrUpdateEvent();
|
||||
$event
|
||||
->setMetaKey('test')
|
||||
->setElementKey(get_class($product))
|
||||
->setElementId($product->getId())
|
||||
->setValue('test');
|
||||
|
||||
$action = new MetaData();
|
||||
$action->createOrUpdate($event);
|
||||
|
||||
$created = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $created);
|
||||
|
||||
$this->assertFalse($created->isNew());
|
||||
|
||||
$this->assertEquals('test', $created->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $created->getElementKey());
|
||||
$this->assertEquals($product->getId(), $created->getElementId());
|
||||
$this->assertEquals('test', $created->getValue());
|
||||
$this->assertEquals(false, $created->getIsSerialized());
|
||||
|
||||
// complex
|
||||
$event = new MetaDataCreateOrUpdateEvent();
|
||||
$event
|
||||
->setMetaKey('test2')
|
||||
->setElementKey(get_class($product))
|
||||
->setElementId($product->getId())
|
||||
->setValue(array("fr_FR" => "bonjour", "en_US" => "Hello"));
|
||||
$action = new MetaData();
|
||||
$action->createOrUpdate($event);
|
||||
|
||||
$created = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $created);
|
||||
|
||||
$this->assertFalse($created->isNew());
|
||||
|
||||
$this->assertEquals('test2', $created->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $created->getElementKey());
|
||||
$this->assertEquals($product->getId(), $created->getElementId());
|
||||
$this->assertEquals(array("fr_FR" => "bonjour", "en_US" => "Hello"), $created->getValue());
|
||||
$this->assertEquals(true, $created->getIsSerialized());
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @depends testCreate
|
||||
* @return Product
|
||||
*/
|
||||
public function testRead(Product $product)
|
||||
{
|
||||
$metaDatas = MetaDataQuery::create()
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->find();
|
||||
|
||||
$this->assertEquals($metaDatas->count(), 2);
|
||||
|
||||
$metaData = MetaDataQuery::create()
|
||||
->filterByMetaKey('test')
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($metaData);
|
||||
$this->assertEquals('test', $metaData->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $metaData->getElementKey());
|
||||
$this->assertEquals($product->getId(), $metaData->getElementId());
|
||||
$this->assertEquals('test', $metaData->getValue());
|
||||
|
||||
$this->assertEquals(false, $metaData->getIsSerialized());
|
||||
|
||||
$datas = MetaDataQuery::getAllVal(get_class($product), $product->getId());
|
||||
$this->assertEquals(count($datas), 2);
|
||||
$this->assertEquals($datas['test'], 'test');
|
||||
$this->assertEquals($datas['test2'], array("fr_FR" => "bonjour", "en_US" => "Hello"));
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @depends testRead
|
||||
* @return Product
|
||||
*/
|
||||
public function testUpdate(Product $product)
|
||||
{
|
||||
$metaData = MetaDataQuery::create()
|
||||
->filterByMetaKey('test')
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($metaData);
|
||||
|
||||
$event = new MetaDataCreateOrUpdateEvent();
|
||||
$event
|
||||
->setMetaKey($metaData->getMetaKey())
|
||||
->setElementKey($metaData->getElementKey())
|
||||
->setElementId($metaData->getElementId())
|
||||
->setValue(array("fr_FR" => "bonjour", "en_US" => "Hello"));
|
||||
|
||||
$action = new MetaData();
|
||||
$action->createOrUpdate($event);
|
||||
|
||||
$updated = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $updated);
|
||||
|
||||
$this->assertFalse($updated->isNew());
|
||||
|
||||
$this->assertEquals('test', $updated->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $updated->getElementKey());
|
||||
$this->assertEquals($product->getId(), $updated->getElementId());
|
||||
$this->assertEquals(array("fr_FR" => "bonjour", "en_US" => "Hello"), $updated->getValue());
|
||||
$this->assertEquals(true, $updated->getIsSerialized());
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @depends testUpdate
|
||||
* @return Product
|
||||
*/
|
||||
public function testDelete(Product $product)
|
||||
{
|
||||
$metaData = MetaDataQuery::create()
|
||||
->filterByMetaKey('test')
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($metaData);
|
||||
|
||||
$event = new MetaDataDeleteEvent('test', get_class($product), $product->getId());
|
||||
|
||||
$action = new MetaData();
|
||||
$action->delete($event);
|
||||
|
||||
$deleted = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $deleted);
|
||||
$this->assertTrue($deleted->isDeleted());
|
||||
}
|
||||
}
|
||||
137
tests/phpunit/Thelia/Tests/Action/ModuleHookTest.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\ModuleHook;
|
||||
use Thelia\Core\Event\Hook\ModuleHookCreateEvent;
|
||||
use Thelia\Core\Event\Hook\ModuleHookDeleteEvent;
|
||||
use Thelia\Core\Event\Hook\ModuleHookToggleActivationEvent;
|
||||
use Thelia\Core\Event\Hook\ModuleHookUpdateEvent;
|
||||
use Thelia\Model\Hook as HookModel;
|
||||
use Thelia\Model\Module as ModuleModel;
|
||||
use Thelia\Model\ModuleHook as ModuleHookModel;
|
||||
use Thelia\Model\HookQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
|
||||
/**
|
||||
* Class HookTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class ModuleHookTest extends BaseAction
|
||||
{
|
||||
/** @var ModuleHook $action */
|
||||
protected $action;
|
||||
|
||||
/** @var ModuleModel */
|
||||
protected $module;
|
||||
|
||||
/** @var HookModel */
|
||||
protected $hook;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->action = new ModuleHook($stubContainer, $this->getMockEventDispatcher());
|
||||
|
||||
$this->module = ModuleQuery::create()->findOneByActivate(1);
|
||||
|
||||
$this->hook = HookQuery::create()->findOneByActivate(true);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new ModuleHookCreateEvent();
|
||||
$event
|
||||
->setHookId($this->hook->getId())
|
||||
->setModuleId($this->module->getId());
|
||||
|
||||
$this->action->createModuleHook($event);
|
||||
|
||||
$createdModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertInstanceOf('\Thelia\Model\ModuleHook', $createdModuleHook);
|
||||
$this->assertFalse($createdModuleHook->isNew());
|
||||
$this->assertTrue($event->hasModuleHook());
|
||||
|
||||
$this->assertEquals($event->getHookId(), $createdModuleHook->getHookId());
|
||||
$this->assertEquals($event->getModuleId(), $createdModuleHook->getModuleId());
|
||||
|
||||
return $createdModuleHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModuleHookModel $moduleHook
|
||||
* @depends testCreate
|
||||
* @return ModuleHookModel
|
||||
*/
|
||||
public function testToggleActivation(ModuleHookModel $moduleHook)
|
||||
{
|
||||
$activated = $moduleHook->getActive();
|
||||
|
||||
$event = new ModuleHookToggleActivationEvent($moduleHook);
|
||||
|
||||
$this->action->toggleModuleHookActivation($event, null, $this->getMockEventDispatcher());
|
||||
$updatedModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertEquals(!$activated, $updatedModuleHook->getActive());
|
||||
|
||||
return $updatedModuleHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModuleHookModel $moduleHook
|
||||
* @depends testToggleActivation
|
||||
* @return ModuleHookModel
|
||||
*/
|
||||
public function testUpdate(ModuleHookModel $moduleHook)
|
||||
{
|
||||
$event = new ModuleHookUpdateEvent($moduleHook);
|
||||
|
||||
$event
|
||||
->setHookId($moduleHook->getHookId())
|
||||
->setClassname($moduleHook->getClassname())
|
||||
->setMethod($moduleHook->getMethod())
|
||||
->setActive(true);
|
||||
|
||||
$this->action->updateModuleHook($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertEquals($event->getHookId(), $updatedModuleHook->getHookId());
|
||||
$this->assertEquals($event->getClassname(), $updatedModuleHook->getClassname());
|
||||
$this->assertEquals($event->getMethod(), $updatedModuleHook->getMethod());
|
||||
$this->assertEquals($event->getActive(), $updatedModuleHook->getActive());
|
||||
|
||||
return $updatedModuleHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModuleHookModel $moduleHook
|
||||
* @depends testUpdate
|
||||
* @return ModuleHookModel
|
||||
*/
|
||||
public function testDelete(ModuleHookModel $moduleHook)
|
||||
{
|
||||
$event = new ModuleHookDeleteEvent($moduleHook->getId());
|
||||
|
||||
$this->action->deleteModuleHook($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\ModuleHook', $deletedModuleHook);
|
||||
$this->assertTrue($deletedModuleHook->isDeleted());
|
||||
}
|
||||
}
|
||||
118
tests/phpunit/Thelia/Tests/Action/NewsletterTest.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Newsletter;
|
||||
use Thelia\Model\Newsletter as NewsletterModel;
|
||||
use Thelia\Core\Event\Newsletter\NewsletterEvent;
|
||||
use Thelia\Model\NewsletterQuery;
|
||||
|
||||
/**
|
||||
* Class NewsletterTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class NewsletterTest extends BaseAction
|
||||
{
|
||||
protected $mailerFactory;
|
||||
protected $dispatcher;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mailerFactory = $this->getMockBuilder("Thelia\\Mailer\\MailerFactory")
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$this->dispatcher = $this->getMockEventDispatcher();
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
NewsletterQuery::create()
|
||||
->filterByEmail('test@foo.com')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testSubscribe()
|
||||
{
|
||||
$event = new NewsletterEvent('test@foo.com', 'en_US');
|
||||
$event
|
||||
->setFirstname("foo")
|
||||
->setLastname("bar")
|
||||
;
|
||||
|
||||
$action = new Newsletter($this->mailerFactory, $this->dispatcher);
|
||||
$action->subscribe($event);
|
||||
|
||||
$subscribedNewsletter = $event->getNewsletter();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Newsletter', $subscribedNewsletter);
|
||||
$this->assertFalse($subscribedNewsletter->isNew());
|
||||
|
||||
$this->assertEquals('test@foo.com', $subscribedNewsletter->getEmail());
|
||||
$this->assertEquals('en_US', $subscribedNewsletter->getLocale());
|
||||
$this->assertEquals('foo', $subscribedNewsletter->getFirstname());
|
||||
$this->assertEquals('bar', $subscribedNewsletter->getLastname());
|
||||
|
||||
return $subscribedNewsletter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewsletterModel $newsletter
|
||||
* @depends testSubscribe
|
||||
* @return NewsletterModel
|
||||
*/
|
||||
public function testUpdate(NewsletterModel $newsletter)
|
||||
{
|
||||
$event = new NewsletterEvent('test@foo.com', 'en_US');
|
||||
$event
|
||||
->setId($newsletter->getId())
|
||||
->setFirstname("foo update")
|
||||
->setLastname("bar update")
|
||||
;
|
||||
|
||||
$action = new Newsletter($this->mailerFactory, $this->dispatcher);
|
||||
$action->update($event);
|
||||
|
||||
$updatedNewsletter = $event->getNewsletter();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Newsletter', $updatedNewsletter);
|
||||
|
||||
$this->assertEquals('test@foo.com', $updatedNewsletter->getEmail());
|
||||
$this->assertEquals('en_US', $updatedNewsletter->getLocale());
|
||||
$this->assertEquals('foo update', $updatedNewsletter->getFirstname());
|
||||
$this->assertEquals('bar update', $updatedNewsletter->getLastname());
|
||||
|
||||
return $updatedNewsletter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewsletterModel $newsletter
|
||||
* @depends testUpdate
|
||||
* @param NewsletterModel $newsletter
|
||||
*/
|
||||
public function testUnsubscribe(NewsletterModel $newsletter)
|
||||
{
|
||||
$event = new NewsletterEvent('test@foo.com', 'en_US');
|
||||
$event->setId($newsletter->getId());
|
||||
|
||||
$action = new Newsletter($this->mailerFactory, $this->dispatcher);
|
||||
$action->unsubscribe($event);
|
||||
|
||||
$deletedNewsletter = $event->getNewsletter();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Newsletter', $deletedNewsletter);
|
||||
$this->assertEquals(1, NewsletterQuery::create()->filterByEmail('test@foo.com')->filterByUnsubscribed(true)->count());
|
||||
}
|
||||
}
|
||||
226
tests/phpunit/Thelia/Tests/Action/OrderStatusTest.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?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\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Action\OrderStatus as OrderStatusAction;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusCreateEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusDeleteEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\OrderStatus as OrderStatusModel;
|
||||
|
||||
/**
|
||||
* Class OrderStatusTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
*/
|
||||
class OrderStatusTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
/**
|
||||
* @param OrderStatusModel $orderStatus
|
||||
* @return OrderStatusUpdateEvent
|
||||
*/
|
||||
public function getUpdateEvent(OrderStatusModel $orderStatus)
|
||||
{
|
||||
$event = new OrderStatusUpdateEvent($orderStatus->getId());
|
||||
$event
|
||||
->setLocale($orderStatus->getLocale())
|
||||
->setTitle($orderStatus->getTitle())
|
||||
->setChapo($orderStatus->getChapo())
|
||||
->setDescription($orderStatus->getDescription())
|
||||
->setPostscriptum($orderStatus->getPostscriptum())
|
||||
->setColor($orderStatus->getColor())
|
||||
->setCode($orderStatus->getCode())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderStatusUpdateEvent $event
|
||||
* @return OrderStatusModel
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->update($event);
|
||||
|
||||
return $event->getOrderStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status creation
|
||||
* @covers Thelia\Action\OrderStatus::create
|
||||
*/
|
||||
public function testCreateOrderStatus()
|
||||
{
|
||||
OrderStatusQuery::create()->filterByCode(['order_status_test', 'order_status_test2'], Criteria::IN)->delete();
|
||||
|
||||
$code = 'order_status_test';
|
||||
|
||||
$event = new OrderStatusCreateEvent();
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('order status creation test')
|
||||
->setCode($code);
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
|
||||
$orderStatusAction->create($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertEquals('order status creation test', $orderStatus->getTitle());
|
||||
$this->assertEquals($code, $orderStatus->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* test update creation
|
||||
* @covers Thelia\Action\OrderStatus::update
|
||||
*/
|
||||
public function testUpdateOrderStatusProtected()
|
||||
{
|
||||
if (null !== $find = OrderStatusQuery::create()->findOneByCode('paid_force_update')) {
|
||||
$find->setCode('paid')->save();
|
||||
}
|
||||
|
||||
if (null === OrderStatusQuery::create()->findOneByCode('paid')) {
|
||||
$this->fail('It\'s not possible to run the tests, because the order status "paid" not found');
|
||||
}
|
||||
|
||||
$event = $this->getUpdateEvent(OrderStatusQuery::create()->findOneByCode('paid'));
|
||||
|
||||
$event->setDescription('test');
|
||||
$event->setCode('paid_force_update');
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->update($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertEquals('test', $orderStatus->getDescription());
|
||||
$this->assertEquals('paid', $orderStatus->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* test update creation
|
||||
* @covers Thelia\Action\OrderStatus::update
|
||||
* @depends testCreateOrderStatus
|
||||
*/
|
||||
public function testUpdateOrderStatusNotProtected()
|
||||
{
|
||||
$event = $this->getUpdateEvent(OrderStatusQuery::create()->findOneByCode('order_status_test'));
|
||||
|
||||
$event->setDescription('test');
|
||||
$event->setCode('order_status_test2');
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->update($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertEquals('test', $orderStatus->getDescription());
|
||||
$this->assertEquals('order_status_test2', $orderStatus->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status removal
|
||||
* @covers Thelia\Action\OrderStatus::delete
|
||||
* @depends testUpdateOrderStatusNotProtected
|
||||
*/
|
||||
public function testDeleteOrderStatus()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()->findOneByCode('order_status_test2');
|
||||
|
||||
$event = new OrderStatusDeleteEvent($orderStatus->getId());
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->delete($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertTrue($orderStatus->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status removal
|
||||
* @covers Thelia\Action\OrderStatus::delete
|
||||
* @depends testUpdateOrderStatusProtected
|
||||
*/
|
||||
public function testDeleteOrderStatusProtected()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()->findOneByCode('paid');
|
||||
|
||||
$event = new OrderStatusDeleteEvent($orderStatus->getId());
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
|
||||
try {
|
||||
$orderStatusAction->delete($event);
|
||||
$this->fail("A protected order status has been removed");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status removal
|
||||
* @covers Thelia\Action\OrderStatus::delete
|
||||
* @depends testUpdateOrderStatusNotProtected
|
||||
*/
|
||||
public function testDeleteOrderStatusWithOrders()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()->findOneByCode('paid');
|
||||
|
||||
$event = new OrderStatusDeleteEvent($orderStatus->getId());
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
|
||||
try {
|
||||
$orderStatusAction->delete($event);
|
||||
$this->fail("A protected order status with orders has been removed");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status update position
|
||||
* @covers Thelia\Action\OrderStatus::updatePosition
|
||||
*/
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()
|
||||
->filterByPosition(2)
|
||||
->findOne();
|
||||
|
||||
if (null === $orderStatus) {
|
||||
$this->fail('Use fixtures before launching test, there is not enough folder in database');
|
||||
}
|
||||
|
||||
$newPosition = $orderStatus->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent($orderStatus->getId(), UpdatePositionEvent::POSITION_UP);
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$orderStatusUpdated = OrderStatusQuery::create()->findOneById($orderStatus->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $orderStatusUpdated->getPosition(), sprintf("new position is %d, new position expected is %d for order status %d", $newPosition, $orderStatusUpdated->getPosition(), $orderStatusUpdated->getCode()));
|
||||
}
|
||||
}
|
||||
716
tests/phpunit/Thelia/Tests/Action/OrderTest.php
Normal file
@@ -0,0 +1,716 @@
|
||||
<?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\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Order;
|
||||
use Thelia\Core\Event\Order\OrderAddressEvent;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\Order\OrderManualEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\Cart;
|
||||
use Thelia\Model\CartItem;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Customer as CustomerModel;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Model\Order as OrderModel;
|
||||
use Thelia\Model\OrderAddressQuery;
|
||||
use Thelia\Model\OrderProductQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\OrderStatus;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
/**
|
||||
* Class CustomerTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class OrderTest extends BaseAction
|
||||
{
|
||||
/**
|
||||
* @var ContainerBuilder $container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var Order $orderAction
|
||||
*/
|
||||
protected $orderAction;
|
||||
|
||||
/**
|
||||
* @var \Thelia\Core\Event\Order\OrderEvent $orderEvent
|
||||
*/
|
||||
protected $orderEvent;
|
||||
|
||||
/**
|
||||
* @var CustomerModel $customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @var Cart $customer
|
||||
*/
|
||||
protected $cart;
|
||||
|
||||
/**
|
||||
* @var CartItem[]
|
||||
*/
|
||||
protected $cartItems;
|
||||
|
||||
/**
|
||||
* @var SecurityContext
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
/** @var RequestStack */
|
||||
protected $requestStack;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
$this->container = new ContainerBuilder();
|
||||
|
||||
$this->container->set("event_dispatcher", $this->getMockEventDispatcher());
|
||||
$this->container->set('request', $request);
|
||||
|
||||
$this->requestStack = new RequestStack();
|
||||
$this->requestStack->push($request);
|
||||
$this->container->set('request_stack', $this->requestStack);
|
||||
|
||||
$this->securityContext = new SecurityContext($this->requestStack);
|
||||
|
||||
$this->orderEvent = new OrderEvent(new OrderModel());
|
||||
|
||||
$mailerFactory = new MailerFactory(
|
||||
$this->getMockEventDispatcher(),
|
||||
$this->getMockParserInterface()
|
||||
);
|
||||
|
||||
$this->orderAction = new Order(
|
||||
$this->requestStack,
|
||||
$mailerFactory,
|
||||
$this->securityContext
|
||||
);
|
||||
|
||||
/* load customer */
|
||||
$this->customer = $this->loadCustomer();
|
||||
if (null === $this->customer) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* fill cart */
|
||||
$this->cart = $this->fillCart();
|
||||
}
|
||||
|
||||
public function loadCustomer()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
if (null === $customer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->securityContext->setCustomerUser($customer);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public function fillCart()
|
||||
{
|
||||
$currency = CurrencyQuery::create()->findOne();
|
||||
|
||||
//create a fake cart in database;
|
||||
$cart = new Cart();
|
||||
$cart->setToken(uniqid("createorder", true))
|
||||
->setCustomer($this->customer)
|
||||
->setCurrency($currency)
|
||||
->save();
|
||||
|
||||
/* add 3 items */
|
||||
$productList = array();
|
||||
for ($i=0; $i<3; $i++) {
|
||||
$pse = ProductSaleElementsQuery::create()
|
||||
->filterByProduct(
|
||||
ProductQuery::create()
|
||||
->filterByVisible(1)
|
||||
->filterById($productList, Criteria::NOT_IN)
|
||||
->find()
|
||||
)
|
||||
->filterByQuantity(5, Criteria::GREATER_EQUAL)
|
||||
->joinProductPrice('pp', Criteria::INNER_JOIN)
|
||||
->addJoinCondition('pp', 'currency_id = ?', $currency->getId(), null, \PDO::PARAM_INT)
|
||||
->withColumn('`pp`.price', 'price_PRICE')
|
||||
->withColumn('`pp`.promo_price', 'price_PROMO_PRICE')
|
||||
->findOne();
|
||||
|
||||
$productList[] = $pse->getProductId();
|
||||
|
||||
$cartItem = new CartItem();
|
||||
$cartItem
|
||||
->setCart($cart)
|
||||
->setProduct($pse->getProduct())
|
||||
->setProductSaleElements($pse)
|
||||
->setQuantity($i+1)
|
||||
->setPrice($pse->getPrice())
|
||||
->setPromoPrice($pse->getPromoPrice())
|
||||
->setPromo($pse->getPromo())
|
||||
->setPriceEndOfLife(time() + 60*60*24*30)
|
||||
->save();
|
||||
$this->cartItems[] = $cartItem;
|
||||
}
|
||||
|
||||
$this->requestStack->getCurrentRequest()->getSession()->set("thelia.cart_id", $cart->getId());
|
||||
|
||||
return $cart;
|
||||
}
|
||||
|
||||
public function testSetDeliveryAddress()
|
||||
{
|
||||
//$validAddressId = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$this->orderEvent->setDeliveryAddress(321);
|
||||
|
||||
$this->orderAction->setDeliveryAddress($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
321,
|
||||
$this->orderEvent->getOrder()->getChoosenDeliveryAddress()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetinvoiceAddress()
|
||||
{
|
||||
$this->orderEvent->setInvoiceAddress(654);
|
||||
|
||||
$this->orderAction->setInvoiceAddress($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
654,
|
||||
$this->orderEvent->getOrder()->getChoosenInvoiceAddress()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetDeliveryModule()
|
||||
{
|
||||
$this->orderEvent->setDeliveryModule(123);
|
||||
|
||||
$this->orderAction->setDeliveryModule($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
123,
|
||||
$this->orderEvent->getOrder()->getDeliveryModuleId()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetPaymentModule()
|
||||
{
|
||||
$this->orderEvent->setPaymentModule(456);
|
||||
|
||||
$this->orderAction->setPaymentModule($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
456,
|
||||
$this->orderEvent->getOrder()->getPaymentModuleId()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
$validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$deliveryModule = ModuleQuery::create()
|
||||
->filterByType(BaseModule::DELIVERY_MODULE_TYPE)
|
||||
->filterByActivate(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $deliveryModule) {
|
||||
throw new \Exception('No Delivery Module fixture found');
|
||||
}
|
||||
|
||||
$paymentModule = ModuleQuery::create()
|
||||
->filterByType(BaseModule::PAYMENT_MODULE_TYPE)
|
||||
->filterByActivate(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $paymentModule) {
|
||||
throw new \Exception('No Payment Module fixture found');
|
||||
}
|
||||
|
||||
/* define payment module in container */
|
||||
$paymentModuleClass = $paymentModule->getFullNamespace();
|
||||
|
||||
/** @var \Thelia\Module\PaymentModuleInterface $paymentInstance */
|
||||
$paymentInstance = new $paymentModuleClass();
|
||||
$this->container->set(sprintf('module.%s', $paymentModule->getCode()), $paymentInstance);
|
||||
$manageStock = $paymentInstance->manageStockOnCreation();
|
||||
|
||||
|
||||
$this->orderEvent->getOrder()->setChoosenDeliveryAddress($validDeliveryAddress->getId());
|
||||
$this->orderEvent->getOrder()->setChoosenInvoiceAddress($validInvoiceAddress->getId());
|
||||
$this->orderEvent->getOrder()->setDeliveryModuleId($deliveryModule->getId());
|
||||
$this->orderEvent->getOrder()->setPostage(20);
|
||||
$this->orderEvent->getOrder()->setPaymentModuleId($paymentModule->getId());
|
||||
|
||||
/* memorize current stocks */
|
||||
$itemsStock = array();
|
||||
foreach ($this->cartItems as $index => $cartItem) {
|
||||
$itemsStock[$index] = $cartItem->getProductSaleElements()->getQuantity();
|
||||
}
|
||||
|
||||
$this->orderAction->create($this->orderEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$placedOrder = $this->orderEvent->getPlacedOrder();
|
||||
|
||||
$this->assertNotNull($placedOrder);
|
||||
$this->assertNotNull($placedOrder->getId());
|
||||
|
||||
/* check customer */
|
||||
$this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not match');
|
||||
|
||||
/* check delivery address */
|
||||
$deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
|
||||
|
||||
/* check invoice address */
|
||||
$invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||
$this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
|
||||
|
||||
/* check currency */
|
||||
$this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not match');
|
||||
$this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not match');
|
||||
|
||||
/* check delivery module */
|
||||
$this->assertEquals(20, $placedOrder->getPostage(), 'postage does not match');
|
||||
$this->assertEquals($deliveryModule->getId(), $placedOrder->getDeliveryModuleId(), 'delivery module does not match');
|
||||
|
||||
/* check payment module */
|
||||
$this->assertEquals($paymentModule->getId(), $placedOrder->getPaymentModuleId(), 'payment module does not match');
|
||||
|
||||
/* check status */
|
||||
$this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not match');
|
||||
|
||||
/* check lang */
|
||||
$this->assertEquals($this->requestStack->getCurrentRequest()->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not match');
|
||||
|
||||
/* check ordered product */
|
||||
foreach ($this->cartItems as $index => $cartItem) {
|
||||
$orderProduct = OrderProductQuery::create()
|
||||
->filterByOrderId($placedOrder->getId())
|
||||
->filterByProductRef($cartItem->getProduct()->getRef())
|
||||
->filterByProductSaleElementsRef($cartItem->getProductSaleElements()->getRef())
|
||||
->filterByQuantity($cartItem->getQuantity())
|
||||
->filterByPrice($cartItem->getPrice(), Criteria::LIKE)
|
||||
->filterByPromoPrice($cartItem->getPromoPrice(), Criteria::LIKE)
|
||||
->filterByWasNew($cartItem->getProductSaleElements()->getNewness())
|
||||
->filterByWasInPromo($cartItem->getPromo())
|
||||
->filterByWeight($cartItem->getProductSaleElements()->getWeight())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($orderProduct);
|
||||
|
||||
/* check attribute combinations */
|
||||
$this->assertEquals(
|
||||
$cartItem->getProductSaleElements()->getAttributeCombinations()->count(),
|
||||
$orderProduct->getOrderProductAttributeCombinations()->count()
|
||||
);
|
||||
|
||||
if ($manageStock) {
|
||||
if ($orderProduct->getVirtual()) {
|
||||
/* check same stock*/
|
||||
$this->assertEquals(
|
||||
$itemsStock[$index],
|
||||
$cartItem->getProductSaleElements()->getQuantity()
|
||||
);
|
||||
} else {
|
||||
/* check stock decrease */
|
||||
$this->assertEquals(
|
||||
$itemsStock[$index] - $orderProduct->getQuantity(),
|
||||
$cartItem->getProductSaleElements()->getQuantity()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
/* check same stock*/
|
||||
$this->assertEquals(
|
||||
$itemsStock[$index],
|
||||
$cartItem->getProductSaleElements()->getQuantity()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* check tax */
|
||||
$orderProductTaxList = $orderProduct->getOrderProductTaxes();
|
||||
foreach ($cartItem->getProduct()->getTaxRule()->getTaxDetail($cartItem->getProduct(), $validDeliveryAddress->getCountry(), $cartItem->getPrice(), $cartItem->getPromoPrice()) as $index => $tax) {
|
||||
$orderProductTax = $orderProductTaxList[$index];
|
||||
$this->assertEquals($tax->getAmount(), $orderProductTax->getAmount());
|
||||
$this->assertEquals($tax->getPromoAmount(), $orderProductTax->getPromoAmount());
|
||||
}
|
||||
}
|
||||
|
||||
return $placedOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
* @param OrderModel $order
|
||||
* @return OrderModel
|
||||
*/
|
||||
public function testCreateManual(OrderModel $order)
|
||||
{
|
||||
$orderCopy = $order->copy();
|
||||
|
||||
$validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
$validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$orderManuelEvent = new OrderManualEvent(
|
||||
$orderCopy,
|
||||
$this->cart->getCurrency(),
|
||||
$this->requestStack->getCurrentRequest()->getSession()->getLang(),
|
||||
$this->cart,
|
||||
$this->customer
|
||||
);
|
||||
|
||||
$orderManuelEvent->getOrder()->setChoosenDeliveryAddress($validDeliveryAddress->getId());
|
||||
$orderManuelEvent->getOrder()->setChoosenInvoiceAddress($validInvoiceAddress->getId());
|
||||
|
||||
$deliveryModuleId = $orderCopy->getDeliveryModuleId();
|
||||
$paymentModuleId = $orderCopy->getPaymentModuleId();
|
||||
|
||||
$this->orderAction->createManual($orderManuelEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$placedOrder = $orderManuelEvent->getPlacedOrder();
|
||||
|
||||
$this->assertNotNull($placedOrder);
|
||||
$this->assertNotNull($placedOrder->getId());
|
||||
|
||||
/* check customer */
|
||||
$this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not match');
|
||||
|
||||
/* check delivery address */
|
||||
$deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
|
||||
|
||||
/* check invoice address */
|
||||
$invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||
$this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
|
||||
|
||||
/* check currency */
|
||||
$this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not match');
|
||||
$this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not match');
|
||||
|
||||
/* check delivery module */
|
||||
$this->assertEquals(20, $placedOrder->getPostage(), 'postage does not match');
|
||||
$this->assertEquals($deliveryModuleId, $placedOrder->getDeliveryModuleId(), 'delivery module does not match');
|
||||
|
||||
/* check payment module */
|
||||
$this->assertEquals($paymentModuleId, $placedOrder->getPaymentModuleId(), 'payment module does not match');
|
||||
|
||||
/* check status */
|
||||
$this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not match');
|
||||
|
||||
/* check lang */
|
||||
$this->assertEquals($this->requestStack->getCurrentRequest()->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not match');
|
||||
|
||||
|
||||
// without address duplication
|
||||
$copyOrder = $order->copy();
|
||||
|
||||
$orderManuelEvent
|
||||
->setOrder($copyOrder)
|
||||
->setUseOrderDefinedAddresses(true);
|
||||
|
||||
$validDeliveryAddressId = $orderCopy->getDeliveryOrderAddressId();
|
||||
$validInvoiceAddressId = $orderCopy->getInvoiceOrderAddressId();
|
||||
|
||||
$this->orderAction->createManual($orderManuelEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$placedOrder = $orderManuelEvent->getPlacedOrder();
|
||||
|
||||
$this->assertNotNull($placedOrder);
|
||||
$this->assertNotNull($placedOrder->getId());
|
||||
|
||||
/* check delivery address */
|
||||
$deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$this->assertEquals($validDeliveryAddressId, $deliveryOrderAddress->getId(), 'delivery address title does not match');
|
||||
|
||||
/* check invoice address */
|
||||
$invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||
$this->assertEquals($validInvoiceAddressId, $invoiceOrderAddress->getId(), 'invoice address title does not match');
|
||||
|
||||
return $placedOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testUpdateStatus(OrderModel $order)
|
||||
{
|
||||
$newStatus = $order->getStatusId() == 5 ? 1 : 5;
|
||||
$this->orderEvent->setStatus($newStatus);
|
||||
$this->orderEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateStatus($this->orderEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$this->assertEquals(
|
||||
$newStatus,
|
||||
$this->orderEvent->getOrder()->getStatusId()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$newStatus,
|
||||
OrderQuery::create()->findPk($order->getId())->getStatusId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusPaidWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setPaid();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isPaid()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusNotPaidWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setNotPaid();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isNotPaid()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusProcessedWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setProcessing();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PROCESSING)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isProcessing()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusSentWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setSent();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_SENT)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isSent()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusCanceledWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setCancelled();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_CANCELED)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isCancelled()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testUpdateTransactionRef(OrderModel $order)
|
||||
{
|
||||
$transactionRef = uniqid('TRANSREF');
|
||||
$this->orderEvent->setTransactionRef($transactionRef);
|
||||
$this->orderEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateTransactionRef($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
$transactionRef,
|
||||
$this->orderEvent->getOrder()->getTransactionRef()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$transactionRef,
|
||||
OrderQuery::create()->findPk($order->getId())->getTransactionRef()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testUpdateDeliveryRef(OrderModel $order)
|
||||
{
|
||||
$deliveryRef = uniqid('DELREF');
|
||||
$this->orderEvent->setDeliveryRef($deliveryRef);
|
||||
$this->orderEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateDeliveryRef($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
$deliveryRef,
|
||||
$this->orderEvent->getOrder()->getDeliveryRef()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$deliveryRef,
|
||||
OrderQuery::create()->findPk($order->getId())->getDeliveryRef()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testUpdateAddress(OrderModel $order)
|
||||
{
|
||||
$orderAddress = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId());
|
||||
$title = $orderAddress->getCustomerTitleId() == 3 ? 1 : 3;
|
||||
$country = $orderAddress->getCountryId() == 64 ? 1 : 64;
|
||||
$orderAddressEvent = new OrderAddressEvent(
|
||||
$title, 'B', 'C', 'D', 'E', 'F', 'G', 'H', $country, 'J', 'K', '0102030405'
|
||||
);
|
||||
$orderAddressEvent->setOrderAddress($orderAddress);
|
||||
$orderAddressEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateAddress($orderAddressEvent);
|
||||
|
||||
$newOrderAddress = OrderAddressQuery::create()->findPk($orderAddress->getId());
|
||||
|
||||
$this->assertEquals($title, $orderAddressEvent->getOrderAddress()->getCustomerTitleId());
|
||||
$this->assertEquals('B', $orderAddressEvent->getOrderAddress()->getFirstname());
|
||||
$this->assertEquals('C', $orderAddressEvent->getOrderAddress()->getLastname());
|
||||
$this->assertEquals('D', $orderAddressEvent->getOrderAddress()->getAddress1());
|
||||
$this->assertEquals('E', $orderAddressEvent->getOrderAddress()->getAddress2());
|
||||
$this->assertEquals('F', $orderAddressEvent->getOrderAddress()->getAddress3());
|
||||
$this->assertEquals('G', $orderAddressEvent->getOrderAddress()->getZipcode());
|
||||
$this->assertEquals('H', $orderAddressEvent->getOrderAddress()->getCity());
|
||||
$this->assertEquals($country, $orderAddressEvent->getOrderAddress()->getCountryId());
|
||||
$this->assertEquals('J', $orderAddressEvent->getOrderAddress()->getPhone());
|
||||
$this->assertEquals('0102030405', $orderAddressEvent->getOrderAddress()->getCellphone());
|
||||
$this->assertEquals('K', $orderAddressEvent->getOrderAddress()->getCompany());
|
||||
|
||||
$this->assertEquals($title, $newOrderAddress->getCustomerTitleId());
|
||||
$this->assertEquals('B', $newOrderAddress->getFirstname());
|
||||
$this->assertEquals('C', $newOrderAddress->getLastname());
|
||||
$this->assertEquals('D', $newOrderAddress->getAddress1());
|
||||
$this->assertEquals('E', $newOrderAddress->getAddress2());
|
||||
$this->assertEquals('F', $newOrderAddress->getAddress3());
|
||||
$this->assertEquals('G', $newOrderAddress->getZipcode());
|
||||
$this->assertEquals('H', $newOrderAddress->getCity());
|
||||
$this->assertEquals($country, $newOrderAddress->getCountryId());
|
||||
$this->assertEquals('J', $newOrderAddress->getPhone());
|
||||
$this->assertEquals('K', $newOrderAddress->getCompany());
|
||||
}
|
||||
}
|
||||
36
tests/phpunit/Thelia/Tests/Action/PdfTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Pdf;
|
||||
use Thelia\Core\Event\PdfEvent;
|
||||
|
||||
/**
|
||||
* Class PdfTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class PdfTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGeneratePdf()
|
||||
{
|
||||
$event = new PdfEvent("test content");
|
||||
|
||||
$action = new Pdf();
|
||||
$action->generatePdf($event);
|
||||
|
||||
$generatedPdf = $event->getPdf();
|
||||
|
||||
$this->assertNotNull($generatedPdf);
|
||||
}
|
||||
}
|
||||
1142
tests/phpunit/Thelia/Tests/Action/ProductTest.php
Normal file
134
tests/phpunit/Thelia/Tests/Action/ProfileTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Profile;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\Profile as ProfileModel;
|
||||
use Thelia\Core\Event\Profile\ProfileEvent;
|
||||
use Thelia\Model\ProfileQuery;
|
||||
|
||||
/**
|
||||
* Class ProfileTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ProfileTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ProfileQuery::create()
|
||||
->filterByCode('Test')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
|
||||
$event
|
||||
->setCode("Test")
|
||||
->setLocale('en_US')
|
||||
->setTitle('test profile')
|
||||
->setChapo('test chapo')
|
||||
->setDescription('test description')
|
||||
->setPostscriptum('test postscriptum');
|
||||
;
|
||||
|
||||
$action = new Profile($this->getMockEventDispatcher());
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $createdProfile);
|
||||
$this->assertFalse($createdProfile->isNew());
|
||||
|
||||
$this->assertEquals('Test', $createdProfile->getCode());
|
||||
$this->assertEquals('en_US', $createdProfile->getLocale());
|
||||
$this->assertEquals('test profile', $createdProfile->getTitle());
|
||||
$this->assertEquals('test chapo', $createdProfile->getChapo());
|
||||
$this->assertEquals('test description', $createdProfile->getDescription());
|
||||
$this->assertEquals('test postscriptum', $createdProfile->getPostscriptum());
|
||||
|
||||
return $createdProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProfileModel $profile
|
||||
* @depends testCreate
|
||||
* @return ProfileModel
|
||||
*/
|
||||
public function testUpdate(ProfileModel $profile)
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
|
||||
$event
|
||||
->setId($profile->getId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update title')
|
||||
->setChapo('test update chapo')
|
||||
->setDescription('test update description')
|
||||
->setPostscriptum('test update postscriptum');
|
||||
;
|
||||
|
||||
$action = new Profile($this->getMockEventDispatcher());
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $updatedProfile);
|
||||
|
||||
$this->assertEquals($profile->getCode(), $updatedProfile->getCode());
|
||||
$this->assertEquals('en_US', $updatedProfile->getLocale());
|
||||
$this->assertEquals('test update title', $updatedProfile->getTitle());
|
||||
$this->assertEquals('test update chapo', $updatedProfile->getChapo());
|
||||
$this->assertEquals('test update description', $updatedProfile->getDescription());
|
||||
$this->assertEquals('test update postscriptum', $updatedProfile->getPostscriptum());
|
||||
|
||||
return $updatedProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProfileModel $profile
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testUpdateResourceAccess(ProfileModel $profile)
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
$event
|
||||
->setId($profile->getId())
|
||||
->setResourceAccess(array(
|
||||
'admin.address' => array(AccessManager::CREATE)
|
||||
))
|
||||
;
|
||||
|
||||
$action = new Profile($this->getMockEventDispatcher());
|
||||
$action->updateResourceAccess($event);
|
||||
|
||||
$updatedProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $updatedProfile);
|
||||
|
||||
$resources = $updatedProfile->getResources();
|
||||
|
||||
$this->assertEquals(1, count($resources));
|
||||
|
||||
$resource = $resources->getFirst();
|
||||
$this->assertEquals('admin.address', $resource->getCode());
|
||||
|
||||
$profileResource = $updatedProfile->getProfileResources()->getFirst();
|
||||
$accessManager = new AccessManager($profileResource->getAccess());
|
||||
|
||||
$this->assertTrue($accessManager->can(AccessManager::CREATE));
|
||||
}
|
||||
}
|
||||
113
tests/phpunit/Thelia/Tests/Action/RewrittenUrlTestTrait.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?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\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Exception\UrlRewritingException;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\RewritingUrlQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Rewriting\RewritingResolver;
|
||||
|
||||
/**
|
||||
* Class RewrittenUrlTestTrait
|
||||
* @package Thelia\Tests\Action
|
||||
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
* @method EventDispatcherInterface getMockEventDispatcher()
|
||||
*/
|
||||
trait RewrittenUrlTestTrait
|
||||
{
|
||||
abstract public function getUpdateEvent(&$object);
|
||||
abstract public function getUpdateSeoEvent(&$object);
|
||||
abstract public function processUpdateAction($event);
|
||||
abstract public function processUpdateSeoAction($event);
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Form\Exception\FormValidationException
|
||||
* @expectedExceptionCode 100
|
||||
*/
|
||||
public function testUpdateExistingUrl()
|
||||
{
|
||||
$object = null;
|
||||
$event = $this->getUpdateSeoEvent($object);
|
||||
|
||||
/* get an existing url */
|
||||
$existingUrl = RewritingUrlQuery::create()
|
||||
->filterByViewId($object->getId(), Criteria::NOT_EQUAL)
|
||||
->filterByRedirected(null)
|
||||
->filterByView(ConfigQuery::getObsoleteRewrittenUrlView(), Criteria::NOT_EQUAL)
|
||||
->findOne();
|
||||
|
||||
if (null === $existingUrl) {
|
||||
$this->fail('use fixtures before launching test, there is not enough rewritten url');
|
||||
}
|
||||
|
||||
$event->setUrl($existingUrl->getUrl());
|
||||
|
||||
$this->processUpdateSeoAction($event);
|
||||
}
|
||||
|
||||
public function testUpdateUrl()
|
||||
{
|
||||
$object = null;
|
||||
$event = $this->getUpdateSeoEvent($object);
|
||||
|
||||
$currentUrl = $object->getRewrittenUrl($object->getLocale());
|
||||
|
||||
/* get a brand new URL */
|
||||
$exist = true;
|
||||
while (true === $exist) {
|
||||
$newUrl = md5(rand(1, 999999)) . ".html";
|
||||
try {
|
||||
new RewritingResolver($newUrl);
|
||||
} catch (UrlRewritingException $e) {
|
||||
if ($e->getCode() === UrlRewritingException::URL_NOT_FOUND) {
|
||||
/* It's all good if URL is not found */
|
||||
$exist = false;
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$event->setUrl($newUrl);
|
||||
|
||||
$updatedObject = $this->processUpdateSeoAction($event);
|
||||
|
||||
/* new URL is updated */
|
||||
$this->assertEquals($newUrl, $updatedObject->getRewrittenUrl($object->getLocale()));
|
||||
|
||||
/* old url must be redirected to the new one */
|
||||
$newUrlEntry = RewritingUrlQuery::create()->findOneByUrl($newUrl);
|
||||
$oldUrlEntry = RewritingUrlQuery::create()->findOneByUrl($currentUrl);
|
||||
|
||||
$this->assertEquals($oldUrlEntry->getRedirected(), $newUrlEntry->getId());
|
||||
|
||||
/* we can reassign old Url to another object */
|
||||
$aRandomProduct = ProductQuery::create()
|
||||
->filterById($object->getId(), Criteria::NOT_EQUAL)
|
||||
->findOne();
|
||||
|
||||
$failReassign = true;
|
||||
try {
|
||||
$aRandomProduct->setRewrittenUrl($aRandomProduct->getLocale(), $currentUrl);
|
||||
$failReassign = false;
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$this->assertFalse($failReassign);
|
||||
}
|
||||
}
|
||||
230
tests/phpunit/Thelia/Tests/Action/SaleTest.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\Sale;
|
||||
use Thelia\Core\Event\Sale\SaleClearStatusEvent;
|
||||
use Thelia\Core\Event\Sale\SaleCreateEvent;
|
||||
use Thelia\Core\Event\Sale\SaleDeleteEvent;
|
||||
use Thelia\Core\Event\Sale\SaleToggleActivityEvent;
|
||||
use Thelia\Core\Event\Sale\SaleUpdateEvent;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\SaleQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\Sale as SaleModel;
|
||||
|
||||
/**
|
||||
* Class SaleTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class SaleTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
public function getUpdateEvent(&$sale)
|
||||
{
|
||||
if (!$sale instanceof SaleModel) {
|
||||
$sale = $this->getRandomSale();
|
||||
}
|
||||
|
||||
$event = new SaleUpdateEvent($sale->getId());
|
||||
$event
|
||||
->setActive(1)
|
||||
->setLocale($sale->getLocale())
|
||||
->setTitle($sale->getTitle())
|
||||
->setChapo($sale->getChapo())
|
||||
->setDescription($sale->getDescription())
|
||||
->setPostscriptum($sale->getPostscriptum())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SaleUpdateEvent $event
|
||||
* @return SaleModel
|
||||
* @throws \Exception
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$saleAction = new Sale();
|
||||
$saleAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getSale();
|
||||
}
|
||||
|
||||
public function testCreateSale()
|
||||
{
|
||||
$event = new SaleCreateEvent();
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test create sale')
|
||||
->setSaleLabel('test create sale label')
|
||||
;
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->create($event);
|
||||
|
||||
$createdSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $createdSale);
|
||||
$this->assertEquals('test create sale', $createdSale->getTitle());
|
||||
$this->assertEquals('test create sale label', $createdSale->getSaleLabel());
|
||||
}
|
||||
|
||||
public function testUpdateSale()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$date = new \DateTime();
|
||||
|
||||
$product = ProductQuery::create()->findOne();
|
||||
|
||||
$event = new SaleUpdateEvent($sale->getId());
|
||||
$event
|
||||
->setStartDate($date->setTimestamp(strtotime("today - 1 month")))
|
||||
->setEndDate($date->setTimestamp(strtotime("today + 1 month")))
|
||||
->setActive(1)
|
||||
->setDisplayInitialPrice(1)
|
||||
->setPriceOffsetType(SaleModel::OFFSET_TYPE_AMOUNT)
|
||||
->setPriceOffsets([ CurrencyQuery::create()->findOne()->getId() => 10 ])
|
||||
->setProducts([$product->getId()])
|
||||
->setProductAttributes([])
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update sale title')
|
||||
->setChapo('test update sale short description')
|
||||
->setDescription('test update sale description')
|
||||
->setPostscriptum('test update sale postscriptum')
|
||||
->setSaleLabel('test create sale label')
|
||||
;
|
||||
|
||||
$saleAction = new Sale();
|
||||
$saleAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $updatedSale);
|
||||
$this->assertEquals(1, $updatedSale->getActive());
|
||||
$this->assertEquals('test update sale title', $updatedSale->getTitle());
|
||||
$this->assertEquals('test update sale short description', $updatedSale->getChapo());
|
||||
$this->assertEquals('test update sale description', $updatedSale->getDescription());
|
||||
$this->assertEquals('test update sale postscriptum', $updatedSale->getPostscriptum());
|
||||
$this->assertEquals('test create sale label', $updatedSale->getSaleLabel());
|
||||
}
|
||||
|
||||
public function testUpdatePseSale()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$date = new \DateTime();
|
||||
|
||||
$product = ProductQuery::create()->findOne();
|
||||
$attrAv = AttributeAvQuery::create()->findOne();
|
||||
|
||||
$event = new SaleUpdateEvent($sale->getId());
|
||||
$event
|
||||
->setStartDate($date->setTimestamp(strtotime("today - 1 month")))
|
||||
->setEndDate($date->setTimestamp(strtotime("today + 1 month")))
|
||||
->setActive(1)
|
||||
->setDisplayInitialPrice(1)
|
||||
->setPriceOffsetType(SaleModel::OFFSET_TYPE_AMOUNT)
|
||||
->setPriceOffsets([ CurrencyQuery::create()->findOne()->getId() => 10 ])
|
||||
->setProducts([$product->getId()])
|
||||
->setProductAttributes([$product->getId() => [ $attrAv->getId()] ])
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update sale title')
|
||||
->setChapo('test update sale short description')
|
||||
->setDescription('test update sale description')
|
||||
->setPostscriptum('test update sale postscriptum')
|
||||
->setSaleLabel('test create sale label')
|
||||
;
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $updatedSale);
|
||||
$this->assertEquals(1, $updatedSale->getActive());
|
||||
$this->assertEquals('test update sale title', $updatedSale->getTitle());
|
||||
$this->assertEquals('test update sale short description', $updatedSale->getChapo());
|
||||
$this->assertEquals('test update sale description', $updatedSale->getDescription());
|
||||
$this->assertEquals('test update sale postscriptum', $updatedSale->getPostscriptum());
|
||||
$this->assertEquals('test create sale label', $updatedSale->getSaleLabel());
|
||||
}
|
||||
|
||||
public function testDeleteSale()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$event = new SaleDeleteEvent($sale->getId());
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $deletedSale);
|
||||
$this->assertTrue($deletedSale->isDeleted());
|
||||
}
|
||||
|
||||
public function testSaleToggleVisibility()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$visibility = $sale->getActive();
|
||||
|
||||
$event = new SaleToggleActivityEvent($sale);
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->toggleActivity($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $updatedSale);
|
||||
$this->assertEquals(!$visibility, $updatedSale->getActive());
|
||||
}
|
||||
|
||||
public function testClearAllSales()
|
||||
{
|
||||
// Store current promo statuses
|
||||
$promoList = ProductSaleElementsQuery::create()->filterByPromo(true)->select('Id')->find()->toArray();
|
||||
|
||||
$event = new SaleClearStatusEvent();
|
||||
|
||||
$saleAction = new Sale();
|
||||
$saleAction->clearStatus($event);
|
||||
|
||||
// Restore promo status
|
||||
ProductSaleElementsQuery::create()->filterById($promoList)->update(['Promo' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Sale
|
||||
*/
|
||||
protected function getRandomSale()
|
||||
{
|
||||
$sale = SaleQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $sale) {
|
||||
$this->fail('use fixtures before launching test, there is no sale in database');
|
||||
}
|
||||
|
||||
return $sale;
|
||||
}
|
||||
}
|
||||
110
tests/phpunit/Thelia/Tests/Action/StateTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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\Action;
|
||||
|
||||
use Thelia\Action\State;
|
||||
use Thelia\Core\Event\State\StateCreateEvent;
|
||||
use Thelia\Core\Event\State\StateDeleteEvent;
|
||||
use Thelia\Core\Event\State\StateUpdateEvent;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\State as StateModel;
|
||||
|
||||
/**
|
||||
* Class StateTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <julien@thelia.net>
|
||||
*/
|
||||
class StateTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$country = CountryQuery::create()
|
||||
->filterByHasStates(1)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
$event = new StateCreateEvent();
|
||||
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setCountry($country->getId())
|
||||
->setIsocode('AA')
|
||||
->setLocale('en_US')
|
||||
->setTitle('State1')
|
||||
;
|
||||
|
||||
$action = new State();
|
||||
$action->create($event);
|
||||
|
||||
$createdState = $event->getState();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\State', $createdState);
|
||||
$this->assertFalse($createdState->isNew());
|
||||
|
||||
$this->assertEquals($country->getId(), $createdState->getCountryId());
|
||||
$this->assertEquals('AA', $createdState->getIsocode());
|
||||
$this->assertEquals('en_US', $createdState->getLocale());
|
||||
$this->assertEquals('State1', $createdState->getTitle());
|
||||
|
||||
return $createdState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StateModel $state
|
||||
* @depends testCreate
|
||||
* @return StateModel
|
||||
*/
|
||||
public function testUpdate(StateModel $state)
|
||||
{
|
||||
$event = new StateUpdateEvent($state->getId());
|
||||
|
||||
$event
|
||||
->setIsocode('BB')
|
||||
->setVisible(0)
|
||||
->setCountry($state->getCountryId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('State2')
|
||||
;
|
||||
|
||||
$action = new State();
|
||||
$action->update($event);
|
||||
|
||||
$updatedState = $event->getState();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\State', $updatedState);
|
||||
|
||||
$this->assertEquals('BB', $updatedState->getIsocode());
|
||||
$this->assertEquals(0, $updatedState->getVisible());
|
||||
$this->assertEquals('en_US', $updatedState->getLocale());
|
||||
$this->assertEquals('State2', $updatedState->getTitle());
|
||||
|
||||
return $updatedState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StateModel $state
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(StateModel $state)
|
||||
{
|
||||
$event = new StateDeleteEvent($state->getId());
|
||||
|
||||
$action = new State();
|
||||
$action->delete($event);
|
||||
|
||||
$deletedState = $event->getState();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\State', $deletedState);
|
||||
$this->assertTrue($deletedState->isDeleted());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
This is a text document.
|
||||
@@ -0,0 +1 @@
|
||||
This is a text document.
|
||||
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-1.png
Executable file
|
After Width: | Height: | Size: 13 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-2.png
Executable file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-3.png
Executable file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-4.png
Executable file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-5.png
Executable file
|
After Width: | Height: | Size: 17 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-6.png
Executable file
|
After Width: | Height: | Size: 15 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-7.png
Executable file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-8.png
Executable file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-9.png
Executable file
|
After Width: | Height: | Size: 11 KiB |