1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenOrchestra\FunctionalTests\BackofficeBundle\Controller; |
4
|
|
|
|
5
|
|
|
use OpenOrchestra\FunctionalTests\Utils\AbstractFormTest; |
6
|
|
|
use OpenOrchestra\ModelInterface\Model\NodeInterface; |
7
|
|
|
use OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface; |
8
|
|
|
use OpenOrchestra\ModelInterface\Repository\SiteRepositoryInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class SiteControllerTest |
12
|
|
|
* |
13
|
|
|
* @group backofficeTest |
14
|
|
|
*/ |
15
|
|
|
class SiteControllerTest extends AbstractFormTest |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var NodeRepositoryInterface |
19
|
|
|
*/ |
20
|
|
|
protected $nodeRepository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var SiteRepositoryInterface |
24
|
|
|
*/ |
25
|
|
|
protected $siteRepository; |
26
|
|
|
|
27
|
|
|
protected $siteId; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Set up the test |
31
|
|
|
*/ |
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
parent::setUp(); |
35
|
|
|
|
36
|
|
|
$this->siteId = uniqid(); |
37
|
|
|
$this->nodeRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.node'); |
38
|
|
|
$this->siteRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.site'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Test when you create a site and update it |
43
|
|
|
*/ |
44
|
|
|
public function testCreateSite() |
45
|
|
|
{ |
46
|
|
|
$this->assertNodeCount(0, 'fr'); |
47
|
|
|
$this->assertNodeCount(0, 'en'); |
48
|
|
|
|
49
|
|
|
$this->createSite(); |
50
|
|
|
|
51
|
|
|
$this->assertNodeCount(1, 'fr'); |
52
|
|
|
$this->assertNodeCount(0, 'en'); |
53
|
|
|
|
54
|
|
|
$crawler = $this->client->request('GET', '/admin/site/form/' . $this->siteId); |
55
|
|
|
$form = $crawler->selectButton('Save')->form(); |
56
|
|
|
|
57
|
|
|
$values = $form->getPhpValues(); |
58
|
|
|
|
59
|
|
|
$values['oo_site']['aliases'][1]['domain'] = $this->siteId . 'name'; |
60
|
|
|
$values['oo_site']['aliases'][1]['language'] = 'en'; |
61
|
|
|
$values['oo_site']['aliases'][1]['main'] = false; |
62
|
|
|
|
63
|
|
|
$this->client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles()); |
64
|
|
|
|
65
|
|
|
$this->assertNodeCount(1, 'fr'); |
66
|
|
|
$this->assertNodeCount(1, 'en'); |
67
|
|
|
|
68
|
|
|
$this->client->request('DELETE', '/api/site/' . $this->siteId . '/delete'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test create 2 site with the same siteId only one is save |
73
|
|
|
*/ |
74
|
|
|
public function testUniqueSiteId() |
75
|
|
|
{ |
76
|
|
|
$this->assertSiteCount(0, $this->siteId); |
77
|
|
|
|
78
|
|
|
$this->createSite(); |
79
|
|
|
|
80
|
|
|
$this->assertSiteCount(1, $this->siteId); |
81
|
|
|
|
82
|
|
|
$this->createSite(); |
83
|
|
|
|
84
|
|
|
$this->assertSiteCount(1, $this->siteId); |
85
|
|
|
|
86
|
|
|
$this->client->request('DELETE', '/api/site/' . $this->siteId . '/delete'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Create a site |
91
|
|
|
*/ |
92
|
|
|
protected function createSite() |
93
|
|
|
{ |
94
|
|
|
$crawler = $this->client->request('GET', '/admin/site/new'); |
95
|
|
|
|
96
|
|
|
$form = $crawler->selectButton('Save')->form(); |
97
|
|
|
|
98
|
|
|
$form['oo_site[siteId]'] = $this->siteId; |
99
|
|
|
$form['oo_site[name]'] = $this->siteId . 'domain'; |
100
|
|
|
$form['oo_site[metaAuthor]'] = $this->siteId . ' Author'; |
101
|
|
|
|
102
|
|
|
$values = $form->getPhpValues(); |
|
|
|
|
103
|
|
|
|
104
|
|
|
$values['oo_site']['aliases'][0]['domain'] = $this->siteId . 'name'; |
105
|
|
|
$values['oo_site']['aliases'][0]['language'] = 'fr'; |
106
|
|
|
$values['oo_site']['aliases'][0]['main'] = true; |
107
|
|
|
|
108
|
|
|
$this->client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles()); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param int $count |
113
|
|
|
* @param string $language |
114
|
|
|
*/ |
115
|
|
|
protected function assertNodeCount($count, $language) |
116
|
|
|
{ |
117
|
|
|
$nodes = $this->nodeRepository->findNotDeletedSortByUpdatedAt(NodeInterface::ROOT_NODE_ID, $language, $this->siteId); |
118
|
|
|
|
119
|
|
|
$this->assertCount($count, $nodes); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param int $count |
124
|
|
|
* @param string $siteId |
125
|
|
|
*/ |
126
|
|
|
protected function assertSiteCount($count, $siteId) |
127
|
|
|
{ |
128
|
|
|
$sites = $this->siteRepository->findBy(array('siteId' => $siteId)); |
|
|
|
|
129
|
|
|
|
130
|
|
|
$this->assertCount($count, $sites); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.