|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Tests\Controller; |
|
15
|
|
|
|
|
16
|
|
|
use ApiTestCase\JsonApiTestCase; |
|
17
|
|
|
use Exception; |
|
18
|
|
|
use Symfony\Component\BrowserKit\Cookie; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
|
21
|
|
|
|
|
22
|
|
|
final class AdminProductAjaxTest extends JsonApiTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @test |
|
26
|
|
|
* |
|
27
|
|
|
* @throws Exception |
|
28
|
|
|
*/ |
|
29
|
|
|
public function it_denies_access_to_a_products_list_for_not_authenticated_user() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->client->request('GET', '/admin/ajax/products/'); |
|
32
|
|
|
|
|
33
|
|
|
$response = $this->client->getResponse(); |
|
34
|
|
|
$this->assertTrue($response->isRedirection()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @test |
|
39
|
|
|
* |
|
40
|
|
|
* @throws Exception |
|
41
|
|
|
*/ |
|
42
|
|
|
public function it_allows_to_get_a_products_list() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->loadFixturesFromFile('authentication/administrator.yml'); |
|
45
|
|
|
$this->loadFixturesFromFiles([ |
|
46
|
|
|
'resources/product_association_types.yml', |
|
47
|
|
|
'resources/products.yml', |
|
48
|
|
|
'resources/many_products.yml', |
|
49
|
|
|
'resources/product_associations.yml', |
|
50
|
|
|
]); |
|
51
|
|
|
|
|
52
|
|
|
$this->authenticateAdminUser(); |
|
53
|
|
|
|
|
54
|
|
|
$this->client->request('GET', '/admin/ajax/products/'); |
|
55
|
|
|
|
|
56
|
|
|
$response = $this->client->getResponse(); |
|
57
|
|
|
$this->assertResponse($response, 'ajax/product/index_response', Response::HTTP_OK); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function authenticateAdminUser(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$adminUserRepository = self::$container->get('sylius.repository.admin_user'); |
|
63
|
|
|
$user = $adminUserRepository->findOneByEmail('[email protected]'); |
|
64
|
|
|
|
|
65
|
|
|
$session = self::$container->get('session'); |
|
66
|
|
|
$firewallName = 'admin'; |
|
67
|
|
|
$firewallContext = 'admin'; |
|
68
|
|
|
$token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles()); |
|
69
|
|
|
$session->set(sprintf('_security_%s', $firewallContext), serialize($token)); |
|
70
|
|
|
$session->save(); |
|
71
|
|
|
|
|
72
|
|
|
$cookie = new Cookie($session->getName(), $session->getId()); |
|
73
|
|
|
$this->client->getCookieJar()->set($cookie); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|