コード例 #1
0
ファイル: WebTestCase.php プロジェクト: NandoKstroNet/thelia
 /**
  * @param  array                                $options
  * @param  array                                $server
  * @return \Symfony\Component\HttpKernel\Client
  */
 protected static function createClient(array $options = [], array $server = [])
 {
     if (null !== static::$kernel) {
         static::$kernel->shutdown();
     }
     static::$kernel = new Thelia('test', true);
     static::$kernel->boot();
     $client = static::$kernel->getContainer()->get('test.client');
     $client->setServerParameters($server);
     return $client;
 }
コード例 #2
0
 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();
 }
コード例 #3
0
 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());
     }
 }
コード例 #4
0
ファイル: config.php プロジェクト: alex63530/thelia
<?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(), '/');
コード例 #5
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;
 }
コード例 #6
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;
 }