Initial commit
This commit is contained in:
42
tests/phpunit/Thelia/Tests/Api/ApiSendJsonTest.php
Normal file
42
tests/phpunit/Thelia/Tests/Api/ApiSendJsonTest.php
Normal 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\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ApiSendJsonTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ApiSendJsonTest extends ApiTestCase
|
||||
{
|
||||
public function testSendNotValidJson()
|
||||
{
|
||||
$data = "this is not a valid json";
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products?sign='.$this->getSignParameter($data),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$data
|
||||
);
|
||||
|
||||
$this->assertEquals(400, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
104
tests/phpunit/Thelia/Tests/Api/AttributeAvControllerTest.php
Normal file
104
tests/phpunit/Thelia/Tests/Api/AttributeAvControllerTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class AttributeAvControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class AttributeAvControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$attributeAvCount = AttributeAvQuery::create()->count();
|
||||
if ($attributeAvCount > 10) {
|
||||
$attributeAvCount = 10;
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($attributeAvCount, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testListWithTranslation()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$attributeAvCount = AttributeAvQuery::create()->count();
|
||||
if ($attributeAvCount > 10) {
|
||||
$attributeAvCount = 10;
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($attributeAvCount, $content, "10 results must be return by default");
|
||||
|
||||
$firstResult = $content[0];
|
||||
$this->assertEquals(1, $firstResult['IS_TRANSLATED'], 'content must be translated');
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testGetActionWithWrongId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
}
|
||||
}
|
||||
159
tests/phpunit/Thelia/Tests/Api/BrandControllerTest.php
Normal file
159
tests/phpunit/Thelia/Tests/Api/BrandControllerTest.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?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\Api;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Brand;
|
||||
use Thelia\Model\BrandQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class BrandControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class BrandControllerTest extends ApiTestCase
|
||||
{
|
||||
protected $created = false;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!$this->created) {
|
||||
if (BrandQuery::create()->count() === 0) {
|
||||
$brand = new Brand();
|
||||
|
||||
$brand
|
||||
->getTranslation()
|
||||
->setTitle("Foo")
|
||||
->setChapo("Bar")
|
||||
->setDescription("Baz")
|
||||
;
|
||||
|
||||
$brand
|
||||
->getTranslation("fr_FR")
|
||||
->setTitle("orange")
|
||||
->setChapo("banana")
|
||||
->setDescription("apple")
|
||||
;
|
||||
|
||||
$brand->save();
|
||||
}
|
||||
|
||||
$this->created = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$brand = $this->getBrand();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands/'.$brand->getId().'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$brand = $this->getBrand("fr_FR");
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands/'.$brand->getId().'?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
protected function getBrand($locale = 'en_US')
|
||||
{
|
||||
$brand = BrandQuery::create()
|
||||
->joinBrandI18n("brand_i18n_join", Criteria::INNER_JOIN)
|
||||
->addJoinCondition('brand_i18n_join', "locale = ?", $locale, null, \PDO::PARAM_STR)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $brand) {
|
||||
$this->markTestSkipped(
|
||||
sprintf(
|
||||
"You must have at least one brand with an i18n that has the '%s' locale",
|
||||
$locale
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $brand;
|
||||
}
|
||||
}
|
||||
243
tests/phpunit/Thelia/Tests/Api/CategoryControllerTest.php
Normal file
243
tests/phpunit/Thelia/Tests/Api/CategoryControllerTest.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?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\Api;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Category;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CategoryControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CategoryControllerTest extends ApiTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (CategoryQuery::create()->count() === 0) {
|
||||
$category = new Category();
|
||||
|
||||
$category->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testListWithTranslation()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content, "10 results must be return by default");
|
||||
|
||||
$firstResult = $content[0];
|
||||
$this->assertEquals(1, $firstResult['IS_TRANSLATED'], 'content must be translated');
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$category = $this->getCategory();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories/'.$category->getId().'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testGetActionWithWrongId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$category = [
|
||||
'title' => 'test en',
|
||||
'locale' => 'en_US',
|
||||
'visible' => 0,
|
||||
'parent' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($category);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/categories?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('en_US', $content[0]['LOCALE']);
|
||||
$this->assertEquals(0, $content[0]['VISIBLE']);
|
||||
}
|
||||
|
||||
public function testCreateFr()
|
||||
{
|
||||
$category = [
|
||||
'title' => 'test fr',
|
||||
'locale' => 'fr_FR',
|
||||
'visible' => 1,
|
||||
'parent' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($category);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/categories?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('fr_FR', $content[0]['LOCALE']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->orderById(Criteria::DESC)
|
||||
->findOne();
|
||||
|
||||
$content = [
|
||||
'id' => $category->getId(),
|
||||
'title' => 'foo',
|
||||
'parent' => 0,
|
||||
'locale' => 'en_US',
|
||||
'visible' => 1,
|
||||
'chapo' => 'category chapo',
|
||||
'description' => 'category description',
|
||||
'postscriptum' => 'category postscriptum'
|
||||
];
|
||||
$requestContent = json_encode($content);
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/categories?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'HTTP status code must be 204');
|
||||
|
||||
$results = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertEquals(1, $results[0]["VISIBLE"]);
|
||||
}
|
||||
|
||||
public function testDeleteAction()
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->orderById(Criteria::DESC)
|
||||
->findOne();
|
||||
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/categories/'.$category->getId().'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'HTTP status code muse be 204');
|
||||
}
|
||||
|
||||
protected function getCategory($locale = 'en_US')
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->joinCategoryI18n("category_i18n_join", Criteria::INNER_JOIN)
|
||||
->addJoinCondition('category_i18n_join', "locale = ?", $locale, null, \PDO::PARAM_STR)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $category) {
|
||||
$this->markTestSkipped(
|
||||
sprintf(
|
||||
"You must have at least one category with an i18n that has the '%s' locale",
|
||||
$locale
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/CountryControllerTest.php
Normal file
103
tests/phpunit/Thelia/Tests/Api/CountryControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CountryControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class CountryControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/CurrencyControllerTest.php
Normal file
103
tests/phpunit/Thelia/Tests/Api/CurrencyControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CurrencyControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class CurrencyControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
390
tests/phpunit/Thelia/Tests/Api/CustomerControllerTest.php
Normal file
390
tests/phpunit/Thelia/Tests/Api/CustomerControllerTest.php
Normal file
@@ -0,0 +1,390 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CustomerControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
* @author Baptiste Cabarrou <bcabarrou@openstudio.fr>
|
||||
*/
|
||||
class CustomerControllerTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::listAction
|
||||
*/
|
||||
public function testListActionWithDefaultParameters()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content);
|
||||
|
||||
$this->customerKeyTest($content[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::listAction
|
||||
*/
|
||||
public function testListActionWithOrderError()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers?order=foo&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode(), 'Http status code must be 500');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::listAction
|
||||
*/
|
||||
public function testListActionWithLimit()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers?limit=1&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content);
|
||||
|
||||
$this->customerKeyTest($content[0]);
|
||||
}
|
||||
|
||||
protected function customerKeyTest($customer)
|
||||
{
|
||||
$this->assertArrayHasKey('ID', $customer, 'customer entity must contains Id key');
|
||||
$this->assertArrayHasKey('REF', $customer, 'customer entity must contains Ref key');
|
||||
$this->assertArrayHasKey('TITLE', $customer, 'customer entity must contains TitleId key');
|
||||
$this->assertArrayHasKey('FIRSTNAME', $customer, 'customer entity must contains Firstname key');
|
||||
$this->assertArrayHasKey('LASTNAME', $customer, 'customer entity must contains Lastname key');
|
||||
$this->assertArrayHasKey('EMAIL', $customer, 'customer entity must contains Email key');
|
||||
$this->assertArrayHasKey('RESELLER', $customer, 'customer entity must contains Reseller key');
|
||||
$this->assertArrayHasKey('SPONSOR', $customer, 'customer entity must contains Sponsor key');
|
||||
$this->assertArrayHasKey('DISCOUNT', $customer, 'customer entity must contains Discount key');
|
||||
$this->assertArrayHasKey('CREATE_DATE', $customer, 'customer entity must contains CreatedAt key');
|
||||
$this->assertArrayHasKey('UPDATE_DATE', $customer, 'customer entity must contains UpdatedAt key');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::getAction
|
||||
*/
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers/1?&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content);
|
||||
|
||||
$this->customerKeyTest($content[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::getAction
|
||||
*/
|
||||
public function testGetActionWithUnexistingCustomer()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers/'.PHP_INT_MAX.'?&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$user = [
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => sprintf("%s@thelia.fr", uniqid()),
|
||||
'password' => 'azerty',
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode());
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
return $content[0]['ID'];
|
||||
}
|
||||
|
||||
public function testCreateWithExistingEmail()
|
||||
{
|
||||
$customer = CustomerQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
|
||||
|
||||
$user = [
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => $customer->getEmail(),
|
||||
'password' => 'azerty',
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*/
|
||||
public function testDelete($customerId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/customers/'.$customerId.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), "the response code must be 204");
|
||||
}
|
||||
|
||||
public function testDeleteWithExistingOrders()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/customers/1?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(403, $client->getResponse()->getStatusCode(), "the response code must be 403 because the customer already have orders");
|
||||
}
|
||||
|
||||
public function testUpdateCustomer()
|
||||
{
|
||||
$user = [
|
||||
'id' => 1,
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => sprintf("%s@thelia.fr", uniqid()),
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testUpdateCustomerWithUnexistingCustomer()
|
||||
{
|
||||
$user = [
|
||||
'id' => PHP_INT_MAX,
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => sprintf("%s@thelia.fr", uniqid()),
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::checkLoginAction
|
||||
*/
|
||||
public function testCheckLogin()
|
||||
{
|
||||
$logins = [
|
||||
'email' => CustomerQuery::create()->findPk(1)->getEmail(),
|
||||
'password' => 'azerty'
|
||||
];
|
||||
|
||||
$requestContent = json_encode($logins);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers/checkLogin?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::checkLoginAction
|
||||
*/
|
||||
public function testCheckLoginWithUnexistingEmail()
|
||||
{
|
||||
$logins = [
|
||||
'email' => 'test@exemple.com',
|
||||
'password' => 'azerty'
|
||||
];
|
||||
|
||||
$requestContent = json_encode($logins);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers/checkLogin?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::checkLoginAction
|
||||
*/
|
||||
public function testCheckLoginWithWrongPassword()
|
||||
{
|
||||
$logins = [
|
||||
'email' => CustomerQuery::create()->findPk(1)->getEmail(),
|
||||
'password' => 'notthis'
|
||||
];
|
||||
|
||||
$requestContent = json_encode($logins);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers/checkLogin?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
36
tests/phpunit/Thelia/Tests/Api/IndexControllerTest.php
Normal file
36
tests/phpunit/Thelia/Tests/Api/IndexControllerTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class IndexControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class IndexControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testIndexAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request(
|
||||
'GET',
|
||||
'/api'
|
||||
);
|
||||
$response = $client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('OK', $response->getContent());
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/LangControllerTest.php
Normal file
103
tests/phpunit/Thelia/Tests/Api/LangControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class LangControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class LangControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
276
tests/phpunit/Thelia/Tests/Api/ProductControllerTest.php
Normal file
276
tests/phpunit/Thelia/Tests/Api/ProductControllerTest.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ProductControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ProductControllerTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListActionWithLimit()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products?limit=2&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(2, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/1?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
|
||||
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||
$taxRule = TaxRuleQuery::create()->findOneByIsDefault(1);
|
||||
$product = [
|
||||
'ref' => uniqid('testCreateProduct'),
|
||||
'locale' => 'en_US',
|
||||
'title' => 'product create from api',
|
||||
'description' => 'product description from api',
|
||||
'default_category' => $category->getId(),
|
||||
'visible' => 1,
|
||||
'price' => '10',
|
||||
'currency' => $defaultCurrency->getId(),
|
||||
'tax_rule' => $taxRule->getId(),
|
||||
'weight' => 10,
|
||||
'brand_id' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($product);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('en_US', $content[0]['LOCALE']);
|
||||
|
||||
return $content['0']['ID'];
|
||||
}
|
||||
|
||||
public function testCreateWithOptionalParametersAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
|
||||
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||
$taxRule = TaxRuleQuery::create()->findOneByIsDefault(1);
|
||||
$templateId = $category->getDefaultTemplateId();
|
||||
|
||||
if (null === $templateId) {
|
||||
$templateId = TemplateQuery::create()->addAscendingOrderByColumn('RAND()')->findOne()->getId();
|
||||
}
|
||||
|
||||
$product = [
|
||||
'ref' => uniqid('testCreateProduct'),
|
||||
'locale' => 'en_US',
|
||||
'title' => 'product create from api',
|
||||
'description' => 'product description from api',
|
||||
'default_category' => $category->getId(),
|
||||
'visible' => 1,
|
||||
'price' => '10',
|
||||
'currency' => $defaultCurrency->getId(),
|
||||
'tax_rule' => $taxRule->getId(),
|
||||
'weight' => 10,
|
||||
'brand_id' => 0,
|
||||
'quantity' => 10,
|
||||
'template_id' => $templateId
|
||||
];
|
||||
|
||||
$requestContent = json_encode($product);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('en_US', $content[0]['LOCALE']);
|
||||
|
||||
$this->assertEquals(10, $content[0]['QUANTITY']);
|
||||
$this->assertEquals($templateId, $content[0]['TEMPLATE']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productId
|
||||
* @depends testCreateAction
|
||||
*/
|
||||
public function testUpdateAction($productId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = ProductQuery::create()->findPk($productId);
|
||||
|
||||
$productData = [
|
||||
'ref' => $product->getRef(),
|
||||
'locale' => 'en_US',
|
||||
'title' => 'product updated from api',
|
||||
'default_category' => $product->getDefaultCategoryId(),
|
||||
'visible' => 1,
|
||||
'description' => 'product description updated from api',
|
||||
'chapo' => 'product chapo updated from api',
|
||||
'postscriptum' => 'product postscriptum',
|
||||
'brand_id' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($productData);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/'.$productId.'?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
|
||||
return $productId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productId
|
||||
* @depends testUpdateAction
|
||||
*/
|
||||
public function testDeleteAction($productId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/products/'.$productId.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
}
|
||||
|
||||
public function testDeleteActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/products/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
}
|
||||
318
tests/phpunit/Thelia/Tests/Api/ProductImageControllerTest.php
Normal file
318
tests/phpunit/Thelia/Tests/Api/ProductImageControllerTest.php
Normal file
@@ -0,0 +1,318 @@
|
||||
<?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\Api;
|
||||
|
||||
use Propel\Runtime\Exception\UnexpectedValueException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ProductImageControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductImageControllerTest extends ApiTestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fs->copy(
|
||||
__DIR__ . '/fixtures/base.png',
|
||||
__DIR__ . '/fixtures/visuel.png'
|
||||
);
|
||||
|
||||
$fs->copy(
|
||||
__DIR__ . '/fixtures/base.png',
|
||||
__DIR__ . '/fixtures/visuel2.png'
|
||||
);
|
||||
|
||||
$fs->copy(
|
||||
__DIR__ . '/fixtures/base.png',
|
||||
__DIR__ . '/fixtures/visuel3.png'
|
||||
);
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/1/images?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertGreaterThan(0, count($content), 'must contain at least 1 image');
|
||||
}
|
||||
|
||||
public function testListActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/'.PHP_INT_MAX.'/images?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = ProductQuery::create()->joinProductImage()->findOne();
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("This test can't be run as there is no product that has an image");
|
||||
}
|
||||
|
||||
$productImage = $product->getProductImages()->get(0);
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/'.$product->getId().'/images/'.$productImage->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'image get action must retrieve 1 image');
|
||||
}
|
||||
|
||||
public function testGetActionWithNonExistingImage()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/1/images/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreateImageAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$image = new UploadedFile(
|
||||
__DIR__ . '/fixtures/visuel.png',
|
||||
'visuel.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
$image2 = new UploadedFile(
|
||||
__DIR__ . '/fixtures/visuel2.png',
|
||||
'visuel2.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products/1/images?&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[
|
||||
'image1' => $image,
|
||||
'image2' => $image2
|
||||
],
|
||||
$servers
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$last = array_pop($content);
|
||||
|
||||
return $last['ID'];
|
||||
}
|
||||
|
||||
public function testCreateImageActionWithWrongMimeType()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$image = new UploadedFile(
|
||||
__DIR__ . '/fixtures/fail.pdf',
|
||||
'fail.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products/1/images?&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[
|
||||
'image1' => $image
|
||||
],
|
||||
$servers
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode(), 'Http status code must be 500');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testCreateImageAction
|
||||
*/
|
||||
public function testUpdateImageAction($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$image = new UploadedFile(
|
||||
__DIR__ . '/fixtures/visuel3.png',
|
||||
'visuel3.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.$imageId.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[
|
||||
'image1' => $image
|
||||
],
|
||||
$servers
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
return $imageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testCreateImageAction
|
||||
*/
|
||||
public function testUpdateImageDataAction($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"title" => "My Image",
|
||||
"chapo" => "My Super Image"
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"title" => "Mon image",
|
||||
"chapo" => "Ma super image"
|
||||
]
|
||||
)
|
||||
];
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$content = json_encode($data);
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.$imageId.'?lang=en_US&no-cache=yes&sign='.$this->getSignParameter($content),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$content
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals("My Image", $content[0]["TITLE"]);
|
||||
$this->assertEquals("My Super Image", $content[0]["CHAPO"]);
|
||||
|
||||
return $imageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testCreateImageAction
|
||||
*/
|
||||
public function testUpdateFailsOnPutNothing($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.$imageId.'?no-cache=yes&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode(), 'Http status code must be 500');
|
||||
|
||||
return $imageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testUpdateImageAction
|
||||
*/
|
||||
public function testDeleteImageAction($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/products/1/images/'.$imageId.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
}
|
||||
|
||||
public function testUpdateImageFailWithBadId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.PHP_INT_MAX.'?no-cache=yes&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,472 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Map\AttributeAvTableMap;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ProductSaleElementsControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductSaleElementsControllerTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/product/'.$product->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$productPse = $product->getProductSaleElementss()->count();
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(
|
||||
$productPse > 10 ? 10 : $productPse,
|
||||
$content,
|
||||
'without parameters, the api must return 10 results, or the number of PSE of the product'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListActionWithLimit()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$product = $this->getProduct();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/product/'.$product->getId().'?limit=1&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'with the limit parameter at 1, the api must return 1 result');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$pse = ProductSaleElementsQuery::create()->findOne();
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped(
|
||||
sprintf("You can't run this test without any product sale elements")
|
||||
);
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/'.$pse->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = $this->getProduct();
|
||||
$currency = $this->getCurrency();
|
||||
$taxRule = $this->getTaxRule();
|
||||
|
||||
$attributeAvs = AttributeAvQuery::create()
|
||||
->limit(2)
|
||||
->select(AttributeAvTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$data = [
|
||||
"pse" => [
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "3.99",
|
||||
"reference" => "foo",
|
||||
"attribute_av" => $attributeAvs,
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/pse?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
201,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
)
|
||||
);
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
// Find the item we've juste created in the result list
|
||||
$pse = null;
|
||||
|
||||
if (count($content) > 1) {
|
||||
foreach ($content as $item) {
|
||||
if ($item['REF'] == 'foo') {
|
||||
$pse = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif (count($content) == 1) {
|
||||
$pse = $content[0];
|
||||
}
|
||||
|
||||
$this->assertNotNull($pse);
|
||||
|
||||
$this->assertEquals('3.99', $pse['PRICE']);
|
||||
|
||||
return $content['0']['ID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pseId
|
||||
* @depends testCreateAction
|
||||
*/
|
||||
public function testUpdateAction($pseId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$pseData = [
|
||||
"pse" => [
|
||||
[
|
||||
"id" => $pseId,
|
||||
"price" => "3.33",
|
||||
"sale_price" => "2.11",
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($pseData);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/pse/'.$pseId.'?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('3.33', $data["0"]["PRICE"]);
|
||||
$this->assertEquals('2.11', $data["0"]["PROMO_PRICE"]);
|
||||
$this->assertEquals('foo', $data["0"]["REF"]);
|
||||
|
||||
return $pseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pseId
|
||||
* @depends testUpdateAction
|
||||
*/
|
||||
public function testDeleteAction($pseId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$pse = ProductSaleElementsQuery::create()->findPk($pseId);
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped(
|
||||
sprintf("You can't run this test without any product sale elements")
|
||||
);
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/pse/'.$pse->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
}
|
||||
|
||||
public function testCreateMultiplePSEInOneShot()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = $this->getProduct();
|
||||
$currency = $this->getCurrency();
|
||||
$taxRule = $this->getTaxRule();
|
||||
|
||||
$attributeAvs = AttributeAvQuery::create()
|
||||
->limit(2)
|
||||
->select(AttributeAvTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray();
|
||||
|
||||
$data = [
|
||||
"pse" => [
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "3.12",
|
||||
"reference" => "foo",
|
||||
"quantity" => 1,
|
||||
"attribute_av" => $attributeAvs,
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
],
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "3.33",
|
||||
"reference" => "bar",
|
||||
"quantity" => 10,
|
||||
"attribute_av" => [$attributeAvs[0]],
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
],
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "12.09",
|
||||
"reference" => "baz",
|
||||
"quantity" => 100,
|
||||
"attribute_av" => [$attributeAvs[1]],
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/pse?order=quantity&sign=' . $this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
201,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
)
|
||||
);
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(3, $content);
|
||||
$this->assertEquals('3.12', $content[0]['PRICE']);
|
||||
$this->assertEquals('3.33', $content[1]['PRICE']);
|
||||
$this->assertEquals('12.09', $content[2]['PRICE']);
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach ($content as $entry) {
|
||||
$ids[] = $entry["ID"];
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
* @depends testCreateMultiplePSEInOneShot
|
||||
*/
|
||||
public function testUpdateMultiplePSEInOneShot($ids)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"pse" => [
|
||||
[
|
||||
"id" => $ids[0],
|
||||
"price" => "3.50",
|
||||
],
|
||||
[
|
||||
"id" => $ids[1],
|
||||
"price" => "2.54",
|
||||
],
|
||||
[
|
||||
"id" => $ids[2],
|
||||
"price" => "9.60",
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/pse?order=quantity&sign=' . $this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
201,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
)
|
||||
);
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(3, $content);
|
||||
$this->assertEquals('3.50', $content[0]['PRICE']);
|
||||
$this->assertEquals('2.54', $content[1]['PRICE']);
|
||||
$this->assertEquals('9.60', $content[2]['PRICE']);
|
||||
}
|
||||
|
||||
public function testDeleteActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/pse/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
/**
|
||||
* Not tests
|
||||
*/
|
||||
|
||||
protected function getProduct()
|
||||
{
|
||||
$product = ProductQuery::create()->findOne();
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("You must have at least one product to run this test");
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
protected function getTaxRule()
|
||||
{
|
||||
$product = TaxRuleQuery::create()->findOne();
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("You must have at least one tax rule to run this test");
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
protected function getCurrency()
|
||||
{
|
||||
$product = CurrencyQuery::create()->findOneByCode("EUR");
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("You must have at least one currency to run this test");
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/TaxControllerTest.php
Normal file
103
tests/phpunit/Thelia/Tests/Api/TaxControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class TaxControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class TaxControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
307
tests/phpunit/Thelia/Tests/Api/TaxRuleControllerTest.php
Normal file
307
tests/phpunit/Thelia/Tests/Api/TaxRuleControllerTest.php
Normal file
@@ -0,0 +1,307 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\Map\CountryTableMap;
|
||||
use Thelia\Model\Map\TaxTableMap;
|
||||
use Thelia\Model\TaxQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class TaxRuleControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class TaxRuleControllerTest extends ApiTestCase
|
||||
{
|
||||
protected static $defaultId;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$taxRule = TaxRuleQuery::create()
|
||||
->filterByIsDefault(1)
|
||||
->findOne();
|
||||
|
||||
self::$defaultId = $taxRule->getId();
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testCreateTaxRule()
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$taxes = TaxQuery::create()
|
||||
->limit(2)
|
||||
->select(TaxTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$countries = CountryQuery::create()
|
||||
->limit(2)
|
||||
->select(CountryTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$data = [
|
||||
"country" => $countries,
|
||||
"tax" => $taxes,
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"title" => "Test tax rule",
|
||||
"description" => "foo",
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"title" => "Test règle de taxe",
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/tax-rules?lang=en_US&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
$content = json_decode($response->getContent(), true)[0];
|
||||
|
||||
$this->assertEquals("Test tax rule", $content["TITLE"]);
|
||||
$this->assertEquals(0, $content["IS_DEFAULT"]);
|
||||
|
||||
return $content["ID"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $taxRuleId
|
||||
* @depends testCreateTaxRule
|
||||
*/
|
||||
public function testUpdateTaxRule($taxRuleId)
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$data = [
|
||||
"id" => $taxRuleId,
|
||||
"default" => true,
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"description" => "bar",
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"description" => "baz",
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/tax-rules?lang=fr_FR&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
$content = json_decode($response->getContent(), true)[0];
|
||||
|
||||
$this->assertEquals("Test règle de taxe", $content["TITLE"]);
|
||||
$this->assertEquals("baz", $content["DESCRIPTION"]);
|
||||
$this->assertEquals(1, $content["IS_DEFAULT"]);
|
||||
|
||||
return $content["ID"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $taxRuleId
|
||||
* @depends testCreateTaxRule
|
||||
*/
|
||||
public function testDeleteTaxRule($taxRuleId)
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/tax-rules/'.$taxRuleId.'?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$servers
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testCreateTaxRuleWithInvalidData()
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$countries = CountryQuery::create()
|
||||
->limit(2)
|
||||
->select(CountryTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$data = [
|
||||
"country" => $countries,
|
||||
"tax" => array(),
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"title" => "Test tax rule",
|
||||
"description" => "foo",
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"title" => "Test règle de taxe",
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/tax-rules?lang=en_US&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(500, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
TaxRuleQuery::create()
|
||||
->filterById(self::$defaultId)
|
||||
->update(array('IsDefault' => true));
|
||||
}
|
||||
}
|
||||
374
tests/phpunit/Thelia/Tests/Api/TitleControllerTest.php
Normal file
374
tests/phpunit/Thelia/Tests/Api/TitleControllerTest.php
Normal file
@@ -0,0 +1,374 @@
|
||||
<?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\Api;
|
||||
|
||||
use Thelia\Model\CustomerTitleQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class TitleControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class TitleControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$maxCount = CustomerTitleQuery::create()->count();
|
||||
|
||||
if ($maxCount > 10) {
|
||||
$maxCount = 10;
|
||||
}
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($maxCount, $content, sprintf('reponse must contains %d results', $maxCount));
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$maxCount = CustomerTitleQuery::create()->count();
|
||||
|
||||
if ($maxCount > 10) {
|
||||
$maxCount = 10;
|
||||
}
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($maxCount, $content, sprintf('reponse must contains %d results', $maxCount));
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'response must contains only 1 result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'response must contains only 1 result');
|
||||
$firstResult = $content[0];
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetActionWithUnexistingId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"short" => "Mr"
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"short" => "M.",
|
||||
"long" => "Monsieur"
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/title?lang=en_US&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
|
||||
$content = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals('Mr', $content[0]['SHORT']);
|
||||
$this->assertEquals('', $content[0]['LONG']);
|
||||
|
||||
return $content[0]['ID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $titleId
|
||||
* @depends testCreateAction
|
||||
*/
|
||||
public function testUpdateAction($titleId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"long" => "Mister"
|
||||
],
|
||||
],
|
||||
"default" => true,
|
||||
"title_id" => $titleId,
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/title?lang=en_US&no-cache=yes&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
|
||||
$content = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals('Mr', $content[0]['SHORT']);
|
||||
$this->assertEquals('Mister', $content[0]['LONG']);
|
||||
$this->assertEquals(1, $content[0]['DEFAULT']);
|
||||
|
||||
return $titleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $titleId
|
||||
* @depends testUpdateAction
|
||||
*/
|
||||
public function testUpdateActionWithFormError($titleId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"short" => "This sentence is really too long for a short"
|
||||
],
|
||||
],
|
||||
"default" => true,
|
||||
"title_id" => $titleId,
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/title?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(500, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 500. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
|
||||
return $titleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $titleId
|
||||
* @depends testUpdateActionWithFormError
|
||||
*/
|
||||
public function testDeleteAction($titleId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/title/'.$titleId.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testCreateActionWithNotCompleteForm()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"short" => "Mr"
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"short" => "Mr",
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/title?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(500, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 500. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
}
|
||||
|
||||
public function testUpdateActionWithNotExistingTitleId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"long" => "Mister"
|
||||
],
|
||||
],
|
||||
"default" => true,
|
||||
"title_id" => PHP_INT_MAX,
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/title?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(404, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 404. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
}
|
||||
|
||||
public function testDeleteActionWithNotExistingTitleId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/title/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
BIN
tests/phpunit/Thelia/Tests/Api/fixtures/base.png
Normal file
BIN
tests/phpunit/Thelia/Tests/Api/fixtures/base.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
BIN
tests/phpunit/Thelia/Tests/Api/fixtures/fail.pdf
Normal file
BIN
tests/phpunit/Thelia/Tests/Api/fixtures/fail.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user