SiteControllerTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 118
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
B testCreateSite() 0 26 1
A testUniqueSiteId() 0 14 1
A createSite() 0 18 1
A assertNodeCount() 0 6 1
A assertSiteCount() 0 6 1
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();
0 ignored issues
show
Bug introduced by
The method getPhpValues cannot be called on $form (of type array<string,string,{"oo...metaAuthor]":"string"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method getMethod cannot be called on $form (of type array<string,string,{"oo...metaAuthor]":"string"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method getUri cannot be called on $form (of type array<string,string,{"oo...metaAuthor]":"string"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method getPhpFiles cannot be called on $form (of type array<string,string,{"oo...metaAuthor]":"string"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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));
0 ignored issues
show
Bug introduced by
The method findBy() does not exist on OpenOrchestra\ModelInter...SiteRepositoryInterface. Did you maybe mean findByAliasDomain()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
129
130
        $this->assertCount($count, $sites);
131
    }
132
}
133