Completed
Push — master ( c3eba2...34879d )
by amaury
05:12 queued 01:44
created

BackofficeBundle/Controller/NodeControllerTest.php (1 issue)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

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();
71
72
        $crawler = $this->client->request('GET', '/admin/node/new/2/fr/fixture_page_news/1');
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
$formNode is of type array<string,string,{"oo...utePattern]":"string"}>, but the function expects a object<Symfony\Component\DomCrawler\Form>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
83
        $node = static::$kernel->getContainer()->get('open_orchestra_model.repository.node')->findOneByName($nodeName);
84
        $this->client->request('GET', '/api/node/show/' . $node->getNodeId() . '/' . $node->getSiteId() . '/' . $node->getLanguage() . '/' . $node->getVersion());
85
        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
86
        $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
87
        $node = json_decode($this->client->getResponse()->getContent());
88
        $nodeId = $node->id;
89
90
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
91
        $statuses = array();
92
        $statuses[0] = $statusRepository->findOneBy(array("name" => "draft"));
93
        $statuses[1] = $statusRepository->findOneBy(array("name" => "published"));
94
        $statuses[2] = $statusRepository->findOneBy(array("name" => "pending"));
95
96
        $autoUnpublishTo = $statusRepository->findOnebyAutoUnpublishTo();
97
98
        $routeDocumentCount = count($this->routeDocumentRepository->findAll());
99
        $redirectionCount = count($this->redirectionRepository->findAll());
100
101
        $this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[2], $redirectionCount, $routeDocumentCount);
102
        $this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[1], $redirectionCount, $routeDocumentCount + 2);
103
104
        $this->client->request('POST', '/api/node/new-version/' . $nodeName . '/fr/' . $node->version, array());
105
        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
106
        $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
107
108
        $newNode = $this->nodeRepository->findInLastVersion($nodeName, $node->language, $this->siteId);
109
        $newNode->setRoutePattern('/page-test' .time());
110
        $this->documentManager->persist($newNode);
111
        $this->documentManager->flush($newNode);
112
113
        $this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[2], $redirectionCount, $routeDocumentCount + 2);
114
        $this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[1], $redirectionCount + 2, $routeDocumentCount + 6);
115
        $this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[0], $redirectionCount, $routeDocumentCount + 2);
116
        $this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[0], $redirectionCount, $routeDocumentCount);
117
118
        $nodes = $this->nodeRepository->findByNodeId($nodeName);
119
        foreach ($nodes as $node) {
120
            var_dump($node->getId());
121
            $node->setStatus($autoUnpublishTo);
122
        }
123
        static::$kernel->getContainer()->get('object_manager')->flush();
124
125
        $this->client->request('DELETE', '/api/node/delete/' . $nodeName);
126
        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
127
128
        $this->assertEquals(1, count($this->redirectionRepository->findAll()));
129
        $this->assertEquals($routeDocumentCount, count($this->routeDocumentRepository->findAll()));
130
    }
131
132
    /**
133
     * change Node status
134
     *
135
     * @param string          $nodeId
136
     * @param StatusInterface $status
137
     * @param int             $redirectionNumber
138
     * @param int             $routeNumber
139
     */
140
    protected function changeNodeStatusWithRouteRedirectionTest($nodeId, StatusInterface $status, $redirectionNumber, $routeNumber)
141
    {
142
        $node = $this->nodeRepository->find($nodeId);
143
        $node->setStatus($status);
144
        $this->client->request('PUT', '/api/node/update-status',
145
            array(), array(), array(), static::$kernel->getContainer()->get('jms_serializer')->serialize($node, 'json'));
146
147
148
        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
149
        $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
150
        $this->assertEquals($redirectionNumber, count($this->redirectionRepository->findAll()));
151
        $this->assertEquals($routeNumber, count($this->routeDocumentRepository->findAll()));
152
    }
153
}
154