|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Sulu. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sulu\Bundle\ElasticsearchActivityLogBundle\Tests\Storage; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Service\Manager; |
|
15
|
|
|
use Prophecy\Argument; |
|
16
|
|
|
use Sulu\Bundle\ElasticsearchActivityLogBundle\Storage\ElasticsearchActivityStorage; |
|
17
|
|
|
use Sulu\Component\ActivityLog\Repository\UserRepositoryInterface; |
|
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
20
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
21
|
|
|
|
|
22
|
|
|
class ElasticsearchActivityStorageTest extends KernelTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var ContainerInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $container; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var ElasticsearchActivityStorage |
|
31
|
|
|
*/ |
|
32
|
|
|
private $storage; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var UserInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
private $user; |
|
38
|
|
|
|
|
39
|
|
|
public function setUp() |
|
40
|
|
|
{ |
|
41
|
|
|
/** @var Manager $manager */ |
|
42
|
|
|
$manager = $this->getContainer()->get('es.manager.live'); |
|
43
|
|
|
$manager->dropAndCreateIndex(); |
|
44
|
|
|
|
|
45
|
|
|
$userRepository = $this->prophesize(UserRepositoryInterface::class); |
|
46
|
|
|
$this->user = $this->prophesize(TestUserInterface::class); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
$userRepository->findOneById(Argument::any())->willReturn($this->user->reveal()); |
|
49
|
|
|
|
|
50
|
|
|
$this->storage = new ElasticsearchActivityStorage( |
|
51
|
|
|
$manager, |
|
52
|
|
|
$userRepository->reveal() |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testPersist() |
|
57
|
|
|
{ |
|
58
|
|
|
$activity = $this->storage->create('test')->setData(['test' => 'test'])->setCreator($this->user->reveal()); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$this->storage->persist($activity); |
|
61
|
|
|
$this->storage->flush(); |
|
62
|
|
|
|
|
63
|
|
|
$result = $this->storage->find($activity->getUuid()); |
|
64
|
|
|
$this->assertEquals($activity->getUuid(), $result->getUuid()); |
|
65
|
|
|
$this->assertEquals($activity->getData(), $result->getData()); |
|
66
|
|
|
$this->assertEquals($activity->getCreator(), $this->user->reveal()); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
return $activity; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testPersistChildren() |
|
72
|
|
|
{ |
|
73
|
|
|
$parentActivity = $this->storage->create('test'); |
|
74
|
|
|
$childActivity = $this->storage->create('test')->setParent($parentActivity)->setCreator($this->user->reveal()); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$this->storage->persist($parentActivity); |
|
77
|
|
|
$this->storage->persist($childActivity); |
|
78
|
|
|
$this->storage->flush(); |
|
79
|
|
|
|
|
80
|
|
|
$result = $this->storage->findByParent($parentActivity, 1, 10); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertCount(1, $result); |
|
83
|
|
|
$this->assertEquals($childActivity->getUuid(), $result[0]->getUuid()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testFind() |
|
87
|
|
|
{ |
|
88
|
|
|
$parentActivity = $this->storage->create('test'); |
|
89
|
|
|
$childActivity = $this->storage->create('test')->setParent($parentActivity)->setCreator($this->user->reveal()); |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$this->storage->persist($parentActivity); |
|
92
|
|
|
$this->storage->persist($childActivity); |
|
93
|
|
|
$this->storage->flush(); |
|
94
|
|
|
|
|
95
|
|
|
$result = $this->storage->find($childActivity->getUuid()); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertEquals($childActivity->getUuid(), $result->getUuid()); |
|
98
|
|
|
$this->assertEquals($parentActivity->getUuid(), $result->getParent()->getUuid()); |
|
99
|
|
|
$this->assertEquals($childActivity->getCreator(), $this->user->reveal()); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testFindAll() |
|
103
|
|
|
{ |
|
104
|
|
|
$parentActivity = $this->storage->create('test')->setCreator($this->user->reveal()); |
|
|
|
|
|
|
105
|
|
|
$childActivity = $this->storage->create('test')->setParent($parentActivity)->setCreator($this->user->reveal()); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
$this->storage->persist($parentActivity); |
|
108
|
|
|
$this->storage->persist($childActivity); |
|
109
|
|
|
$this->storage->flush(); |
|
110
|
|
|
|
|
111
|
|
|
$result = $this->storage->findAll(1, 10); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertCount(2, $result); |
|
114
|
|
|
$this->assertEquals($parentActivity->getUuid(), $result[0]->getUuid()); |
|
115
|
|
|
$this->assertEquals($childActivity->getUuid(), $result[1]->getUuid()); |
|
116
|
|
|
$this->assertEquals($parentActivity->getUuid(), $result[1]->getParent()->getUuid()); |
|
117
|
|
|
$this->assertEquals($childActivity->getCreator(), $this->user->reveal()); |
|
|
|
|
|
|
118
|
|
|
$this->assertEquals($parentActivity->getCreator(), $this->user->reveal()); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testFindAllWithSearch() |
|
122
|
|
|
{ |
|
123
|
|
|
$activity = $this->storage->create('test')->setMessage('Message which should be found'); |
|
124
|
|
|
$activity2 = $this->storage->create('test')->setMessage('Secret message'); |
|
125
|
|
|
$activity3 = $this->storage->create('test')->setMessage('Another message which should be found'); |
|
126
|
|
|
$activity4 = $this->storage->create('test')->setMessage('Another secret message'); |
|
127
|
|
|
$activity5 = $this->storage->create('test')->setMessage('Third message which should be found'); |
|
128
|
|
|
$activity6 = $this->storage->create('test')->setMessage('Third secret message'); |
|
129
|
|
|
|
|
130
|
|
|
$this->storage->persist($activity); |
|
131
|
|
|
$this->storage->persist($activity2); |
|
132
|
|
|
$this->storage->persist($activity3); |
|
133
|
|
|
$this->storage->persist($activity4); |
|
134
|
|
|
$this->storage->persist($activity5); |
|
135
|
|
|
$this->storage->persist($activity6); |
|
136
|
|
|
$this->storage->flush(); |
|
137
|
|
|
|
|
138
|
|
|
$result = $this->storage->findAllWithSearch(); |
|
139
|
|
|
$resultWithSearch = $this->storage->findAllWithSearch('found', ['message']); |
|
140
|
|
|
$sortedResultWithSearch = $this->storage->findAllWithSearch('found', ['message'], 1, 2, 'message', 'desc'); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertCount(6, $result); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertCount(3, $resultWithSearch); |
|
145
|
|
|
$this->assertEquals($activity->getUuid(), $resultWithSearch[0]->getUuid()); |
|
146
|
|
|
$this->assertEquals($activity3->getUuid(), $resultWithSearch[1]->getUuid()); |
|
147
|
|
|
$this->assertEquals($activity5->getUuid(), $resultWithSearch[2]->getUuid()); |
|
148
|
|
|
|
|
149
|
|
|
$this->assertCount(2, $sortedResultWithSearch); |
|
150
|
|
|
$this->assertEquals($activity->getUuid(), $sortedResultWithSearch[1]->getUuid()); |
|
151
|
|
|
$this->assertEquals($activity5->getUuid(), $sortedResultWithSearch[0]->getUuid()); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function testFindAllWithSearchAndSorting() |
|
155
|
|
|
{ |
|
156
|
|
|
$activity = $this->storage->create('test')->setMessage('Message which should be found'); |
|
157
|
|
|
$activity2 = $this->storage->create('test')->setMessage('Secret message'); |
|
158
|
|
|
$activity3 = $this->storage->create('test')->setMessage('Another message which should be found'); |
|
159
|
|
|
$activity4 = $this->storage->create('test')->setMessage('Another secret message'); |
|
160
|
|
|
|
|
161
|
|
|
$this->storage->persist($activity); |
|
162
|
|
|
$this->storage->persist($activity2); |
|
163
|
|
|
$this->storage->persist($activity3); |
|
164
|
|
|
$this->storage->persist($activity4); |
|
165
|
|
|
$this->storage->flush(); |
|
166
|
|
|
|
|
167
|
|
|
$result = $this->storage->findAllWithSearch('found', ['message']); |
|
168
|
|
|
|
|
169
|
|
|
$this->assertCount(2, $result); |
|
170
|
|
|
$this->assertEquals($activity->getUuid(), $result[0]->getUuid()); |
|
171
|
|
|
$this->assertEquals($activity3->getUuid(), $result[1]->getUuid()); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Return the test container. |
|
176
|
|
|
* |
|
177
|
|
|
* This container will use the default configuration of the kernel. |
|
178
|
|
|
* |
|
179
|
|
|
* If you require the container for a different kernel environment |
|
180
|
|
|
* you should create a new Kernel with the `getKernel` method and |
|
181
|
|
|
* retrieve the Container from that. |
|
182
|
|
|
* |
|
183
|
|
|
* @return ContainerInterface |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getContainer() |
|
186
|
|
|
{ |
|
187
|
|
|
if ($this->container) { |
|
188
|
|
|
return $this->container; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
self::bootKernel(); |
|
192
|
|
|
|
|
193
|
|
|
$this->container = self::$kernel->getContainer(); |
|
194
|
|
|
|
|
195
|
|
|
return $this->container; |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
interface TestUserInterface extends UserInterface |
|
|
|
|
|
|
200
|
|
|
{ |
|
201
|
|
|
public function getId(); |
|
202
|
|
|
} |
|
203
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..