-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #13611 Optimize variant autocomplete selector (rafal.swiercz…
…ek@drophub.pl) This PR was merged into the 1.11 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.11 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT Commits ------- 05531e8 Add product variant pagination 5c65af7 Remove pagination from product variant. Keep limit abff837 Fix findByPhrase method name f88b362 Fix functional test for partial product variants 83e6be1 Remove useless productId field d4cf31b Make limit optional 04e3ea9 Clean code 8e1a32e Add copyright b0cc5af Refactor product variant limit 25129d8 Adjust product variant test 4d51bbf Add void to test methods 1c7ac83 Make limit configurable from twig scope 17054db Improve product variants tests b1b8e45 Move product variants limit to parameter bag d475f45 Remove useless limit param
- Loading branch information
Showing
7 changed files
with
239 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?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 Symfony\Component\BrowserKit\Cookie; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
|
||
final class AdminProductVariantAjaxTest extends JsonApiTestCase | ||
{ | ||
/** @test */ | ||
public function it_denies_access_to_product_variants_for_not_authenticated_user(): void | ||
{ | ||
$this->client->request('GET', '/admin/ajax/product-variants/search-all'); | ||
|
||
$response = $this->client->getResponse(); | ||
|
||
$this->assertEquals($response->getStatusCode(), Response::HTTP_FOUND); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_only_specified_part_of_all_product_variants_for_empty_phrase(): void | ||
{ | ||
$this->loadFixturesFromFile('authentication/administrator.yml'); | ||
$this->loadFixturesFromFiles(['resources/product_variants.yml']); | ||
|
||
$this->authenticateAdminUser(); | ||
|
||
$this->client->request('GET', '/admin/ajax/product-variants/search-all?phrase='); | ||
|
||
$response = $this->client->getResponse(); | ||
|
||
$this->assertResponse($response, 'ajax/product_variant/index_response', Response::HTTP_OK); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_type_error_when_phrase_is_not_specified(): void | ||
{ | ||
$this->loadFixturesFromFile('authentication/administrator.yml'); | ||
$this->loadFixturesFromFiles(['resources/product_variants.yml']); | ||
|
||
$this->authenticateAdminUser(); | ||
|
||
$this->expectException(\TypeError::class); | ||
|
||
$this->client->request('GET', '/admin/ajax/product-variants/search-all'); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_specific_product_variants_for_given_phrase(): void | ||
{ | ||
$this->loadFixturesFromFile('authentication/administrator.yml'); | ||
$this->loadFixturesFromFiles(['resources/product_variants.yml']); | ||
|
||
$this->authenticateAdminUser(); | ||
|
||
$this->client->request('GET', '/admin/ajax/product-variants/search-all?phrase=LA'); | ||
|
||
$response = $this->client->getResponse(); | ||
|
||
$productVariants = json_decode($response->getContent()); | ||
|
||
$this->assertEquals('LARGE_MUG', $productVariants[0]->code); | ||
} | ||
|
||
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'; | ||
|
||
/** @deprecated parameter credential was deprecated in Symfony 5.4, so in Sylius 1.11 too, in Sylius 2.0 providing 4 arguments will be prohibited. */ | ||
if (3 === (new \ReflectionClass(UsernamePasswordToken::class))->getConstructor()->getNumberOfParameters()) { | ||
$token = new UsernamePasswordToken($user, $firewallName, $user->getRoles()); | ||
} else { | ||
$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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
tests/Responses/ajax/product_variant/index_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
[ | ||
{ | ||
"descriptor":"Mug 1 (MUG_1)", | ||
"id":@integer@, | ||
"code":"MUG_1" | ||
}, | ||
{ | ||
"descriptor":"Mug 2 (MUG_2)", | ||
"id":@integer@, | ||
"code":"MUG_2" | ||
}, | ||
{ | ||
"descriptor":"Mug 3 (MUG_3)", | ||
"id":@integer@, | ||
"code":"MUG_3" | ||
}, | ||
{ | ||
"descriptor":"Mug 4 (MUG_4)", | ||
"id":@integer@, | ||
"code":"MUG_4" | ||
}, | ||
{ | ||
"descriptor":"Mug 5 (MUG_5)", | ||
"id":@integer@, | ||
"code":"MUG_5" | ||
}, | ||
{ | ||
"descriptor":"Mug 6 (MUG_6)", | ||
"id":@integer@, | ||
"code":"MUG_6" | ||
}, | ||
{ | ||
"descriptor":"Mug 7 (MUG_7)", | ||
"id":@integer@, | ||
"code":"MUG_7" | ||
}, | ||
{ | ||
"descriptor":"Mug 8 (MUG_8)", | ||
"id":@integer@, | ||
"code":"MUG_8" | ||
}, | ||
{ | ||
"descriptor":"Mug 9 (MUG_9)", | ||
"id":@integer@, | ||
"code":"MUG_9" | ||
}, | ||
{ | ||
"descriptor":"Mug 10 (MUG_10)", | ||
"id":@integer@, | ||
"code":"MUG_10" | ||
}, | ||
{ | ||
"descriptor":"Mug 11 (MUG_11)", | ||
"id":@integer@, | ||
"code":"MUG_11" | ||
}, | ||
{ | ||
"descriptor":"Mug 12 (MUG_12)", | ||
"id":@integer@, | ||
"code":"MUG_12" | ||
}, | ||
{ | ||
"descriptor":"Mug 13 (MUG_13)", | ||
"id":@integer@, | ||
"code":"MUG_13" | ||
}, | ||
{ | ||
"descriptor":"Mug 14 (MUG_14)", | ||
"id":@integer@, | ||
"code":"MUG_14" | ||
}, | ||
{ | ||
"descriptor":"Mug 15 (MUG_15)", | ||
"id":@integer@, | ||
"code":"MUG_15" | ||
}, | ||
{ | ||
"descriptor":"Mug 16 (MUG_16)", | ||
"id":@integer@, | ||
"code":"MUG_16" | ||
}, | ||
{ | ||
"descriptor":"Mug 17 (MUG_17)", | ||
"id":@integer@, | ||
"code":"MUG_17" | ||
}, | ||
{ | ||
"descriptor":"Mug 18 (MUG_18)", | ||
"id":@integer@, | ||
"code":"MUG_18" | ||
}, | ||
{ | ||
"descriptor":"Mug 19 (MUG_19)", | ||
"id":@integer@, | ||
"code":"MUG_19" | ||
}, | ||
{ | ||
"descriptor":"Mug 20 (MUG_20)", | ||
"id":@integer@, | ||
"code":"MUG_20" | ||
}, | ||
{ | ||
"descriptor":"Large Mug (LARGE_MUG)", | ||
"id":@integer@, | ||
"code":"LARGE_MUG" | ||
}, | ||
{ | ||
"descriptor":"Mug 23 (MUG_23)", | ||
"id":@integer@, | ||
"code":"MUG_23" | ||
}, | ||
{ | ||
"descriptor":"Mug 24 (MUG_24)", | ||
"id":@integer@, | ||
"code":"MUG_24" | ||
}, | ||
{ | ||
"descriptor":"Mug 25 (MUG_25)", | ||
"id":@integer@, | ||
"code":"MUG_25" | ||
}, | ||
{ | ||
"descriptor":"Mug 26 (MUG_26)", | ||
"id":@integer@, | ||
"code":"MUG_26" | ||
} | ||
] |