mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 01:20:59 +00:00
Fix ajax product search when too many products
This commit is contained in:
parent
ab6ee66241
commit
80221911d7
4 changed files with 240 additions and 0 deletions
|
|
@ -41,5 +41,6 @@ sylius_admin_ajax_product_index:
|
|||
_controller: sylius.controller.product:indexAction
|
||||
_format: json
|
||||
_sylius:
|
||||
serialization_groups: [Default]
|
||||
permission: true
|
||||
grid: sylius_admin_product
|
||||
|
|
|
|||
71
tests/Controller/AdminProductAjaxTest.php
Normal file
71
tests/Controller/AdminProductAjaxTest.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Tests\Controller;
|
||||
|
||||
use ApiTestCase\JsonApiTestCase;
|
||||
use Exception;
|
||||
use Symfony\Component\BrowserKit\Cookie;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
|
||||
class AdminProductAjaxTest extends JsonApiTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function it_denies_access_to_a_products_list_for_not_authenticated_user()
|
||||
{
|
||||
$this->client->request('GET', '/admin/ajax/products/');
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isRedirection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function it_allows_to_get_a_products_list()
|
||||
{
|
||||
$this->loadFixturesFromFile('authentication/administrator.yml');
|
||||
$this->loadFixturesFromFile('resources/products.yml');
|
||||
$this->loadFixturesFromFile('resources/many_products.yml');
|
||||
|
||||
$this->authenticateAdminUser();
|
||||
|
||||
$this->client->request('GET', '/admin/ajax/products/');
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponse($response, 'ajax/product/index_response', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function authenticateAdminUser(): void
|
||||
{
|
||||
$adminUserRepository = self::$container->get('sylius.repository.admin_user');
|
||||
$user = $adminUserRepository->findOneByEmail('admin@sylius.com');
|
||||
|
||||
$session = self::$container->get('session');
|
||||
$firewallName = 'admin';
|
||||
$firewallContext = 'admin';
|
||||
$token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles());
|
||||
$session->set(sprintf('_security_%s', $firewallContext), serialize($token));
|
||||
$session->save();
|
||||
|
||||
$cookie = new Cookie($session->getName(), $session->getId());
|
||||
$this->client->getCookieJar()->set($cookie);
|
||||
}
|
||||
}
|
||||
8
tests/DataFixtures/ORM/authentication/administrator.yml
Normal file
8
tests/DataFixtures/ORM/authentication/administrator.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Sylius\Component\Core\Model\AdminUser:
|
||||
admin:
|
||||
plainPassword: sylius
|
||||
roles: [ROLE_ADMINISTRATION_ACCESS]
|
||||
enabled: true
|
||||
email: admin@sylius.com
|
||||
username: sylius
|
||||
localeCode: en_US
|
||||
160
tests/Responses/ajax/product/index_response.json
Normal file
160
tests/Responses/ajax/product/index_response.json
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
{
|
||||
"page": 1,
|
||||
"limit": 10,
|
||||
"pages": 3,
|
||||
"total": 22,
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/admin\/ajax\/products\/?page=1&limit=10"
|
||||
},
|
||||
"first": {
|
||||
"href": "\/admin\/ajax\/products\/?page=1&limit=10"
|
||||
},
|
||||
"last": {
|
||||
"href": "\/admin\/ajax\/products\/?page=3&limit=10"
|
||||
},
|
||||
"next": {
|
||||
"href": "\/admin\/ajax\/products\/?page=2&limit=10"
|
||||
}
|
||||
},
|
||||
"_embedded": {
|
||||
"items": [
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Breaking bad mug",
|
||||
"code": "MUG_BB",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/MUG_BB"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Lotr mug",
|
||||
"code": "MUG_LOTR",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/MUG_LOTR"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Star Wars mug",
|
||||
"code": "MUG_SW",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [
|
||||
{
|
||||
"id": @integer@,
|
||||
"type": "thumbnail",
|
||||
"path": "\/uo\/product.jpg"
|
||||
}
|
||||
],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/MUG_SW"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Product 10",
|
||||
"code": "PRODUCT_10",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/PRODUCT_10"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Product 11",
|
||||
"code": "PRODUCT_11",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/PRODUCT_11"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Product 12",
|
||||
"code": "PRODUCT_12",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/PRODUCT_12"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Product 13",
|
||||
"code": "PRODUCT_13",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/PRODUCT_13"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Product 14",
|
||||
"code": "PRODUCT_14",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/PRODUCT_14"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Product 15",
|
||||
"code": "PRODUCT_15",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/PRODUCT_15"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"name": "Product 16",
|
||||
"code": "PRODUCT_16",
|
||||
"options": [],
|
||||
"averageRating": 0,
|
||||
"images": [],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/products\/PRODUCT_16"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue