1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overwatch\ResultBundle\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use Overwatch\ResultBundle\DataFixtures\ORM\TestResultFixtures; |
6
|
|
|
use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures; |
7
|
|
|
use Overwatch\TestBundle\DataFixtures\ORM\TestGroupFixtures; |
8
|
|
|
use Overwatch\UserBundle\Tests\Base\DatabaseAwareTestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* ApiControllerTest |
12
|
|
|
* Functional test of API methods provided by the APIController |
13
|
|
|
*/ |
14
|
|
|
class ApiControllerTest extends DatabaseAwareTestCase |
15
|
|
|
{ |
16
|
|
View Code Duplication |
public function testGetResults() |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$this->logIn('ROLE_SUPER_ADMIN'); |
19
|
|
|
$this->client->request('GET', '/api/results'); |
20
|
|
|
|
21
|
|
|
$this->assertJsonResponse($this->client->getResponse()); |
22
|
|
|
$this->assertCount(4, $this->getResponseContent()); |
23
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-1'], $this->getResponseContent()); |
24
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-2'], $this->getResponseContent()); |
25
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $this->getResponseContent()); |
26
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-4'], $this->getResponseContent()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetResultsInsufficentPerms() |
30
|
|
|
{ |
31
|
|
|
$this->logIn('ROLE_ADMIN'); |
32
|
|
|
$this->client->request('GET', '/api/results'); |
33
|
|
|
|
34
|
|
|
$this->assertForbidden($this->client->getResponse()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetRecentGroupResults() |
38
|
|
|
{ |
39
|
|
|
$this->logIn('ROLE_SUPER_ADMIN'); |
40
|
|
|
$this->client->request('GET', '/api/results/group/' . TestGroupFixtures::$groups['group-1']->getId()); |
41
|
|
|
|
42
|
|
|
$this->assertJsonResponse($this->client->getResponse()); |
43
|
|
|
$this->assertCount(2, $this->getResponseContent()); |
44
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $this->getResponseContent()); |
45
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-4'], $this->getResponseContent()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function testGetRecentGroupResultsInsufficentPerms() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$this->logIn('ROLE_ADMIN'); |
51
|
|
|
$this->client->request('GET', '/api/results/group/' . TestGroupFixtures::$groups['group-1']->getId()); |
52
|
|
|
|
53
|
|
|
$this->assertForbidden($this->client->getResponse()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function testGetResultsForTest() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$this->logIn('ROLE_SUPER_ADMIN'); |
59
|
|
|
$this->client->request('GET', '/api/results/test/' . TestFixtures::$tests['test-1']->getId()); |
60
|
|
|
|
61
|
|
|
$this->assertJsonResponse($this->client->getResponse()); |
62
|
|
|
$this->assertCount(3, $this->getResponseContent()); |
63
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-1'], $this->getResponseContent()); |
64
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-2'], $this->getResponseContent()); |
65
|
|
|
$this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $this->getResponseContent()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
public function testGetResultsForTestInsufficentPerms() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$this->logIn('ROLE_ADMIN'); |
71
|
|
|
$this->client->request('GET', '/api/results/test/' . TestFixtures::$tests['test-1']->getId()); |
72
|
|
|
|
73
|
|
|
$this->assertForbidden($this->client->getResponse()); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.