|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Tests\UserPreference; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway; |
|
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\UserPreference\Mapper; |
|
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\UserPreference\Handler; |
|
14
|
|
|
use eZ\Publish\SPI\Persistence\UserPreference\UserPreferenceSetStruct; |
|
15
|
|
|
use eZ\Publish\SPI\Persistence\UserPreference\UserPreference; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class HandlerTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
const USER_PREFERENCE_ID = 1; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway|\PHPUnit\Framework\MockObject\MockObject |
|
24
|
|
|
*/ |
|
25
|
|
|
private $gateway; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\UserPreference\Mapper|\PHPUnit\Framework\MockObject\MockObject |
|
29
|
|
|
*/ |
|
30
|
|
|
private $mapper; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\UserPreference\Handler |
|
34
|
|
|
*/ |
|
35
|
|
|
private $handler; |
|
36
|
|
|
|
|
37
|
|
|
protected function setUp() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->gateway = $this->createMock(Gateway::class); |
|
40
|
|
|
$this->mapper = $this->createMock(Mapper::class); |
|
41
|
|
|
$this->handler = new Handler($this->gateway, $this->mapper); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\UserPreference\Handler::setUserPreference() |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testSetUserPreference() |
|
48
|
|
|
{ |
|
49
|
|
|
$setStruct = new UserPreferenceSetStruct([ |
|
50
|
|
|
'userId' => 5, |
|
51
|
|
|
'name' => 'setting', |
|
52
|
|
|
'value' => 'value', |
|
53
|
|
|
]); |
|
54
|
|
|
|
|
55
|
|
|
$this->gateway |
|
56
|
|
|
->expects($this->once()) |
|
57
|
|
|
->method('setUserPreference') |
|
58
|
|
|
->with($setStruct) |
|
59
|
|
|
->willReturn(self::USER_PREFERENCE_ID); |
|
60
|
|
|
|
|
61
|
|
|
$this->mapper |
|
62
|
|
|
->expects($this->once()) |
|
63
|
|
|
->method('extractUserPreferencesFromRows') |
|
64
|
|
|
->willReturn([new UserPreference([ |
|
65
|
|
|
'id' => self::USER_PREFERENCE_ID, |
|
66
|
|
|
])]); |
|
67
|
|
|
|
|
68
|
|
|
$userPreference = $this->handler->setUserPreference($setStruct); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals($userPreference->id, self::USER_PREFERENCE_ID); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\UserPreference\Handler::countUserPreferences |
|
75
|
|
|
*/ |
|
76
|
|
View Code Duplication |
public function testCountUserPreferences() |
|
77
|
|
|
{ |
|
78
|
|
|
$ownerId = 10; |
|
79
|
|
|
$expectedCount = 12; |
|
80
|
|
|
|
|
81
|
|
|
$this->gateway |
|
82
|
|
|
->expects($this->once()) |
|
83
|
|
|
->method('countUserPreferences') |
|
84
|
|
|
->with($ownerId) |
|
85
|
|
|
->willReturn($expectedCount); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals($expectedCount, $this->handler->countUserPreferences($ownerId)); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\UserPreference\Handler::loadUserPreferences |
|
92
|
|
|
*/ |
|
93
|
|
View Code Duplication |
public function testLoadUserPreferences() |
|
94
|
|
|
{ |
|
95
|
|
|
$ownerId = 9; |
|
96
|
|
|
$limit = 5; |
|
97
|
|
|
$offset = 0; |
|
98
|
|
|
|
|
99
|
|
|
$rows = [ |
|
100
|
|
|
['id' => 1/* ... */], |
|
101
|
|
|
['id' => 2/* ... */], |
|
102
|
|
|
['id' => 3/* ... */], |
|
103
|
|
|
]; |
|
104
|
|
|
|
|
105
|
|
|
$objects = [ |
|
106
|
|
|
new UserPreference(['id' => 1/* ... */]), |
|
107
|
|
|
new UserPreference(['id' => 2/* ... */]), |
|
108
|
|
|
new UserPreference(['id' => 3/* ... */]), |
|
109
|
|
|
]; |
|
110
|
|
|
|
|
111
|
|
|
$this->gateway |
|
112
|
|
|
->expects($this->once()) |
|
113
|
|
|
->method('loadUserPreferences') |
|
114
|
|
|
->with($ownerId, $offset, $limit) |
|
115
|
|
|
->willReturn($rows); |
|
116
|
|
|
|
|
117
|
|
|
$this->mapper |
|
118
|
|
|
->expects($this->once()) |
|
119
|
|
|
->method('extractUserPreferencesFromRows') |
|
120
|
|
|
->with($rows) |
|
121
|
|
|
->willReturn($objects); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertEquals($objects, $this->handler->loadUserPreferences($ownerId, $offset, $limit)); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|