1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenOrchestra\FunctionalTests\ApiBundle\Controller; |
4
|
|
|
|
5
|
|
|
use OpenOrchestra\FunctionalTests\Utils\AbstractAuthenticatedTest; |
6
|
|
|
use OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface; |
7
|
|
|
use OpenOrchestra\ModelInterface\Repository\StatusRepositoryInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ContentControllerTest |
11
|
|
|
*/ |
12
|
|
|
class ContentControllerTest extends AbstractAuthenticatedTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var StatusRepositoryInterface |
16
|
|
|
*/ |
17
|
|
|
protected $statusRepository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ContentRepositoryInterface |
21
|
|
|
*/ |
22
|
|
|
protected $contentRepository; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Set up the test |
26
|
|
|
*/ |
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
parent::setUp(); |
30
|
|
|
$this->contentRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.content'); |
31
|
|
|
$this->statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $name |
36
|
|
|
* |
37
|
|
|
* @dataProvider provideStatusName |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function testChangeContentStatus($name) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$content = $this->contentRepository->findOneByLanguageAndVersion('206_3_portes', 'fr', '2'); |
42
|
|
|
$newStatus = $this->statusRepository->findOneByName($name); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$content->setStatus($newStatus); |
45
|
|
|
$this->client->request( |
46
|
|
|
'PUT', |
47
|
|
|
'/api/content/update-status', |
48
|
|
|
array(), |
49
|
|
|
array(), |
50
|
|
|
array(), |
51
|
|
|
static::$kernel->getContainer()->get('jms_serializer')->serialize($content, 'json') |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
55
|
|
|
|
56
|
|
|
$newContent = $this->contentRepository->findOneByLanguageAndVersion('206_3_portes', 'fr', '2'); |
57
|
|
|
$this->assertSame($name, $newContent->getStatus()->getName()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function provideStatusName() |
64
|
|
|
{ |
65
|
|
|
return array( |
66
|
|
|
array('draft'), |
67
|
|
|
array('pending'), |
68
|
|
|
array('published'), |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.