Initial commit
This commit is contained in:
40
tests/phpunit/Thelia/Tests/Module/BaseModuleTestor.php
Normal file
40
tests/phpunit/Thelia/Tests/Module/BaseModuleTestor.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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\Module;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class BaseModuleTestor extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $instance;
|
||||
|
||||
abstract public function getTestedClassName();
|
||||
abstract public function getTestedInstance();
|
||||
|
||||
/*protected function getMethod($name)
|
||||
{
|
||||
$class = new \ReflectionClass($this->getTestedClassName());
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method;
|
||||
}*/
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->instance = $this->getTestedInstance();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
|
||||
<fullnamespace>AuthorTest\AuthorTest</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Automatically generated module - please update module.xml file</title>
|
||||
<!--
|
||||
<subtitle></subtitle>
|
||||
<description></description>
|
||||
<postscriptum></postscriptum>
|
||||
-->
|
||||
</descriptive>
|
||||
<descriptive locale="fr_FR">
|
||||
<title>test authors</title>
|
||||
</descriptive>
|
||||
<!-- <logo></logo> -->
|
||||
<!--<images-folder>images</images-folder>-->
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
<language>fr_FR</language>
|
||||
</languages>
|
||||
<version>0.1</version>
|
||||
<authors>
|
||||
<author>
|
||||
<name>foo</name>
|
||||
<email>bar</email>
|
||||
</author>
|
||||
<author>
|
||||
<name>baz</name>
|
||||
<email>bad</email>
|
||||
</author>
|
||||
</authors>
|
||||
<type>classic</type>
|
||||
<!--
|
||||
module dependencies
|
||||
<required>
|
||||
<module version=">=0.1">Front</module>
|
||||
<module version="~1.0">HookCart</module>
|
||||
<module version=">0.2">HookSearch</module>
|
||||
</required>
|
||||
-->
|
||||
<thelia>2.2.0</thelia>
|
||||
<stability>other</stability>
|
||||
</module>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
|
||||
<fullnamespace>AuthorTest\AuthorTest</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Automatically generated module - please update module.xml file</title>
|
||||
<!--
|
||||
<subtitle></subtitle>
|
||||
<description></description>
|
||||
<postscriptum></postscriptum>
|
||||
-->
|
||||
</descriptive>
|
||||
<descriptive locale="fr_FR">
|
||||
<title>test authors</title>
|
||||
</descriptive>
|
||||
<!-- <logo></logo> -->
|
||||
<!--<images-folder>images</images-folder>-->
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
<language>fr_FR</language>
|
||||
</languages>
|
||||
<version>0.1</version>
|
||||
<authors>
|
||||
<author>
|
||||
<name>foo</name>
|
||||
<email>bar</email>
|
||||
</author>
|
||||
</authors>
|
||||
<type>classic</type>
|
||||
<!--
|
||||
module dependencies
|
||||
<required>
|
||||
<module version=">=0.1">Front</module>
|
||||
<module version="~1.0">HookCart</module>
|
||||
<module version=">0.2">HookSearch</module>
|
||||
</required>
|
||||
-->
|
||||
<thelia>2.2.0</thelia>
|
||||
<stability>other</stability>
|
||||
</module>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
|
||||
<fullnamespace>AuthorTest\AuthorTest</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Automatically generated module - please update module.xml file</title>
|
||||
<!--
|
||||
<subtitle></subtitle>
|
||||
<description></description>
|
||||
<postscriptum></postscriptum>
|
||||
-->
|
||||
</descriptive>
|
||||
<descriptive locale="fr_FR">
|
||||
<title>test authors</title>
|
||||
</descriptive>
|
||||
<!-- <logo></logo> -->
|
||||
<!--<images-folder>images</images-folder>-->
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
<language>fr_FR</language>
|
||||
</languages>
|
||||
<version>0.1</version>
|
||||
<author>
|
||||
<name>foo</name>
|
||||
<email>bar</email>
|
||||
</author>
|
||||
<type>classic</type>
|
||||
<!--
|
||||
module dependencies
|
||||
<required>
|
||||
<module version=">=0.1">Front</module>
|
||||
<module version="~1.0">HookCart</module>
|
||||
<module version=">0.2">HookSearch</module>
|
||||
</required>
|
||||
-->
|
||||
<thelia>2.1.0</thelia>
|
||||
<stability>other</stability>
|
||||
</module>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
|
||||
<fullnamespace>Module1\Module1</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Module test 1</title>
|
||||
</descriptive>
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
</languages>
|
||||
<version>0.1</version>
|
||||
<author>
|
||||
<name>Julien Chanséaume</name>
|
||||
<email>jchanseaume@openstudio.fr</email>
|
||||
</author>
|
||||
<type>classic</type>
|
||||
<thelia>2.5.0</thelia>
|
||||
<stability>other</stability>
|
||||
</module>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
|
||||
<fullnamespace>Module2\Module2</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Module test 2</title>
|
||||
</descriptive>
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
</languages>
|
||||
<version>0.1</version>
|
||||
<author>
|
||||
<name>Julien Chanséaume</name>
|
||||
<email>jchanseaume@openstudio.fr</email>
|
||||
</author>
|
||||
<type>classic</type>
|
||||
<required>
|
||||
<module version=">=2.2.3">Front</module>
|
||||
<module version=">=2.1.0">HookCart</module>
|
||||
<module version=">=2.5.0">HookSearch</module>
|
||||
</required>
|
||||
<thelia>2.1.0</thelia>
|
||||
<stability>other</stability>
|
||||
</module>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
|
||||
<fullnamespace>Module4\Module4</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Module test 4</title>
|
||||
</descriptive>
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
</languages>
|
||||
<version>0.1</version>
|
||||
<author>
|
||||
<name>Julien Chanséaume</name>
|
||||
<email>jchanseaume@openstudio.fr</email>
|
||||
</author>
|
||||
<type>classic</type>
|
||||
<thelia>2.1.0</thelia>
|
||||
<stability>other</stability>
|
||||
</module>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
|
||||
<fullnamespace>Module5\Module5</fullnamespace>
|
||||
</module>
|
||||
@@ -0,0 +1,204 @@
|
||||
<?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\Module\Validator;
|
||||
|
||||
use Thelia\Core\Thelia;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Module\Validator\ModuleValidator;
|
||||
use Thelia\Tools\Version\Version;
|
||||
|
||||
/**
|
||||
* Class ModuleValidator
|
||||
* @package Thelia\Tests\Module\Validator
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class ModuleValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Thelia\Exception\ModuleException
|
||||
*/
|
||||
public function testCheque()
|
||||
{
|
||||
$moduleChequePath = THELIA_MODULE_DIR . "Cheque";
|
||||
|
||||
$moduleValidator = new ModuleValidator($moduleChequePath, $this->getStubTranslator());
|
||||
|
||||
$moduleDescriptor = $moduleValidator->getModuleDescriptor();
|
||||
|
||||
$this->assertInstanceOf('SimpleXMLElement', $moduleDescriptor);
|
||||
$this->assertEquals("2", $moduleValidator->getModuleVersion());
|
||||
|
||||
$moduleDefinition = $moduleValidator->getModuleDefinition();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Module\Validator\ModuleDefinition', $moduleDefinition);
|
||||
|
||||
$this->assertEquals("Cheque", $moduleDefinition->getCode());
|
||||
$this->assertEquals("Cheque\\Cheque", $moduleDefinition->getNamespace());
|
||||
|
||||
// validate
|
||||
$moduleValidator->validate();
|
||||
}
|
||||
|
||||
public function testVirtualProductDelivery()
|
||||
{
|
||||
$modulePath = THELIA_MODULE_DIR . "VirtualProductDelivery";
|
||||
|
||||
$moduleValidator = new ModuleValidator($modulePath, $this->getStubTranslator());
|
||||
|
||||
$moduleDescriptor = $moduleValidator->getModuleDescriptor();
|
||||
|
||||
$this->assertInstanceOf('SimpleXMLElement', $moduleDescriptor);
|
||||
$this->assertEquals("2", $moduleValidator->getModuleVersion());
|
||||
|
||||
$moduleDefinition = $moduleValidator->getModuleDefinition();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Module\Validator\ModuleDefinition', $moduleDefinition);
|
||||
|
||||
$this->assertEquals("VirtualProductDelivery", $moduleDefinition->getCode());
|
||||
$this->assertEquals("VirtualProductDelivery\\VirtualProductDelivery", $moduleDefinition->getNamespace());
|
||||
$this->assertEquals(2, count($moduleDefinition->getLanguages()));
|
||||
$this->assertEquals(0, count($moduleDefinition->getDependencies()));
|
||||
$this->assertEquals(1, count($moduleDefinition->getAuthors()));
|
||||
$this->assertEquals("", $moduleDefinition->getDocumentation());
|
||||
$this->assertEquals("", $moduleDefinition->getLogo());
|
||||
$this->assertEquals("2.4.3", $moduleDefinition->getTheliaVersion());
|
||||
$this->assertTrue(
|
||||
Version::test(
|
||||
Thelia::THELIA_VERSION,
|
||||
$moduleDefinition->getTheliaVersion(),
|
||||
false,
|
||||
">="
|
||||
)
|
||||
);
|
||||
|
||||
// validate
|
||||
$moduleValidator->validate(false);
|
||||
}
|
||||
|
||||
public function authorsProvider()
|
||||
{
|
||||
return [
|
||||
['Module1', 2],
|
||||
['Module2', 1],
|
||||
['Module3', 1]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider authorsProvider
|
||||
* @param $path
|
||||
* @param $expectedAuthors
|
||||
*/
|
||||
public function testAuthorsTag($path, $expectedAuthors)
|
||||
{
|
||||
$modulePath = __DIR__ . "/Authors/" . $path;
|
||||
|
||||
$moduleValidator = new ModuleValidator($modulePath, $this->getStubTranslator());
|
||||
$moduleDefinition = $moduleValidator->getModuleDefinition();
|
||||
|
||||
$this->assertEquals($expectedAuthors, count($moduleDefinition->getAuthors()), sprintf("%d author(s) was expected for module %s", $expectedAuthors, $path));
|
||||
}
|
||||
|
||||
public function validatorProvider()
|
||||
{
|
||||
return [
|
||||
['Module1', '\Thelia\Exception\ModuleException', 'The module Module1 requires Thelia'],
|
||||
['Module2', '\Thelia\Exception\ModuleException', 'To activate module Module2, the following modules should be activated first'],
|
||||
['Module3', '\Thelia\Exception\FileNotFoundException', 'Module Module3 should have a module.xml in the Config directory'],
|
||||
['Module4', '\Thelia\Exception\FileNotFoundException', 'Module Module4 should have a config.xml in the Config directory'],
|
||||
['Module5', '\Thelia\Module\Exception\InvalidXmlDocumentException', null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validatorProvider
|
||||
* @param $path
|
||||
* @param $exceptionExpected
|
||||
* @param $exceptionMessage
|
||||
*/
|
||||
public function testValidator($path, $exceptionExpected, $exceptionMessage)
|
||||
{
|
||||
$modulePath = __DIR__ . "/" . $path;
|
||||
/** @var \Exception $exception */
|
||||
$exception = null;
|
||||
|
||||
try {
|
||||
$moduleValidator = new ModuleValidator($modulePath, $this->getStubTranslator("opiopi"));
|
||||
|
||||
$moduleValidator->validate(true);
|
||||
} catch (\Exception $ex) {
|
||||
$exception = $ex;
|
||||
}
|
||||
|
||||
if (null !== $exceptionExpected) {
|
||||
$this->assertInstanceOf(
|
||||
$exceptionExpected,
|
||||
$exception,
|
||||
$path . " module should return exception " . $exceptionExpected
|
||||
);
|
||||
|
||||
if (null !== $exceptionMessage) {
|
||||
$this->assertNotEmpty(
|
||||
$exception->getMessage(),
|
||||
$path . " module exception should not be empty"
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
false !== strpos($exception->getMessage(), $exceptionMessage),
|
||||
$path . " module exception should contain : " . $exceptionMessage
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->assertNull(
|
||||
$exception,
|
||||
$path . " module should not return exception [" . $exception->getMessage() . ']'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Exception\FileNotFoundException
|
||||
*/
|
||||
public function testNonExistentModule()
|
||||
{
|
||||
$moduleChuckNorrisPath = THELIA_MODULE_DIR . "ChuckNorris";
|
||||
|
||||
new ModuleValidator($moduleChuckNorrisPath, $this->getStubTranslator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Translator
|
||||
*/
|
||||
private function getStubTranslator()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function ($l, $p) {
|
||||
foreach ($p as $pk => $pv) {
|
||||
$l = str_replace($pk, $pv, $l);
|
||||
}
|
||||
return $l;
|
||||
}
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
return $stubTranslator;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user