Completed
Push — master ( f2dfe9...84d91c )
by André
35:37 queued 16:15
created

DoctrineDatabaseTest::testLoadLanguageData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\Language\Gateway\DoctrineDatabaseTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content\Language\Gateway;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase;
13
use eZ\Publish\SPI\Persistence\Content\Language;
14
15
/**
16
 * Test case for eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase.
17
 */
18
class DoctrineDatabaseTest extends TestCase
19
{
20
    /**
21
     * Database gateway to test.
22
     *
23
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase
24
     */
25
    protected $databaseGateway;
26
27
    /**
28
     * Inserts DB fixture.
29
     */
30
    public function setUp()
31
    {
32
        parent::setUp();
33
34
        $this->insertDatabaseFixture(
35
            __DIR__ . '/../../_fixtures/languages.php'
36
        );
37
    }
38
39
    /**
40
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::__construct
41
     */
42
    public function testCtor()
43
    {
44
        $handler = $this->getDatabaseHandler();
45
        $gateway = $this->getDatabaseGateway();
46
47
        $this->assertAttributeSame(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3338

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
48
            $handler,
49
            'dbHandler',
50
            $gateway
51
        );
52
    }
53
54
    /**
55
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::insertLanguage
56
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::setCommonLanguageColumns
57
     */
58
    public function testInsertLanguage()
59
    {
60
        $gateway = $this->getDatabaseGateway();
61
62
        $gateway->insertLanguage($this->getLanguageFixture());
63
64
        $this->assertQueryResult(
65
            array(
66
                array(
67
                    'id' => '8',
68
                    'locale' => 'de-DE',
69
                    'name' => 'Deutsch (Deutschland)',
70
                    'disabled' => '0',
71
                ),
72
            ),
73
            $this->getDatabaseHandler()->createSelectQuery()
74
                ->select('id', 'locale', 'name', 'disabled')
75
                ->from('ezcontent_language')
76
                ->where('id=8')
77
        );
78
    }
79
80
    /**
81
     * Returns a Language fixture.
82
     *
83
     * @return \eZ\Publish\SPI\Persistence\Content\Language
84
     */
85
    protected function getLanguageFixture()
86
    {
87
        $language = new Language();
88
89
        $language->languageCode = 'de-DE';
90
        $language->name = 'Deutsch (Deutschland)';
91
        $language->isEnabled = true;
92
93
        return $language;
94
    }
95
96
    /**
97
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::updateLanguage
98
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::setCommonLanguageColumns
99
     */
100 View Code Duplication
    public function testUpdateLanguage()
101
    {
102
        $gateway = $this->getDatabaseGateway();
103
104
        $language = $this->getLanguageFixture();
105
        $language->id = 2;
106
107
        $gateway->updateLanguage($language);
108
109
        $this->assertQueryResult(
110
            array(
111
                array(
112
                    'id' => '2',
113
                    'locale' => 'de-DE',
114
                    'name' => 'Deutsch (Deutschland)',
115
                    'disabled' => '0',
116
                ),
117
            ),
118
            $this->getDatabaseHandler()->createSelectQuery()
119
                ->select('id', 'locale', 'name', 'disabled')
120
                ->from('ezcontent_language')
121
                ->where('id=2')
122
        );
123
    }
124
125
    /**
126
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::loadLanguageListData
127
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::createFindQuery
128
     */
129
    public function testLoadLanguageListData()
130
    {
131
        $gateway = $this->getDatabaseGateway();
132
133
        $result = $gateway->loadLanguageListData([2]);
134
135
        $this->assertEquals(
136
            array(
137
                array(
138
                    'id' => '2',
139
                    'locale' => 'eng-US',
140
                    'name' => 'English (American)',
141
                    'disabled' => '0',
142
                ),
143
            ),
144
            $result
145
        );
146
    }
147
148
    /**
149
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::loadAllLanguagesData
150
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::createFindQuery
151
     */
152
    public function testLoadAllLanguagesData()
153
    {
154
        $gateway = $this->getDatabaseGateway();
155
156
        $result = $gateway->loadAllLanguagesData();
157
158
        $this->assertEquals(
159
            array(
160
                array(
161
                    'id' => '2',
162
                    'locale' => 'eng-US',
163
                    'name' => 'English (American)',
164
                    'disabled' => '0',
165
                ),
166
                array(
167
                    'id' => '4',
168
                    'locale' => 'eng-GB',
169
                    'name' => 'English (United Kingdom)',
170
                    'disabled' => '0',
171
                ),
172
            ),
173
            $result
174
        );
175
    }
176
177
    /**
178
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase::deleteLanguage
179
     */
180 View Code Duplication
    public function testDeleteLanguage()
181
    {
182
        $gateway = $this->getDatabaseGateway();
183
184
        $result = $gateway->deleteLanguage(2);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $gateway->deleteLanguage(2) (which targets eZ\Publish\Core\Persiste...abase::deleteLanguage()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
185
186
        $this->assertQueryResult(
187
            array(
188
                array(
189
                    'count' => '1',
190
                ),
191
            ),
192
            $this->getDatabaseHandler()->createSelectQuery()
193
                ->select('COUNT( * ) AS count')
194
                ->from('ezcontent_language')
195
        );
196
197
        $this->assertQueryResult(
198
            array(
199
                array(
200
                    'count' => '0',
201
                ),
202
            ),
203
            $this->getDatabaseHandler()->createSelectQuery()
204
                ->select('COUNT( * ) AS count')
205
                ->from('ezcontent_language')
206
                ->where('id=2')
207
        );
208
    }
209
210
    /**
211
     * Returns a ready to test DoctrineDatabase gateway.
212
     *
213
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase
214
     */
215
    protected function getDatabaseGateway()
216
    {
217
        if (!isset($this->databaseGateway)) {
218
            $this->databaseGateway = new DoctrineDatabase(
219
                $this->getDatabaseHandler()
220
            );
221
        }
222
223
        return $this->databaseGateway;
224
    }
225
}
226