Completed
Pull Request — master (#168)
by
unknown
02:57
created

PersonalSettingsTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 1
cbo 7
dl 0
loc 102
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 52 1
A testSettingsDisplayed() 0 12 1
A testSettingsSelected() 0 19 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\SettingsBundle\Tests\Functional\Settings\Personal;
13
14
use ONGR\SettingsBundle\Document\Setting;
15
use ONGR\SettingsBundle\Document\Profile;
16
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
17
use ONGR\ElasticsearchBundle\Service\Manager;
18
use Symfony\Bundle\FrameworkBundle\Client;
19
20
/**
21
 * Test integration with admin-user feature in admin bundle.
22
 */
23
class PersonalSettingsTest extends WebTestCase
24
{
25
    /**
26
     * @var Client
27
     */
28
    private $client;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function setUp()
34
    {
35
        parent::setUp();
36
37
        static::bootKernel(['environment' => 'test_container_creation']);
38
39
        /** @var Client $client */
40
        $this->client = static::createClient();
41
        /** @var Manager $manager */
42
        $manager = static::$kernel->getContainer()->get('es.manager');
43
44
        // There is something wrong with ElasticsearchTestCase method getDataArray,
45
        // if we don't create in here all test data, it's not existing when test is run.
46
        $content = new Profile();
47
        $content->setId('default_profile');
48
        $content->setName('default');
49
        $manager->persist($content);
50
51
        $content = new Profile();
52
        $content->setName('profile_foo.com_profile');
53
        $content->setName('profile_foo.com');
54
        $manager->persist($content);
55
56
        $content = new Setting();
57
        $content->setId('foo_default');
58
        $content->setName('test');
59
        $content->setProfile('default');
60
        $content->setDescription('Description');
61
        $content->setType(Setting::TYPE_ARRAY);
62
        $content->setData((object)['value' => 'testData']);
63
        $manager->persist($content);
64
65
        $content = new Setting();
66
        $content->setId('foo');
67
        $content->setName('test2');
68
        $content->setProfile('profile_foo.com');
69
        $content->setDescription('Description');
70
        $content->setType(Setting::TYPE_ARRAY);
71
        $content->setData((object)['value' => 'testData']);
72
        $manager->persist($content);
73
74
        $content = new Setting();
75
        $content->setId('bar');
76
        $content->setName('test2');
77
        $content->setProfile('profile_foo.com');
78
        $content->setDescription('Description');
79
        $content->setType(Setting::TYPE_ARRAY);
80
        $content->setData((object)['value' => 'testData']);
81
        $manager->persist($content);
82
83
        $manager->commit();
84
    }
85
86
    /**
87
     * When user is logged in, he should see admin settings and profile checkboxes.
88
     */
89
    public function testSettingsDisplayed()
90
    {
91
        // Retrieve content.
92
        $crawler = $this->client->request('GET', '/settings/settings');
93
94
        // Asserts.
95
        $settingsDescription = $crawler->filter('.category-ongr_settings_settings');
96
        $this->assertCount(1, $settingsDescription, 'Live settings setting must exist');
97
98
        $profile = $crawler->filter('.profile-ongr_settings_profiles');
99
        $this->assertCount(2, $profile, 'Profile default checkbox must exist');
100
    }
101
102
    /**
103
     * When user is logged in, and he selects profile, then settings container must receive that choice.
104
     */
105
    public function testSettingsSelected()
106
    {
107
        $this->client->request(
108
            'GET',
109
            $this->client->getContainer()->get('router')->generate(
110
                'ongr_settings_personal_settings_change',
111
                [
112
                    'encodedName' => base64_encode('ongr_settings_profile_default'),
113
                ]
114
            )
115
        );
116
        $this->assertTrue($this->client->getResponse()->isOk());
117
        // Load any url and check that user selected domains are loaded.
118
        $this->client->request('GET', '/settings/setting/test/edit');
119
        $settingsContainer = $this->client->getContainer()->get('ongr_settings.settings_container');
120
121
        $selectedDomains = $settingsContainer->getProfiles();
122
        $this->assertTrue(in_array('default', $selectedDomains));
123
    }
124
}
125