-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctionalTest.php
More file actions
54 lines (41 loc) · 1.96 KB
/
Copy pathFunctionalTest.php
File metadata and controls
54 lines (41 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Tests\Functional;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Security\Core\User\InMemoryUser;
class FunctionalTest extends WebTestCase
{
public function testRenderMenuWithUserFoo(): void
{
$client = $this->createClient();
$this->loginUser($client, 'foo', 'bar', ['ROLE_FOO']);
$crawler = $client->request('GET', '/');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertCount(1, $crawler->filter('ul.menu-layer-1'));
$this->assertCount(2, $crawler->filter('ul.menu-layer-2'));
$this->assertCount(5, $crawler->filter('li.menu-item'));
$this->assertCount(1, $crawler->filter('li.bla-class'));
$this->assertCount(1, $crawler->filter('li.foo-child-class'));
$this->assertCount(2, $crawler->filter('a[href="/test_2"]'));
$this->assertCount(0, $crawler->filter('a[href="/test_1"]'));
}
public function testRenderMenuWithUserBar(): void
{
$client = $this->createClient();
$this->loginUser($client, 'bar', 'foo', ['ROLE_BAR']);
$crawler = $client->request('GET', '/');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertCount(1, $crawler->filter('ul.menu-layer-1'));
$this->assertCount(1, $crawler->filter('ul.menu-layer-2'));
$this->assertCount(3, $crawler->filter('li.menu-item'));
$this->assertCount(0, $crawler->filter('li.bla-class'));
$this->assertCount(0, $crawler->filter('li.foo-child-class'));
$this->assertCount(1, $crawler->filter('a[href="/test_2"]'));
$this->assertCount(2, $crawler->filter('a[href="/test_1"]'));
}
private function loginUser(KernelBrowser $client, string $username, string $password, array $roles): void
{
$user = new InMemoryUser($username, $password, $roles);
$client->loginUser($user);
}
}