Beispiel #1
0
 /**
  * Shuts the kernel down if it was used in the test.
  */
 protected function tearDown()
 {
     ConfigQuery::write('one_domain_foreach_lang', $this->isMultiDomainActivated);
     if (null !== static::$kernel) {
         static::$kernel->shutdown();
     }
 }
 public static function installThelia(Event $event)
 {
     if ($event->getIO()->askConfirmation('Would you like to install Thelia now ? [Y/n] ', true)) {
         require __DIR__ . "/../../../bootstrap.php";
         $kernel = new Thelia("install", true);
         $kernel->boot();
         $cmd = new Install();
         $cmd->setApplication(new Application($kernel));
         $cmd->run(new ArrayInput(["command" => "thelia:install"]), new ConsoleOutput());
     }
 }
 protected function setUp()
 {
     // Setup a virtual file system under thelia:// stream
     $this->stream = vfsStream::setup("thelia", 0777);
     // Copy the module fixtures
     vfsStream::copyFromFileSystem(__DIR__ . DS . str_replace("/", DS, static::TEST_MODULE_PATH), $this->stream);
     // Initialize the kernel
     $this->kernel = new Thelia("test", true);
     $this->kernel->boot();
     // Then create event
     $this->event = new ModuleGenerateEvent("TheliaStudioTestModule");
     $this->buildEvent();
 }
Beispiel #4
0
 /**
  * Shuts the kernel down if it was used in the test.
  */
 protected function tearDown()
 {
     if (null !== static::$kernel) {
         static::$kernel->shutdown();
     }
 }
Beispiel #5
0
<?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.                             */
/*************************************************************************************/
use Thelia\Core\Thelia;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpKernel\HttpCache\HttpCache;
//use Symfony\Component\DependencyInjection;
$env = 'dev';
require __DIR__ . '/../core/vendor/autoload.php';
// List of allowed IP
$trustedIp = array('::1', '127.0.0.1');
$request = Request::createFromGlobals();
$thelia = new Thelia("dev", true);
if (false === in_array($request->getClientIp(), $trustedIp)) {
    $response = Response::create('Forbidden', 403)->send();
    $thelia->terminate($request, $response);
} else {
    $response = $thelia->handle($request)->prepare($request)->send();
    $thelia->terminate($request, $response);
}
Beispiel #6
0
 public function propelOnlyRun(callable $method, $arg)
 {
     if (Thelia::isInstalled()) {
         call_user_func($method, $arg);
     }
 }
Beispiel #7
0
/**
 * Generate Coupon fixtures
 */
function generateCouponFixtures(\Thelia\Core\Thelia $thelia)
{
    /** @var $container ContainerInterface Service Container */
    $container = $thelia->getContainer();
    /** @var FacadeInterface $adapter */
    $adapter = $container->get('thelia.facade');
    // Coupons
    $coupon1 = new Thelia\Model\Coupon();
    $coupon1->setCode('XMAS');
    $coupon1->setType('thelia.coupon.type.remove_x_amount');
    $coupon1->setTitle('Christmas coupon');
    $coupon1->setShortDescription('Coupon for Christmas removing 10€ if your total checkout is more than 40€');
    $coupon1->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla.

Donec rhoncus leo mauris, id porttitor ante luctus tempus. Curabitur quis augue feugiat, ullamcorper mauris ac, interdum mi. Quisque aliquam lorem vitae felis lobortis, id interdum turpis mattis. Vestibulum diam massa, ornare congue blandit quis, facilisis at nisl. In tortor metus, venenatis non arcu nec, sollicitudin ornare nisl. Nunc erat risus, varius nec urna at, iaculis lacinia elit. Aenean ut felis tempus, tincidunt odio non, sagittis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae hendrerit elit. Nunc sit amet gravida risus, euismod lobortis massa. Nam a erat mauris. Nam a malesuada lorem. Nulla id accumsan dolor, sed rhoncus tellus. Quisque dictum felis sed leo auctor, at volutpat lectus viverra. Morbi rutrum, est ac aliquam imperdiet, nibh sem sagittis justo, ac mattis magna lacus eu nulla.

Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse potenti. Sed eu purus tellus. Nunc quis rhoncus metus. Fusce vitae tellus enim. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam tempor porttitor erat vitae iaculis. Sed est elit, consequat non ornare vitae, vehicula eget lectus. Etiam consequat sapien mauris, eget consectetur magna imperdiet eget. Nunc sollicitudin luctus velit, in commodo nulla adipiscing fermentum. Fusce nisi sapien, posuere vitae metus sit amet, facilisis sollicitudin dui. Fusce ultricies auctor enim sit amet iaculis. Morbi at vestibulum enim, eget adipiscing eros.

Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.

Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
    $coupon1->setEffects(array(RemoveXAmount::AMOUNT_FIELD_NAME => 10.0));
    $coupon1->setIsUsed(true);
    $coupon1->setIsEnabled(true);
    $date = new \DateTime();
    $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months")));
    $condition1 = new MatchForTotalAmount($adapter);
    $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL);
    $values = array(MatchForTotalAmount::CART_TOTAL => 40.0, MatchForTotalAmount::CART_CURRENCY => 'EUR');
    $condition1->setValidatorsFromForm($operators, $values);
    $condition2 = new MatchForTotalAmount($adapter);
    $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL);
    $values = array(MatchForTotalAmount::CART_TOTAL => 400.0, MatchForTotalAmount::CART_CURRENCY => 'EUR');
    $condition2->setValidatorsFromForm($operators, $values);
    $conditions = new ConditionCollection();
    $conditions[] = $condition1;
    $conditions[] = $condition2;
    /** @var ConditionFactory $conditionFactory */
    $conditionFactory = $container->get('thelia.condition.factory');
    $serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
    $coupon1->setSerializedConditions($serializedConditions);
    $coupon1->setMaxUsage(40);
    $coupon1->setIsCumulative(true);
    $coupon1->setIsRemovingPostage(false);
    $coupon1->setIsAvailableOnSpecialOffers(true);
    $coupon1->setPerCustomerUsageCount(false);
    $coupon1->save();
    // Coupons
    $coupon2 = new Thelia\Model\Coupon();
    $coupon2->setCode('SPRINGBREAK');
    $coupon2->setType('thelia.coupon.type.remove_x_percent');
    $coupon2->setTitle('Springbreak coupon');
    $coupon2->setShortDescription('Coupon for Springbreak removing 10% if you have more than 4 articles in your cart');
    $coupon2->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla.

Donec rhoncus leo mauris, id porttitor ante luctus tempus. Curabitur quis augue feugiat, ullamcorper mauris ac, interdum mi. Quisque aliquam lorem vitae felis lobortis, id interdum turpis mattis. Vestibulum diam massa, ornare congue blandit quis, facilisis at nisl. In tortor metus, venenatis non arcu nec, sollicitudin ornare nisl. Nunc erat risus, varius nec urna at, iaculis lacinia elit. Aenean ut felis tempus, tincidunt odio non, sagittis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae hendrerit elit. Nunc sit amet gravida risus, euismod lobortis massa. Nam a erat mauris. Nam a malesuada lorem. Nulla id accumsan dolor, sed rhoncus tellus. Quisque dictum felis sed leo auctor, at volutpat lectus viverra. Morbi rutrum, est ac aliquam imperdiet, nibh sem sagittis justo, ac mattis magna lacus eu nulla.

Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse potenti. Sed eu purus tellus. Nunc quis rhoncus metus. Fusce vitae tellus enim. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam tempor porttitor erat vitae iaculis. Sed est elit, consequat non ornare vitae, vehicula eget lectus. Etiam consequat sapien mauris, eget consectetur magna imperdiet eget. Nunc sollicitudin luctus velit, in commodo nulla adipiscing fermentum. Fusce nisi sapien, posuere vitae metus sit amet, facilisis sollicitudin dui. Fusce ultricies auctor enim sit amet iaculis. Morbi at vestibulum enim, eget adipiscing eros.

Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.

Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
    $coupon2->setEffects(array(RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.0));
    $coupon2->setIsUsed(true);
    $coupon2->setIsEnabled(true);
    $date = new \DateTime();
    $coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 1 months")));
    $condition1 = new MatchForXArticles($adapter);
    $operators = array(MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR);
    $values = array(MatchForXArticles::CART_QUANTITY => 4);
    $condition1->setValidatorsFromForm($operators, $values);
    $conditions = new ConditionCollection();
    $conditions[] = $condition1;
    /** @var ConditionFactory $conditionFactory */
    $conditionFactory = $container->get('thelia.condition.factory');
    $serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
    $coupon2->setSerializedConditions($serializedConditions);
    $coupon2->setMaxUsage(-1);
    $coupon2->setIsCumulative(false);
    $coupon2->setIsRemovingPostage(true);
    $coupon2->setIsAvailableOnSpecialOffers(true);
    $coupon2->setPerCustomerUsageCount(false);
    $coupon2->save();
    // Coupons
    $coupon3 = new Thelia\Model\Coupon();
    $coupon3->setCode('OLD');
    $coupon3->setType('thelia.coupon.type.remove_x_percent');
    $coupon3->setTitle('Old coupon');
    $coupon3->setShortDescription('Coupon for Springbreak removing 10% if you have more than 4 articles in your cart');
    $coupon3->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla.

Donec rhoncus leo mauris, id porttitor ante luctus tempus. Curabitur quis augue feugiat, ullamcorper mauris ac, interdum mi. Quisque aliquam lorem vitae felis lobortis, id interdum turpis mattis. Vestibulum diam massa, ornare congue blandit quis, facilisis at nisl. In tortor metus, venenatis non arcu nec, sollicitudin ornare nisl. Nunc erat risus, varius nec urna at, iaculis lacinia elit. Aenean ut felis tempus, tincidunt odio non, sagittis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae hendrerit elit. Nunc sit amet gravida risus, euismod lobortis massa. Nam a erat mauris. Nam a malesuada lorem. Nulla id accumsan dolor, sed rhoncus tellus. Quisque dictum felis sed leo auctor, at volutpat lectus viverra. Morbi rutrum, est ac aliquam imperdiet, nibh sem sagittis justo, ac mattis magna lacus eu nulla.

Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse potenti. Sed eu purus tellus. Nunc quis rhoncus metus. Fusce vitae tellus enim. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam tempor porttitor erat vitae iaculis. Sed est elit, consequat non ornare vitae, vehicula eget lectus. Etiam consequat sapien mauris, eget consectetur magna imperdiet eget. Nunc sollicitudin luctus velit, in commodo nulla adipiscing fermentum. Fusce nisi sapien, posuere vitae metus sit amet, facilisis sollicitudin dui. Fusce ultricies auctor enim sit amet iaculis. Morbi at vestibulum enim, eget adipiscing eros.

Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.

Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
    $coupon3->setEffects(array(RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.0));
    $coupon3->setIsUsed(false);
    $coupon3->setIsEnabled(false);
    $date = new \DateTime();
    $coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
    $condition1 = new MatchForEveryone($adapter);
    $operators = array();
    $values = array();
    $condition1->setValidatorsFromForm($operators, $values);
    $conditions = new ConditionCollection();
    $conditions[] = $condition1;
    /** @var ConditionFactory $constraintCondition */
    $constraintCondition = $container->get('thelia.condition.factory');
    $serializedConditions = $constraintCondition->serializeConditionCollection($conditions);
    $coupon3->setSerializedConditions($serializedConditions);
    $coupon3->setMaxUsage(-1);
    $coupon3->setIsCumulative(true);
    $coupon3->setIsRemovingPostage(false);
    $coupon3->setIsAvailableOnSpecialOffers(false);
    $coupon3->setPerCustomerUsageCount(false);
    $coupon3->save();
}
Beispiel #8
0
<?php

use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Thelia;
use Thelia\Model\ConfigQuery;
$env = 'prod';
require __DIR__ . '/../../../../../../../../core/bootstrap.php';
$request = Request::createFromGlobals();
$thelia = new Thelia($env, false);
$thelia->boot();
$httpKernel = $thelia->getContainer()->get('http_kernel');
$httpKernel->getContainer()->enterScope('request');
$httpKernel->getContainer()->set('request', $request, 'request');
$httpKernel->initSession($request);
/** @var \Thelia\Core\Security\SecurityContext $securityContext */
$securityContext = $httpKernel->getContainer()->get('thelia.securityContext');
// We just check the current user has the ADMIN role.
$isGranted = $securityContext->isGranted(array('ADMIN'), array(), array(), array());
if (false === $isGranted) {
    echo "Sorry, it seems that you're not allowed to use this function. ADMIN role is required.";
    exit;
}
//------------------------------------------------------------------------------
// DO NOT COPY THESE VARIABLES IN FOLDERS config.php FILES
//------------------------------------------------------------------------------
//**********************
//Path configuration
//**********************
// In this configuration the media folder is located in the /web directory.
// base url of site (without final /). if you prefer relative urls leave empty.
$base_url = rtrim(ConfigQuery::getConfiguredShopUrl(), '/');
Beispiel #9
0
 public function testCreateClone()
 {
     $kernel = new Thelia('test', true);
     $kernel->boot();
     $originalProduct = ProductQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
     $newRef = uniqid('testClone-');
     $event = new ProductCloneEvent($newRef, 'fr_FR', $originalProduct);
     $event->setDispatcher($kernel->getContainer()->get('event_dispatcher'));
     $originalProductDefaultI18n = ProductI18nQuery::create()->findPk([$originalProduct->getId(), $event->getLang()]);
     $originalProductDefaultPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($originalProduct->getDefaultSaleElements()->getId());
     // Call function to test
     $action = new Product();
     $action->createClone($event, $originalProductDefaultI18n, $originalProductDefaultPrice);
     $cloneProduct = $event->getClonedProduct();
     // Check product information
     $this->assertInstanceOf('Thelia\\Model\\Product', $cloneProduct, 'Instance of clone product must be Thelia\\Model\\Product');
     $this->assertFalse($cloneProduct->isNew(), 'IsNew must be false');
     $this->assertEquals('fr_FR', $cloneProduct->getLocale(), 'Locale must be equal');
     $this->assertEquals($originalProductDefaultI18n->getTitle(), $cloneProduct->getTitle(), 'Title must be equal');
     $this->assertEquals($newRef, $cloneProduct->getRef(), 'Ref must be equal');
     $this->assertEquals(0, $cloneProduct->getVisible(), 'Visible must be false');
     $this->assertEquals($originalProduct->getDefaultCategoryId(), $cloneProduct->getDefaultCategoryId(), 'Default categories must be equal');
     $this->assertGreaterThan(0, $cloneProduct->getPosition(), 'Position must be greater than 0');
     $clonedProductSaleElements = $cloneProduct->getProductSaleElementss();
     $this->assertCount(1, $clonedProductSaleElements, 'There is not only one default PSE (maybe more, maybe none)');
     $clonedDefaultPSE = $clonedProductSaleElements->getFirst();
     $this->assertTrue($clonedDefaultPSE->getIsDefault(), 'IsDefault must be true for the default PSE');
     $this->assertEquals($cloneProduct->getRef(), $clonedDefaultPSE->getRef(), 'Clone product ref and clone PSE ref must be equal');
     $clonedProductPrice = $clonedDefaultPSE->getProductPrices()->getFirst();
     $this->assertEquals($originalProductDefaultPrice->getPrice(), $clonedProductPrice->getPrice(), 'Default price must be equal');
     $this->assertEquals($originalProductDefaultPrice->getCurrencyId(), $clonedProductPrice->getCurrencyId(), 'Currency IDs must be equal');
     return $event;
 }
Beispiel #10
0
if (file_exists(__DIR__ . '/../../../../../../../../core/vendor/autoload.php')) {
    // Symlinked with std install
    require_once __DIR__ . '/../../../../../../../../core/vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../../core/vendor/autoload.php')) {
    // Hard copy with std install
    require_once __DIR__ . '/../../../../core/vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../../../../../../bootstrap.php')) {
    // Symlinked with thelia-project
    require_once __DIR__ . '/../../../../../../../../bootstrap.php';
} elseif (file_exists(__DIR__ . '/../../../../bootstrap.php')) {
    // Hard copy with thelia-project
    require_once __DIR__ . '/../../../../bootstrap.php';
}
/** @var Request $request */
$request = Request::createFromGlobals();
$thelia = new Thelia($env, false);
$thelia->boot();
/** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */
$container = $thelia->getContainer();
$eventDispatcher = $container->get('event_dispatcher');
$container->get('thelia.translator');
$container->get('thelia.url.manager');
$container->enterScope('request');
$container->set('request', $request, 'request');
$event = new \Thelia\Core\Event\SessionEvent(THELIA_CACHE_DIR . $env, false, $env);
$eventDispatcher->dispatch(\Thelia\Core\TheliaKernelEvents::SESSION, $event);
$session = $event->getSession();
$session->start();
$request->setSession($session);
/** @var \Thelia\Core\Security\SecurityContext $securityContext */
$securityContext = $container->get('thelia.securityContext');
Beispiel #11
0
 /**
  * @covers \Thelia\Action\File::cloneFile
  * @depends testCloneAccessories
  * @param ProductCloneEvent $event
  * @return ProductCloneEvent
  */
 public function testCloneFile(ProductCloneEvent $event)
 {
     $kernel = new Thelia('test', true);
     $kernel->boot();
     $action = new File();
     $action->cloneFile($event, null, $kernel->getContainer()->get('event_dispatcher'));
     $originalProductId = $event->getOriginalProduct()->getId();
     $cloneProduct = $event->getClonedProduct();
     $originalProductFiles = [];
     // For each type, check files
     foreach ($event->getTypes() as $type) {
         switch ($type) {
             case 'images':
                 $originalProductFiles = ProductImageQuery::create()->findByProductId($originalProductId);
                 $cloneProductFiles = ProductImageQuery::create()->filterByProductId($cloneProduct->getId())->count();
                 $this->assertEquals(count($originalProductFiles), $cloneProductFiles, 'There must be the same quantity of images');
                 break;
             case 'documents':
                 $originalProductFiles = ProductDocumentQuery::create()->findByProductId($originalProductId);
                 $cloneProductFiles = ProductDocumentQuery::create()->filterByProductId($cloneProduct->getId())->count();
                 $this->assertEquals(count($originalProductFiles), $cloneProductFiles, 'There must be the same quantity of documents');
                 break;
         }
         // Check each file
         /** @var ProductDocument $originalProductFile */
         foreach ($originalProductFiles as $originalProductFile) {
             $srcPath = $originalProductFile->getUploadDir() . DS . $originalProductFile->getFile();
             // Check if original file exists
             $this->assertFileExists($srcPath, 'Original file doesn\'t exist');
             // Get original file mimeType
             $finfo = new \finfo();
             $fileMimeType = $finfo->file($srcPath, FILEINFO_MIME_TYPE);
             // Check files depending on the type
             switch ($type) {
                 case 'images':
                     // Get cloned ProductImage
                     $cloneProductFile = ProductImageQuery::create()->filterByProductId($cloneProduct->getId())->filterByVisible($originalProductFile->getVisible())->findOneByPosition($originalProductFile->getPosition());
                     // Check if the cloned file exists and ProductImage info
                     $this->assertFileExists($cloneProductFile->getUploadDir() . DS . $cloneProductFile->getFile(), 'Cloned image doesn\'t exist');
                     $this->assertEquals($fileMimeType, $finfo->file($cloneProductFile->getUploadDir() . DS . $cloneProductFile->getFile(), FILEINFO_MIME_TYPE), 'ProductImage\'s mime type must be equal');
                     $this->assertInstanceOf('Thelia\\Model\\ProductImage', $cloneProductFile, 'Instance of clone product image must be Thelia\\Model\\ProductImage');
                     $this->assertEquals($cloneProduct->getId(), $cloneProductFile->getProductId(), 'ProductImage\'s productID must be equal');
                     $this->assertEquals($originalProductFile->getVisible(), $cloneProductFile->getVisible(), 'ProductImage\'s visible must be equal');
                     $this->assertEquals($originalProductFile->getPosition(), $cloneProductFile->getPosition(), 'ProductImage\'s position must be equal');
                     break;
                 case 'documents':
                     // Get cloned ProductDocument
                     $cloneProductFile = ProductDocumentQuery::create()->filterByProductId($cloneProduct->getId())->filterByVisible($originalProductFile->getVisible())->findOneByPosition($originalProductFile->getPosition());
                     // Check if the cloned file exists and ProductDocument info
                     $this->assertFileExists($cloneProductFile->getUploadDir() . DS . $cloneProductFile->getFile(), 'Cloned document doesn\'t exist');
                     $this->assertEquals($fileMimeType, $finfo->file($cloneProductFile->getUploadDir() . DS . $cloneProductFile->getFile(), FILEINFO_MIME_TYPE), 'ProductDocument\'s mime type must be equal');
                     $this->assertInstanceOf('Thelia\\Model\\ProductDocument', $cloneProductFile, 'Instance of clone product document must be Thelia\\Model\\ProductDocument');
                     $this->assertEquals($cloneProduct->getId(), $cloneProductFile->getProductId(), 'ProductDocument\'s productID must be equal');
                     $this->assertEquals($originalProductFile->getVisible(), $cloneProductFile->getVisible(), 'ProductDocument\'s  visible must be equal');
                     $this->assertEquals($originalProductFile->getPosition(), $cloneProductFile->getPosition(), 'ProductDocument\'s  position must be equal');
                     break;
             }
         }
     }
     return $event;
 }