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 = (string) microtime(true); |
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->markTestSkipped(); |
47
|
|
|
|
48
|
|
|
$this->assertNodeCount(0, 'fr'); |
49
|
|
|
$this->assertNodeCount(0, 'en'); |
50
|
|
|
|
51
|
|
|
$this->createSite(); |
52
|
|
|
|
53
|
|
|
$this->assertNodeCount(1, 'fr'); |
54
|
|
|
$this->assertNodeCount(0, 'en'); |
55
|
|
|
|
56
|
|
|
$crawler = $this->client->request('GET', '/admin/site/form/' . $this->siteId); |
57
|
|
|
$form = $crawler->selectButton('Save')->form(); |
58
|
|
|
|
59
|
|
|
$values = $form->getPhpValues(); |
60
|
|
|
|
61
|
|
|
$values['oo_site']['aliases'][1]['domain'] = $this->siteId . 'name'; |
62
|
|
|
$values['oo_site']['aliases'][1]['language'] = 'en'; |
63
|
|
|
$values['oo_site']['aliases'][1]['main'] = false; |
64
|
|
|
|
65
|
|
|
$this->client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles()); |
66
|
|
|
|
67
|
|
|
$this->assertNodeCount(1, 'fr'); |
68
|
|
|
$this->assertNodeCount(1, 'en'); |
69
|
|
|
|
70
|
|
|
$this->client->request('DELETE', '/api/site/' . $this->siteId . '/delete'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test create 2 site with the same siteId only one is save |
75
|
|
|
*/ |
76
|
|
|
public function testUniqueSiteId() |
77
|
|
|
{ |
78
|
|
|
$this->assertSiteCount(0, $this->siteId); |
79
|
|
|
|
80
|
|
|
$this->createSite(); |
81
|
|
|
|
82
|
|
|
$this->assertSiteCount(1, $this->siteId); |
83
|
|
|
|
84
|
|
|
$this->createSite(); |
85
|
|
|
|
86
|
|
|
$this->assertSiteCount(1, $this->siteId); |
87
|
|
|
|
88
|
|
|
$this->client->request('DELETE', '/api/site/' . $this->siteId . '/delete'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Create a site |
93
|
|
|
*/ |
94
|
|
|
protected function createSite() |
95
|
|
|
{ |
96
|
|
|
$crawler = $this->client->request('GET', '/admin/site/new'); |
97
|
|
|
|
98
|
|
|
$form = $crawler->selectButton('Save')->form(); |
99
|
|
|
|
100
|
|
|
$form['oo_site[siteId]'] = $this->siteId; |
101
|
|
|
$form['oo_site[name]'] = $this->siteId . 'domain'; |
102
|
|
|
$form['oo_site[metaAuthor]'] = $this->siteId . ' Author'; |
103
|
|
|
|
104
|
|
|
$values = $form->getPhpValues(); |
|
|
|
|
105
|
|
|
|
106
|
|
|
$values['oo_site']['aliases'][0]['domain'] = $this->siteId . 'name'; |
107
|
|
|
$values['oo_site']['aliases'][0]['language'] = 'fr'; |
108
|
|
|
$values['oo_site']['aliases'][0]['main'] = true; |
109
|
|
|
|
110
|
|
|
$this->client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles()); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param int $count |
115
|
|
|
* @param string $language |
116
|
|
|
*/ |
117
|
|
|
protected function assertNodeCount($count, $language) |
118
|
|
|
{ |
119
|
|
|
$nodes = $this->nodeRepository->findNotDeletedSortByUpdatedAt(NodeInterface::ROOT_NODE_ID, $language, $this->siteId); |
120
|
|
|
|
121
|
|
|
$this->assertCount($count, $nodes); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param int $count |
126
|
|
|
* @param string $siteId |
127
|
|
|
*/ |
128
|
|
|
protected function assertSiteCount($count, $siteId) |
129
|
|
|
{ |
130
|
|
|
$sites = $this->siteRepository->findBy(array('siteId' => $siteId)); |
|
|
|
|
131
|
|
|
|
132
|
|
|
$this->assertCount($count, $sites); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.