These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | $this->markTestSkipped('To reactivate when API roles will be implemented'); |
||
71 | |||
72 | $crawler = $this->client->request('GET', '/admin/node/new/fixture_page_community'); |
||
73 | |||
74 | $formNode = $crawler->selectButton('Save')->form(); |
||
75 | |||
76 | $nodeName = 'fixturetest' . time(); |
||
77 | $formNode['oo_node[name]'] = $nodeName; |
||
78 | $formNode['oo_node[nodeTemplateSelection][nodeSource]'] = 'root'; |
||
79 | $formNode['oo_node[routePattern]'] = '/page-test' .time(); |
||
80 | |||
81 | $this->submitForm($formNode); |
||
0 ignored issues
–
show
|
|||
82 | |||
83 | $this->client->request('GET', '/api/node/' . $nodeName); |
||
84 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
||
85 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
||
86 | $node = json_decode($this->client->getResponse()->getContent()); |
||
87 | $nodeId = $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 | $this->assertEquals(1, count($this->redirectionRepository->findAll())); |
||
96 | $routeDocumentCount = count($this->routeDocumentRepository->findAll()); |
||
97 | |||
98 | $this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[2], 1, $routeDocumentCount); |
||
99 | $this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[1], 1, $routeDocumentCount + 2); |
||
100 | |||
101 | $this->client->request('POST', '/api/node/' . $nodeName . '/new-version/1?language=' . $node->language, array()); |
||
102 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
||
103 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
||
104 | |||
105 | $newNode = $this->nodeRepository->findInLastVersion($nodeName, $node->language, $this->siteId); |
||
106 | $newNode->setRoutePattern('/page-test' .time()); |
||
107 | $this->documentManager->persist($newNode); |
||
108 | $this->documentManager->flush($newNode); |
||
109 | |||
110 | $this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[2], 1, $routeDocumentCount + 2); |
||
111 | $this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[1], 3, $routeDocumentCount + 6); |
||
112 | $this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[0], 1, $routeDocumentCount + 2); |
||
113 | $this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[0], 1, $routeDocumentCount); |
||
114 | |||
115 | $this->client->request('DELETE', '/api/node/' . $nodeName . '/delete'); |
||
116 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
||
117 | |||
118 | $this->assertEquals(1, count($this->redirectionRepository->findAll())); |
||
119 | $this->assertEquals($routeDocumentCount, count($this->routeDocumentRepository->findAll())); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * change Node status |
||
124 | * |
||
125 | * @param string $nodeId |
||
126 | * @param StatusInterface $status |
||
127 | * @param int $redirectionNumber |
||
128 | * @param int $routeNumber |
||
129 | */ |
||
130 | protected function changeNodeStatusWithRouteRedirectionTest($nodeId, StatusInterface $status, $redirectionNumber, $routeNumber) |
||
131 | { |
||
132 | $this->client->request('POST', '/api/node/' . $nodeId . '/update', |
||
133 | array(), array(), array(), '{"status_id": "'. $status->getId() .'"}'); |
||
134 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
||
135 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
||
136 | $this->assertEquals($redirectionNumber, count($this->redirectionRepository->findAll())); |
||
137 | $this->assertEquals($routeNumber, count($this->routeDocumentRepository->findAll())); |
||
138 | } |
||
139 | } |
||
140 |
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: