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\Model\StatusInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class NodeControllerTest |
12
|
|
|
* |
13
|
|
|
* @group backofficeTest |
14
|
|
|
*/ |
15
|
|
|
class NodeControllerTest extends AbstractFormTest |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var NodeRepositoryInterface |
19
|
|
|
*/ |
20
|
|
|
protected $nodeRepository; |
21
|
|
|
protected $redirectionRepository; |
22
|
|
|
protected $routeDocumentRepository; |
23
|
|
|
protected $documentManager; |
24
|
|
|
protected $language = 'en'; |
25
|
|
|
protected $siteId = '2'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Set up the test |
29
|
|
|
*/ |
30
|
|
|
public function setUp() |
31
|
|
|
{ |
32
|
|
|
parent::setUp(); |
33
|
|
|
|
34
|
|
|
$this->nodeRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.node'); |
35
|
|
|
$this->redirectionRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.redirection'); |
36
|
|
|
$this->routeDocumentRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.route_document'); |
37
|
|
|
$this->documentManager = static::$kernel->getContainer()->get('object_manager'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Test some of the node forms |
42
|
|
|
*/ |
43
|
|
|
public function testNodeForms() |
44
|
|
|
{ |
45
|
|
|
$nodeRoot = $this->nodeRepository->findInLastVersion(NodeInterface::ROOT_NODE_ID, $this->language, $this->siteId); |
46
|
|
|
$nodeFixtureCommunity = $this->nodeRepository->findInLastVersion('fixture_page_community', $this->language, $this->siteId); |
47
|
|
|
|
48
|
|
|
$url = '/admin/node/form/' . $this->siteId . '/' . $nodeRoot->getNodeId(). '/' . $this->language . '/' . $nodeRoot->getVersion(); |
49
|
|
|
$this->client->request('GET', $url); |
50
|
|
|
$this->assertForm($this->client->getResponse()); |
51
|
|
|
|
52
|
|
|
$url = '/admin/node/new/' . $this->siteId . '/' . $this->language . '/' . $nodeRoot->getNodeId() . '/0'; |
53
|
|
|
$this->client->request('GET', $url); |
54
|
|
|
$this->assertForm($this->client->getResponse()); |
55
|
|
|
|
56
|
|
|
$url = '/admin/node/form/' . $this->siteId . '/' . $nodeFixtureCommunity->getNodeId(). '/' . $this->language . '/' . $nodeFixtureCommunity->getVersion(); |
57
|
|
|
$this->client->request('GET', $url); |
58
|
|
|
$this->assertForm($this->client->getResponse()); |
59
|
|
|
|
60
|
|
|
$url = '/admin/node/new/' . $this->siteId . '/' . $this->language . '/' . $nodeRoot->getNodeId() . '/0'; |
61
|
|
|
$this->client->request('GET', $url); |
62
|
|
|
$this->assertForm($this->client->getResponse()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* test new Node |
67
|
|
|
*/ |
68
|
|
|
public function testNewNodePageHome() |
69
|
|
|
{ |
70
|
|
|
$crawler = $this->client->request('GET', '/admin/node/new/2/fr/fixture_page_news/1'); |
71
|
|
|
|
72
|
|
|
$formNode = $crawler->selectButton('Save')->form(); |
73
|
|
|
|
74
|
|
|
$nodeName = 'fixturetest' . time(); |
75
|
|
|
$formNode['oo_node[name]'] = $nodeName; |
76
|
|
|
$formNode['oo_node[nodeTemplateSelection][nodeSource]'] = 'root'; |
77
|
|
|
$formNode['oo_node[routePattern]'] = '/page-test' .time(); |
78
|
|
|
|
79
|
|
|
$this->submitForm($formNode); |
|
|
|
|
80
|
|
|
|
81
|
|
|
$node = static::$kernel->getContainer()->get('open_orchestra_model.repository.node')->findOneByName($nodeName); |
82
|
|
|
$this->client->request('GET', '/api/node/show/' . $node->getNodeId() . '/' . $node->getSiteId() . '/' . $node->getLanguage() . '/' . $node->getVersion()); |
83
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
84
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
85
|
|
|
$node = json_decode($this->client->getResponse()->getContent()); |
86
|
|
|
$id = $node->id; |
87
|
|
|
$nodeId = $node->node_id; |
88
|
|
|
|
89
|
|
|
$statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
90
|
|
|
$statuses = array(); |
91
|
|
|
$statuses[0] = $statusRepository->findOneBy(array("name" => "draft")); |
92
|
|
|
$statuses[1] = $statusRepository->findOneBy(array("name" => "published")); |
93
|
|
|
$statuses[2] = $statusRepository->findOneBy(array("name" => "pending")); |
94
|
|
|
|
95
|
|
|
$autoUnpublishTo = $statusRepository->findOnebyAutoUnpublishTo(); |
96
|
|
|
|
97
|
|
|
$routeDocumentCount = count($this->routeDocumentRepository->findAll()); |
98
|
|
|
$redirectionCount = count($this->redirectionRepository->findAll()); |
99
|
|
|
|
100
|
|
|
$this->changeNodeStatusWithRouteRedirectionTest($id, $statuses[2], $redirectionCount, $routeDocumentCount); |
101
|
|
|
$this->changeNodeStatusWithRouteRedirectionTest($id, $statuses[1], $redirectionCount, $routeDocumentCount + 2); |
102
|
|
|
|
103
|
|
|
$this->client->request('POST', '/api/node/new-version/' . $nodeId . '/fr/' . $node->version, array()); |
104
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
105
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
106
|
|
|
|
107
|
|
|
$newNode = $this->nodeRepository->findInLastVersion($nodeId, $node->language, $this->siteId); |
108
|
|
|
$newNode->setRoutePattern('/page-test' .time()); |
109
|
|
|
$this->documentManager->persist($newNode); |
110
|
|
|
$this->documentManager->flush(); |
111
|
|
|
|
112
|
|
|
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[2], $redirectionCount, $routeDocumentCount + 2); |
113
|
|
|
|
114
|
|
|
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[1], $redirectionCount + 2, $routeDocumentCount + 2); |
115
|
|
|
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[0], $redirectionCount, $routeDocumentCount); |
116
|
|
|
|
117
|
|
|
$nodes = $this->nodeRepository->findByNodeId($nodeId); |
118
|
|
|
foreach ($nodes as $node) { |
119
|
|
|
$node->setStatus($autoUnpublishTo); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$this->documentManager->flush(); |
123
|
|
|
|
124
|
|
|
$this->client->request('DELETE', '/api/node/delete/' . $nodeId); |
125
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
126
|
|
|
|
127
|
|
|
$this->assertEquals(2, count($this->redirectionRepository->findAll())); |
128
|
|
|
$this->assertEquals($routeDocumentCount, count($this->routeDocumentRepository->findAll())); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* change Node status |
133
|
|
|
* |
134
|
|
|
* @param string $nodeId |
135
|
|
|
* @param StatusInterface $status |
136
|
|
|
* @param int $redirectionNumber |
137
|
|
|
* @param int $routeNumber |
138
|
|
|
*/ |
139
|
|
|
protected function changeNodeStatusWithRouteRedirectionTest($nodeId, StatusInterface $status, $redirectionNumber, $routeNumber) |
140
|
|
|
{ |
141
|
|
|
$node = $this->nodeRepository->find($nodeId); |
142
|
|
|
$node->setStatus($status); |
143
|
|
|
$this->client->request('PUT', '/api/node/update-status', |
144
|
|
|
array(), array(), array(), static::$kernel->getContainer()->get('jms_serializer')->serialize($node, 'json')); |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
148
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
149
|
|
|
$this->assertEquals($routeNumber, count($this->routeDocumentRepository->findAll())); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: