Completed
Push — EZP-31383 ( 83ce0c )
by
unknown
19:12
created

DoctrineDatabaseTest::testCopyRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
dl 25
loc 25
c 0
b 0
f 0
cc 1
nc 1
nop 0
rs 9.52
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\User\Role\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\User\Role\Gateway;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase;
13
use eZ\Publish\SPI\Persistence\User\Role;
14
15
/**
16
 * Test case for eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase.
17
 */
18
class DoctrineDatabaseTest extends TestCase
19
{
20
    /**
21
     * Database gateway to test.
22
     *
23
     * @var \eZ\Publish\Core\Persistence\Legacy\User\Role\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/roles.php'
36
        );
37
    }
38
39
    /**
40
     * @covers \eZ\Publish\Core\Persistence\Legacy\User\Role\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
            'handler',
50
            $gateway
51
        );
52
    }
53
54
    /**
55
     * @covers \eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase::createRole
56
     */
57 View Code Duplication
    public function testCreateRole()
58
    {
59
        $gateway = $this->getDatabaseGateway();
60
61
        $spiRole = new Role([
62
            'identifier' => 'new_role',
63
            'status' => Role::STATUS_DRAFT,
64
        ]);
65
        $gateway->createRole($spiRole);
66
        $query = $this->getDatabaseHandler()->createSelectQuery();
67
68
        $this->assertQueryResult(
69
            [
70
                [
71
                    'id' => '6',
72
                    'name' => 'new_role',
73
                    'version' => -1,
74
                ],
75
            ],
76
            $query
77
                ->select('id', 'name', 'version')
78
                ->from('ezrole')
79
                ->where($query->expr->eq('name', $query->bindValue('new_role')))
80
        );
81
    }
82
83
    /**
84
     * @covers \eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase::createRole
85
     */
86 View Code Duplication
    public function testCopyRole()
87
    {
88
        $gateway = $this->getDatabaseGateway();
89
90
        $spiRole = new Role([
91
            'identifier' => 'cloned_role',
92
            'status' => Role::STATUS_DRAFT,
93
        ]);
94
        $gateway->copyRole($spiRole);
95
        $query = $this->getDatabaseHandler()->createSelectQuery();
96
97
        $this->assertQueryResult(
98
            [
99
                [
100
                    'id' => '6',
101
                    'name' => 'cloned_role',
102
                    'version' => 0,
103
                ],
104
            ],
105
            $query
106
                ->select('id', 'name', 'version')
107
                ->from('ezrole')
108
                ->where($query->expr->eq('name', $query->bindValue('cloned_role')))
109
        );
110
    }
111
112
    /**
113
     * @covers \eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase::loadRoleAssignment
114
     */
115
    public function testLoadRoleAssignment()
116
    {
117
        $gateway = $this->getDatabaseGateway();
118
119
        $this->assertEquals(
120
            [
121
                [
122
                    'contentobject_id' => '12',
123
                    'id' => '25',
124
                    'limit_identifier' => '',
125
                    'limit_value' => '',
126
                    'role_id' => '2',
127
                ],
128
            ],
129
            $gateway->loadRoleAssignment(25)
130
        );
131
    }
132
133
    /**
134
     * @covers \eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase::loadRoleAssignmentsByGroupId
135
     */
136 View Code Duplication
    public function testLoadRoleAssignmentsByGroupId()
137
    {
138
        $gateway = $this->getDatabaseGateway();
139
140
        $this->assertEquals(
141
            [
142
                [
143
                    'contentobject_id' => '11',
144
                    'id' => '28',
145
                    'limit_identifier' => '',
146
                    'limit_value' => '',
147
                    'role_id' => '1',
148
                ],
149
                [
150
                    'contentobject_id' => '11',
151
                    'id' => '34',
152
                    'limit_identifier' => '',
153
                    'limit_value' => '',
154
                    'role_id' => '5',
155
                ],
156
                [
157
                    'contentobject_id' => '11',
158
                    'id' => '40',
159
                    'limit_identifier' => 'Section',
160
                    'limit_value' => '3',
161
                    'role_id' => '4',
162
                ],
163
            ],
164
            $gateway->loadRoleAssignmentsByGroupId(11)
165
        );
166
    }
167
168
    /**
169
     * @covers \eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase::loadRoleAssignmentsByRoleId
170
     */
171 View Code Duplication
    public function testLoadRoleAssignmentsByRoleId()
172
    {
173
        $gateway = $this->getDatabaseGateway();
174
175
        $this->assertEquals(
176
            [
177
                [
178
                    'contentobject_id' => '11',
179
                    'id' => '28',
180
                    'limit_identifier' => '',
181
                    'limit_value' => '',
182
                    'role_id' => '1',
183
                ],
184
                [
185
                    'contentobject_id' => '42',
186
                    'id' => '31',
187
                    'limit_identifier' => '',
188
                    'limit_value' => '',
189
                    'role_id' => '1',
190
                ],
191
                [
192
                    'contentobject_id' => '59',
193
                    'id' => '37',
194
                    'limit_identifier' => '',
195
                    'limit_value' => '',
196
                    'role_id' => '1',
197
                ],
198
            ],
199
            $gateway->loadRoleAssignmentsByRoleId(1)
200
        );
201
    }
202
203
    /**
204
     * Returns a ready to test DoctrineDatabase gateway.
205
     *
206
     * @return \eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase
207
     */
208
    protected function getDatabaseGateway()
209
    {
210
        if (!isset($this->databaseGateway)) {
211
            $this->databaseGateway = new DoctrineDatabase(
212
                $this->getDatabaseHandler()
213
            );
214
        }
215
216
        return $this->databaseGateway;
217
    }
218
}
219