Initial Commit

This commit is contained in:
2019-11-21 12:25:31 +01:00
commit f4aabcb9b1
13959 changed files with 787761 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?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\Tools;
use Thelia\Exception\FileNotFoundException;
use Thelia\Tools\FileDownload\FileDownloader;
/**
* Class FakeFileDownloader
* @package Thelia\Tests\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FakeFileDownloader extends FileDownloader
{
/**
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
* @throws \HttpUrlException
*
* Downloads the file $url in $pathToStore
*/
public function download($url, $pathToStore)
{
if (!file_exists($url) || !is_readable($url)) {
throw new FileNotFoundException();
}
if (!copy($url, $pathToStore)) {
throw new \ErrorException();
}
}
}

View File

@@ -0,0 +1,64 @@
<?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\Tools;
use Symfony\Component\DependencyInjection\Container;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
use Thelia\Tools\FileDownload\FileDownloader;
/**
* Class FileDownloaderTest
* @package Thelia\Tests\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FileDownloaderTest extends \PHPUnit_Framework_TestCase
{
/** @var FileDownloader */
protected $downloader;
public function setUp()
{
$logger = Tlog::getNewInstance();
$translator = new Translator(
new Container()
);
$this->downloader = new FileDownloader(
$logger,
$translator
);
}
/**
* @expectedException \Thelia\Exception\HttpUrlException
* @expectedExceptionMessage Tried to download a file, but the URL was not valid: foo
*/
public function testFileDownloadInvalidURL()
{
$this->downloader->download("foo", "bar");
}
/**
* @expectedException \Thelia\Exception\FileNotFoundException
*/
public function testFileDownloadNonExistingFile()
{
$this->downloader->download("https://github.com/foo/bar/baz", "baz");
}
public function testFileDownloadSuccess()
{
$this->downloader->download("http://thelia.net/", "php://temp");
}
}

View File

@@ -0,0 +1,39 @@
<?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\Tools;
use Thelia\Tools\Password;
/**
* Class PasswordTest
* @package Thelia\Tests\Type
* @author Manuel Raynaud <manu@raynaud.io>
*/
class PasswordTest extends \PHPUnit_Framework_TestCase
{
public function testGenerateRandom()
{
$length = 8;
$password = Password::generateRandom($length);
$this->assertEquals($length, strlen($password));
}
public function testGenerateHexaRandom()
{
$length = 8;
$password = Password::generateHexaRandom($length);
$this->assertEquals($length, strlen($password));
}
}

View File

@@ -0,0 +1,274 @@
<?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\Tools;
use Thelia\Tools\URL;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
* @author Franck Allimant <eroudeix@openstudio.fr>
*
*/
class URLTest extends \PHPUnit_Framework_TestCase
{
protected $context;
public function setUp()
{
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$router = $this->getMockBuilder("Symfony\Component\Routing\Router")
->disableOriginalConstructor()
->getMock();
$this->context = new \Symfony\Component\Routing\RequestContext(
'/thelia/index.php',
'GET',
'localhost',
'http',
80,
443,
'/path/to/action'
);
$router->expects($this->any())
->method('getContext')
->will($this->returnValue($this->context));
$container->set("router.admin", $router);
new URL($container);
}
public function testGetIndexPage()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->getIndexPage();
$this->assertEquals('http://localhost/thelia/index.php', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->getIndexPage();
$this->assertEquals('http://localhost/thelia/', $url);
$this->context->setBaseUrl('/thelia');
$url = URL::getInstance()->getIndexPage();
$this->assertEquals('http://localhost/thelia', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->getIndexPage();
$this->assertEquals('http://localhost/', $url);
}
public function testGetBaseUrl()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->getBaseUrl();
$this->assertEquals('http://localhost/thelia/index.php', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->getBaseUrl();
$this->assertEquals('http://localhost/thelia/', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->getBaseUrl();
$this->assertEquals('http://localhost/', $url);
}
public function testAbsoluteUrl()
{
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('/path/to/action');
$this->assertEquals('http://localhost/path/to/action', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('/path/to/action');
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
$this->context->setBaseUrl('/thelia');
$url = URL::getInstance()->absoluteUrl('/path/to/action');
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('/path/to/action');
$this->assertEquals('http://localhost/thelia/index.php/path/to/action', $url);
}
public function testAbsoluteUrlOnAbsolutePath()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
$this->assertEquals('http://myhost/path/to/action', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
$this->assertEquals('http://myhost/path/to/action', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
$this->assertEquals('http://myhost/path/to/action', $url);
}
public function testAbsoluteUrlOnAbsolutePathWithParameters()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
}
public function testAbsoluteUrlOnAbsolutePathWithParametersAddParameters()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
}
public function testAbsoluteUrlWithParameters()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/thelia/index.php/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia');
$url = URL::getInstance()->absoluteUrl('path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/path/to/action?p1=v1&p2=v2', $url);
}
public function testAbsoluteUrlPathOnly()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array(), URL::PATH_TO_FILE);
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
}
public function testAbsoluteUrlPathOnlyWithParameters()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
$this->assertEquals('http://localhost/path/to/action?p1=v1&p2=v2', $url);
}
public function testAbsoluteUrlFromIndexWithParameters()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/thelia/index.php/?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
$this->assertEquals('http://localhost/?p1=v1&p2=v2', $url);
}
public function testAbsoluteUrlPathOnlyFromIndexWithParameters()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/thelia/');
$url = URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
$this->context->setBaseUrl('/');
$url = URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
$this->assertEquals('http://localhost/?p1=v1&p2=v2', $url);
}
public function testAbsoluteUrlPathWithParameterReplacement()
{
$this->context->setBaseUrl('/thelia/index.php');
$url = URL::getInstance()->absoluteUrl(
'http://localhost/index_dev.php/admin/categories/update?category_id=1&current_tab=general&folder_id=0',
array("category_id" => "2", "edit_language_id" => "1", "current_tab" => "general"),
URL::PATH_TO_FILE
);
$this->assertEquals(
'http://localhost/index_dev.php/admin/categories/update?folder_id=0&category_id=2&edit_language_id=1&current_tab=general',
$url
);
$url = URL::getInstance()->absoluteUrl(
'http://localhost/index_dev.php/admin/categories/update?category_id=1&current_tab=general&folder_id=0',
array("edit_language_id" => "1"),
URL::PATH_TO_FILE
);
$this->assertEquals(
'http://localhost/index_dev.php/admin/categories/update?category_id=1&current_tab=general&folder_id=0&edit_language_id=1',
$url
);
$url = URL::getInstance()->absoluteUrl(
'http://localhost/index_dev.php/admin/categories/update?category_id=1&current_tab=general&folder_id=0',
array(),
URL::PATH_TO_FILE
);
$this->assertEquals(
'http://localhost/index_dev.php/admin/categories/update?category_id=1&current_tab=general&folder_id=0',
$url
);
$url = URL::getInstance()->absoluteUrl(
'http://localhost/index_dev.php/admin/categories/update?category_id=1',
array("category_id" => "2", "edit_language_id" => "1", "current_tab" => "general"),
URL::PATH_TO_FILE
);
$this->assertEquals(
'http://localhost/index_dev.php/admin/categories/update?category_id=2&edit_language_id=1&current_tab=general',
$url
);
}
public function testRetrieve()
{
}
}

View File

@@ -0,0 +1,163 @@
<?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\Tools\Version;
use Thelia\Tools\Version\Version as Tester;
/**
* Class Version
* @package Thelia\Tests\Tools\Version
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class Version extends \PHPUnit_Framework_TestCase
{
public function compareProvider()
{
return [
['2.1', '=2.1', true],
['2.1', '2.1', true],
['2.1', '>=2.1', true],
['2.1', '>2.1', false],
['2.1', '<=2.1', true],
['2.1', '<2.1', false],
['2.1', '~2.1', true],
['2.1.0', '=2.1', true],
['2.1.0', '=2.1.0', true],
['2.1.0', '=2.1', false, true],
['2.1.0', '=2.1.0', true, true],
['2.1.0', '>=2.1', true],
['2.1.0', '>2.1', false],
['2.1.0', '<=2.1', true],
['2.1.0', '<=2.1.0', true],
['2.1.0', '<2.1', false],
['2.1.0', '<2.1.0', false],
['2.1.0', '~2.1', true],
['2.1.1', '=2.1.0', false],
['2.1.1', '>=2.1', true],
['2.1.1', '>2.1', true],
['2.1.1', '<=2.1', false],
['2.1.1', '<2.1', false],
['2.1.1', '~2.1', true],
['2.1.0-alpha1', '>=2.1', true],
['2.1.0-alpha1', '>2.1', false],
['2.1.0-alpha1', '=2.1', true],
['2.1.0-alpha1', '~2.1', true],
['2.1.1-alpha1', '>=2.1', true],
['2.1.3', '=2.1.0 >2.1.2', false],
['2.1.3', '>=2.1 <2.2', true],
['2.1.3', '>2.1 <=2.1.3', true],
['2.1.3', '>2.1 <2.1.3', false],
['2.1.3', '~2.1 >2.1.0 <2.1.4', true],
['2.2', '=2.2', true],
['2.2', '2.2', true],
['2.2', '>=2.2', true],
['2.2', '>2.2', false],
['2.2', '<=2.2', true],
['2.2', '<2.2', false],
['2.2', '~2.2', true],
['2.2.0-alpha1', '>=2.2', true],
['2.2.0-alpha1', '>2.1', true],
['2.2.0-alpha1', '<2.1', false],
['2.2.0-alpha1', '=2.2', true],
['2.2.0-alpha1', '~2.2', true],
['2.2.0-alpha2', '>=2.2', true],
['2.2.0-alpha2', '>2.1', true],
['2.2.0-alpha2', '<2.1', false],
['2.2.0-alpha2', '=2.2', true],
['2.2.0-alpha2', '~2.2', true],
];
}
public function parseProvider()
{
return [
[ '2.1.0', [
'version' => '2.1.0',
'major' => '2',
'minus' => '1',
'release' => '0',
'extra' => '',
] ],
[ '2.5.0', [
'version' => '2.5.0',
'major' => '2',
'minus' => '5',
'release' => '0',
'extra' => '',
], ],
[ '2.3.0-alpha2', [
'version' => '2.3.0-alpha2',
'major' => '2',
'minus' => '3',
'release' => '0',
'extra' => 'alpha2',
], ],
];
}
public function exceptionParseProvider()
{
return [
['x.3.1', ],
['2.x.1', ],
['2.3.x', ],
['2.3.1-alpha.2', ],
['2.1', ],
['a.4', ],
['2.1.2.4', ],
['2.1.2.4.5', ],
['1.alpha.8', ],
['.1.2', ],
];
}
/**
* @dataProvider compareProvider
*/
public function testCompare($version, $expression, $result, $strict = false, $message = null)
{
if (null === $message) {
$message = sprintf(
"Version: %s, expression: %s, expected: %s",
$version,
$expression,
$result ? "true" : "false"
);
}
$this->assertSame($result, Tester::test($version, $expression, $strict), $message);
}
/**
* @dataProvider ParseProvider
*/
public function testParse($version, $expected)
{
$message = sprintf(
"=====\n\tVersion: %s\n\t expected: %s\n======\n",
var_export($version, true),
var_export($expected, true)
);
$this->assertEquals($expected, Tester::parse($version), $message);
}
/**
* @dataProvider exceptionParseProvider
* @expectedException InvalidArgumentException
*/
public function testExceptionParse($version)
{
Tester::parse($version);
}
}