Merge branches 'coupon' and 'master' of https://github.com/thelia/thelia into coupon

* 'coupon' of https://github.com/thelia/thelia:

# By Etienne Roudeix (17) and others
# Via Etienne Roudeix (9) and others
* 'master' of https://github.com/thelia/thelia: (52 commits)
  fix content faker
  fix typo and remove url generation in postInsert model
  add covers annotation in ProductRewriteTest
  create test for UrlRewritingTrait
  payment loop
  fix postage display
  postage + invoice step
  template is not mandatory in product table.
  refactor rewrriten method name
  Changed getDefaultCategory in getDefaultCategoryId
  remove old model classes:
  Working : Content : fix loop giving no elements
  Working : Content : fix loop giving no elements
  Added missing files...
  Started product management
  Working : Content : fix loop giving no elements
  Working : Product : fix loop giving no elements
  cart billing integration
  empty cart or delivery exception
  remove isntall routing and template
  ...
This commit is contained in:
gmorel
2013-09-17 22:55:29 +02:00
178 changed files with 20645 additions and 2315 deletions

View File

@@ -0,0 +1,248 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Action\DocumentTest;
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\DocumentEvent;
use Thelia\Model\ConfigQuery;
/**
* Class DocumentTest
*
* @package Thelia\Tests\Action\DocumentTest
*/
class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
protected $request;
protected $session;
public function getContainer()
{
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
$container->set("event_dispatcher", $dispatcher);
$request = new Request();
$request->setSession($this->session);
$container->set("request", $request);
return $container;
}
public function setUp()
{
$this->session = new Session(new MockArraySessionStorage());
$this->request = new Request();
$this->request->setSession($this->session);
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('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->getContainer());
$document->processDocument($event);
}
/**
*
* Try to process a non-existent file
*
* @expectedException \InvalidArgumentException
*/
public function testProcessNonExistentDocument()
{
$event = new DocumentEvent($this->request);
$document = new Document($this->getContainer());
$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->getContainer());
$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->getContainer());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_document_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->getContainer());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_document_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->getContainer());
$document->clearCache($event);
}
public function testClearWholeCache()
{
$event = new DocumentEvent($this->request);
$document = new Document($this->getContainer());
$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->getContainer());
$document->clearCache($event);
}
}

View File

@@ -0,0 +1 @@
This is a text document.

View File

@@ -0,0 +1 @@
This is a text document.

View File

@@ -0,0 +1,89 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Core\Template\Loop;
use Thelia\Model\DocumentQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Document;
use Thelia\Model\ProductDocumentQuery;
use Thelia\Model\CategoryDocumentQuery;
use Thelia\Model\ContentDocumentQuery;
use Thelia\Model\FolderDocumentQuery;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class DocumentTest extends BaseLoopTestor
{
public function getTestedClassName()
{
return 'Thelia\Core\Template\Loop\Document';
}
public function getTestedInstance()
{
return new Document($this->container);
}
public function getMandatoryArguments()
{
return array('source' => 'product', 'id' => 1);
}
public function testSearchByProductId()
{
$document = ProductDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId());
}
public function testSearchByFolderId()
{
$document = FolderDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId());
}
public function testSearchByContentId()
{
$document = ContentDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId());
}
public function testSearchByCategoryId()
{
$document = CategoryDocumentQuery::create()->findOne();
$this->baseTestSearchById($document->getId());
}
public function testSearchLimit()
{
$this->baseTestSearchWithLimit(1);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Core\Template\Loop;
use Thelia\Model\ImageQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Image;
use Thelia\Model\ProductImageQuery;
use Thelia\Model\CategoryImageQuery;
use Thelia\Model\ContentImageQuery;
use Thelia\Model\FolderImageQuery;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class ImageTest extends BaseLoopTestor
{
public function getTestedClassName()
{
return 'Thelia\Core\Template\Loop\Image';
}
public function getTestedInstance()
{
return new Image($this->container);
}
public function getMandatoryArguments()
{
return array('source' => 'product', 'id' => 1);
}
public function testSearchByProductId()
{
$image = ProductImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId());
}
public function testSearchByFolderId()
{
$image = FolderImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId());
}
public function testSearchByContentId()
{
$image = ContentImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId());
}
public function testSearchByCategoryId()
{
$image = CategoryImageQuery::create()->findOne();
$this->baseTestSearchById($image->getId());
}
public function testSearchLimit()
{
$this->baseTestSearchWithLimit(1);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\Product;
use Thelia\Model\ProductQuery;
/**
* Class ProductRewriteTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ProductRewriteTest extends \PHPUnit_Framework_TestCase
{
protected static $productId;
public static function setUpBeforeClass()
{
$product = new Product();
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
->setPosition(1)
->setVisible(1)
->setLocale('en_US')
->setTitle('My english super Title')
->setLocale('fr_FR')
->setTitle('Mon super titre en français')
->save();
self::$productId = $product->getId();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testFrenchRewrittenUrl()
{
$product = ProductQuery::create()->findPk(self::$productId);
$rewrittenUrl = $product->generateRewrittenUrl('fr_FR');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl);
//mon-super-titre-en-français-2.html
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testEnglishRewrittenUrl()
{
$product = ProductQuery::create()->findPk(self::$productId);
$rewrittenUrl = $product->generateRewrittenUrl('en_US');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
* @expectedException \RuntimeException
* @expectedExceptionMessage Object product must be saved before generating url
*/
public function testOnNotSavedProduct()
{
$product = new Product();
$product->generateRewrittenUrl('fr_FR');
}
}