1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\EntityConfigBundle\Tests\Unit\Config; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\EntityConfigBundle\Config\Config; |
6
|
|
|
use Oro\Bundle\EntityConfigBundle\Config\ConfigManager; |
7
|
|
|
use Oro\Bundle\EntityConfigBundle\Config\Id\ConfigIdInterface; |
8
|
|
|
use Oro\Bundle\EntityConfigBundle\Config\Id\EntityConfigId; |
9
|
|
|
use Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId; |
10
|
|
|
use Oro\Bundle\EntityConfigBundle\Entity\ConfigModel; |
11
|
|
|
use Oro\Bundle\EntityConfigBundle\Entity\EntityConfigModel; |
12
|
|
|
use Oro\Bundle\EntityConfigBundle\Entity\FieldConfigModel; |
13
|
|
|
use Oro\Bundle\EntityConfigBundle\Event\Events; |
14
|
|
|
use Oro\Bundle\EntityConfigBundle\Event\EntityConfigEvent; |
15
|
|
|
use Oro\Bundle\EntityConfigBundle\Event\FieldConfigEvent; |
16
|
|
|
use Oro\Bundle\EntityConfigBundle\Metadata\EntityMetadata; |
17
|
|
|
use Oro\Bundle\EntityConfigBundle\Metadata\FieldMetadata; |
18
|
|
|
use Oro\Bundle\EntityConfigBundle\Provider\PropertyConfigContainer; |
19
|
|
|
use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveClassLength) |
23
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) |
24
|
|
|
* @SuppressWarnings(PHPMD.ExcessivePublicCount) |
25
|
|
|
*/ |
26
|
|
|
class ConfigManagerTest extends \PHPUnit_Framework_TestCase |
27
|
|
|
{ |
28
|
|
|
const ENTITY_CLASS = 'Oro\Bundle\EntityConfigBundle\Tests\Unit\Fixture\DemoEntity'; |
29
|
|
|
|
30
|
|
|
/** @var ConfigManager */ |
31
|
|
|
protected $configManager; |
32
|
|
|
|
33
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
34
|
|
|
protected $eventDispatcher; |
35
|
|
|
|
36
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
37
|
|
|
protected $metadataFactory; |
38
|
|
|
|
39
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
40
|
|
|
protected $configProvider; |
41
|
|
|
|
42
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
43
|
|
|
protected $modelManager; |
44
|
|
|
|
45
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
46
|
|
|
protected $auditManager; |
47
|
|
|
|
48
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
49
|
|
|
protected $configCache; |
50
|
|
|
|
51
|
|
|
protected function setUp() |
52
|
|
|
{ |
53
|
|
|
$this->configProvider = $this->getConfigProviderMock(); |
54
|
|
|
$this->configProvider->expects($this->any()) |
55
|
|
|
->method('getScope') |
56
|
|
|
->willReturn('entity'); |
57
|
|
|
|
58
|
|
|
$this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
59
|
|
|
->disableOriginalConstructor() |
60
|
|
|
->getMock(); |
61
|
|
|
$this->metadataFactory = $this->getMockBuilder('Metadata\MetadataFactory') |
62
|
|
|
->disableOriginalConstructor() |
63
|
|
|
->getMock(); |
64
|
|
|
$this->modelManager = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Config\ConfigModelManager') |
65
|
|
|
->disableOriginalConstructor() |
66
|
|
|
->getMock(); |
67
|
|
|
$this->auditManager = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Audit\AuditManager') |
68
|
|
|
->disableOriginalConstructor() |
69
|
|
|
->getMock(); |
70
|
|
|
$this->configCache = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Config\ConfigCache') |
71
|
|
|
->disableOriginalConstructor() |
72
|
|
|
->getMock(); |
73
|
|
|
|
74
|
|
|
$this->configManager = new ConfigManager( |
75
|
|
|
$this->eventDispatcher, |
76
|
|
|
$this->metadataFactory, |
77
|
|
|
$this->modelManager, |
78
|
|
|
$this->auditManager, |
79
|
|
|
$this->configCache |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$this->configManager->addProvider($this->configProvider); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testGetProviders() |
86
|
|
|
{ |
87
|
|
|
$providers = $this->configManager->getProviders(); |
88
|
|
|
$this->assertCount(1, $providers); |
89
|
|
|
$this->assertSame($this->configProvider, $providers['entity']); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testGetProvider() |
93
|
|
|
{ |
94
|
|
|
$this->assertSame($this->configProvider, $this->configManager->getProvider('entity')); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testGetEventDispatcher() |
98
|
|
|
{ |
99
|
|
|
$this->assertSame($this->eventDispatcher, $this->configManager->getEventDispatcher()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
View Code Duplication |
public function testGetEntityMetadata() |
103
|
|
|
{ |
104
|
|
|
$this->assertNull($this->configManager->getEntityMetadata('SomeUndefinedClass')); |
105
|
|
|
|
106
|
|
|
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS); |
107
|
|
|
|
108
|
|
|
$this->metadataFactory->expects($this->once()) |
109
|
|
|
->method('getMetadataForClass') |
110
|
|
|
->with(self::ENTITY_CLASS) |
111
|
|
|
->willReturn($metadata); |
112
|
|
|
|
113
|
|
|
$this->assertSame($metadata, $this->configManager->getEntityMetadata(self::ENTITY_CLASS)); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testGetFieldMetadata() |
117
|
|
|
{ |
118
|
|
|
$this->assertNull($this->configManager->getFieldMetadata('SomeUndefinedClass', 'entity')); |
119
|
|
|
|
120
|
|
|
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS); |
121
|
|
|
$idFieldMetadata = $this->getFieldMetadata(self::ENTITY_CLASS, 'id'); |
122
|
|
|
$metadata->addPropertyMetadata($idFieldMetadata); |
123
|
|
|
|
124
|
|
|
$this->metadataFactory->expects($this->exactly(2)) |
125
|
|
|
->method('getMetadataForClass') |
126
|
|
|
->with(self::ENTITY_CLASS) |
127
|
|
|
->willReturn($metadata); |
128
|
|
|
|
129
|
|
|
$this->assertNull($this->configManager->getFieldMetadata(self::ENTITY_CLASS, 'undefinedField')); |
130
|
|
|
|
131
|
|
|
$this->assertSame( |
132
|
|
|
$metadata->propertyMetadata['id'], |
133
|
|
|
$this->configManager->getFieldMetadata(self::ENTITY_CLASS, 'id') |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @dataProvider hasConfigProvider |
139
|
|
|
*/ |
140
|
|
|
public function testHasConfig( |
141
|
|
|
$expectedResult, |
142
|
|
|
$checkDatabaseResult, |
143
|
|
|
$cachedResult, |
144
|
|
|
$findModelResult, |
145
|
|
|
$className, |
146
|
|
|
$fieldName |
147
|
|
|
) { |
148
|
|
|
$this->modelManager->expects($this->any()) |
149
|
|
|
->method('checkDatabase') |
150
|
|
|
->willReturn($checkDatabaseResult); |
151
|
|
|
if ($checkDatabaseResult) { |
152
|
|
|
$this->configCache->expects($this->once()) |
153
|
|
|
->method('getConfigurable') |
154
|
|
|
->with($className, $fieldName) |
155
|
|
|
->willReturn($cachedResult); |
156
|
|
|
if (null === $cachedResult) { |
157
|
|
|
$this->configCache->expects($this->once()) |
158
|
|
|
->method('saveConfigurable') |
159
|
|
|
->with($expectedResult, $className, $fieldName); |
160
|
|
|
if ($fieldName) { |
161
|
|
|
$this->modelManager->expects($this->once()) |
162
|
|
|
->method('findFieldModel') |
163
|
|
|
->with($className, $fieldName) |
164
|
|
|
->willReturn($findModelResult); |
165
|
|
|
} else { |
166
|
|
|
$this->modelManager->expects($this->once()) |
167
|
|
|
->method('findEntityModel') |
168
|
|
|
->with($className) |
169
|
|
|
->willReturn($findModelResult); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$result = $this->configManager->hasConfig($className, $fieldName); |
175
|
|
|
$this->assertEquals($expectedResult, $result); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function hasConfigProvider() |
179
|
|
|
{ |
180
|
|
|
return [ |
181
|
|
|
'no database' => [ |
182
|
|
|
'expectedResult' => false, |
183
|
|
|
'checkDatabaseResult' => false, |
184
|
|
|
'cachedResult' => null, |
185
|
|
|
'findModelResult' => null, |
186
|
|
|
'className' => self::ENTITY_CLASS, |
187
|
|
|
'fieldName' => null |
188
|
|
|
], |
189
|
|
|
'no database (field)' => [ |
190
|
|
|
'expectedResult' => false, |
191
|
|
|
'checkDatabaseResult' => false, |
192
|
|
|
'cachedResult' => null, |
193
|
|
|
'findModelResult' => null, |
194
|
|
|
'className' => self::ENTITY_CLASS, |
195
|
|
|
'fieldName' => 'id' |
196
|
|
|
], |
197
|
|
|
'cached false' => [ |
198
|
|
|
'expectedResult' => false, |
199
|
|
|
'checkDatabaseResult' => true, |
200
|
|
|
'cachedResult' => false, |
201
|
|
|
'findModelResult' => null, |
202
|
|
|
'className' => self::ENTITY_CLASS, |
203
|
|
|
'fieldName' => null |
204
|
|
|
], |
205
|
|
|
'cached false (field)' => [ |
206
|
|
|
'expectedResult' => false, |
207
|
|
|
'checkDatabaseResult' => true, |
208
|
|
|
'cachedResult' => false, |
209
|
|
|
'findModelResult' => null, |
210
|
|
|
'className' => self::ENTITY_CLASS, |
211
|
|
|
'fieldName' => 'id' |
212
|
|
|
], |
213
|
|
|
'cached true' => [ |
214
|
|
|
'expectedResult' => true, |
215
|
|
|
'checkDatabaseResult' => true, |
216
|
|
|
'cachedResult' => true, |
217
|
|
|
'findModelResult' => null, |
218
|
|
|
'className' => self::ENTITY_CLASS, |
219
|
|
|
'fieldName' => null |
220
|
|
|
], |
221
|
|
|
'cached true (field)' => [ |
222
|
|
|
'expectedResult' => true, |
223
|
|
|
'checkDatabaseResult' => true, |
224
|
|
|
'cachedResult' => true, |
225
|
|
|
'findModelResult' => null, |
226
|
|
|
'className' => self::ENTITY_CLASS, |
227
|
|
|
'fieldName' => 'id' |
228
|
|
|
], |
229
|
|
|
'no model' => [ |
230
|
|
|
'expectedResult' => false, |
231
|
|
|
'checkDatabaseResult' => true, |
232
|
|
|
'cachedResult' => null, |
233
|
|
|
'findModelResult' => null, |
234
|
|
|
'className' => self::ENTITY_CLASS, |
235
|
|
|
'fieldName' => null |
236
|
|
|
], |
237
|
|
|
'no model (field)' => [ |
238
|
|
|
'expectedResult' => false, |
239
|
|
|
'checkDatabaseResult' => true, |
240
|
|
|
'cachedResult' => null, |
241
|
|
|
'findModelResult' => null, |
242
|
|
|
'className' => self::ENTITY_CLASS, |
243
|
|
|
'fieldName' => 'id' |
244
|
|
|
], |
245
|
|
|
'has model' => [ |
246
|
|
|
'expectedResult' => true, |
247
|
|
|
'checkDatabaseResult' => true, |
248
|
|
|
'cachedResult' => null, |
249
|
|
|
'findModelResult' => $this->createEntityConfigModel(self::ENTITY_CLASS), |
250
|
|
|
'className' => self::ENTITY_CLASS, |
251
|
|
|
'fieldName' => null |
252
|
|
|
], |
253
|
|
|
'has model (field)' => [ |
254
|
|
|
'expectedResult' => true, |
255
|
|
|
'checkDatabaseResult' => true, |
256
|
|
|
'cachedResult' => null, |
257
|
|
|
'findModelResult' => $this->createFieldConfigModel( |
258
|
|
|
$this->createEntityConfigModel(self::ENTITY_CLASS), |
259
|
|
|
'id', |
260
|
|
|
'int' |
261
|
|
|
), |
262
|
|
|
'className' => self::ENTITY_CLASS, |
263
|
|
|
'fieldName' => 'id' |
264
|
|
|
], |
265
|
|
|
]; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @expectedException \Oro\Bundle\EntityConfigBundle\Exception\LogicException |
270
|
|
|
*/ |
271
|
|
|
public function testGetConfigNoDatabase() |
272
|
|
|
{ |
273
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
274
|
|
|
$this->modelManager->expects($this->any()) |
275
|
|
|
->method('checkDatabase') |
276
|
|
|
->willReturn(false); |
277
|
|
|
$this->configManager->getConfig($configId); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @expectedException \Oro\Bundle\EntityConfigBundle\Exception\RuntimeException |
282
|
|
|
*/ |
283
|
|
|
public function testGetConfigForNotConfigurable() |
284
|
|
|
{ |
285
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
286
|
|
|
$this->modelManager->expects($this->any()) |
287
|
|
|
->method('checkDatabase') |
288
|
|
|
->willReturn(true); |
289
|
|
|
$this->configCache->expects($this->once()) |
290
|
|
|
->method('getConfigurable') |
291
|
|
|
->with(self::ENTITY_CLASS) |
292
|
|
|
->willReturn(false); |
293
|
|
|
$this->configManager->getConfig($configId); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
public function testGetConfigForNewEntity() |
297
|
|
|
{ |
298
|
|
|
$configId = new EntityConfigId('entity'); |
299
|
|
|
|
300
|
|
|
$this->modelManager->expects($this->never()) |
301
|
|
|
->method('checkDatabase'); |
302
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
303
|
|
|
$propertyConfigContainer->expects($this->once()) |
304
|
|
|
->method('getDefaultValues') |
305
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
306
|
|
|
->willReturn(['translatable' => 'labelVal', 'other' => 'otherVal']); |
307
|
|
|
$propertyConfigContainer->expects($this->never()) |
308
|
|
|
->method('getTranslatableValues'); |
309
|
|
|
$this->configProvider->expects($this->any()) |
310
|
|
|
->method('getPropertyConfig') |
311
|
|
|
->willReturn($propertyConfigContainer); |
312
|
|
|
|
313
|
|
|
$config = $this->configManager->getConfig($configId); |
314
|
|
|
|
315
|
|
|
$expectedConfig = $this->getConfig( |
316
|
|
|
$configId, |
317
|
|
|
[ |
318
|
|
|
'translatable' => 'labelVal', |
319
|
|
|
'other' => 'otherVal' |
320
|
|
|
] |
321
|
|
|
); |
322
|
|
|
|
323
|
|
|
$this->assertEquals($expectedConfig, $config); |
324
|
|
|
$this->configManager->calculateConfigChangeSet($config); |
325
|
|
|
$this->assertEquals( |
326
|
|
|
[ |
327
|
|
|
'translatable' => [null, 'labelVal'], |
328
|
|
|
'other' => [null, 'otherVal'] |
329
|
|
|
], |
330
|
|
|
$this->configManager->getConfigChangeSet($config) |
331
|
|
|
); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @dataProvider getConfigCacheProvider |
336
|
|
|
*/ |
337
|
|
|
public function testGetConfigCache(ConfigIdInterface $configId, $cachedConfig) |
338
|
|
|
{ |
339
|
|
|
if ($configId instanceof FieldConfigId) { |
340
|
|
|
$this->configCache->expects($this->once()) |
341
|
|
|
->method('getFieldConfig') |
342
|
|
|
->with($configId->getScope(), $configId->getClassName(), $configId->getFieldName()) |
343
|
|
|
->willReturn($cachedConfig); |
344
|
|
|
} else { |
345
|
|
|
$this->configCache->expects($this->once()) |
346
|
|
|
->method('getEntityConfig') |
347
|
|
|
->with($configId->getScope(), $configId->getClassName()) |
348
|
|
|
->willReturn($cachedConfig); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
$this->modelManager->expects($this->never()) |
352
|
|
|
->method('checkDatabase'); |
353
|
|
|
$this->configCache->expects($this->never()) |
354
|
|
|
->method('getConfigurable'); |
355
|
|
|
$this->modelManager->expects($this->never()) |
356
|
|
|
->method('getEntityModel'); |
357
|
|
|
$this->modelManager->expects($this->never()) |
358
|
|
|
->method('getFieldModel'); |
359
|
|
|
|
360
|
|
|
$result = $this->configManager->getConfig($configId); |
361
|
|
|
|
362
|
|
|
$this->assertSame($cachedConfig, $result); |
363
|
|
|
$this->configManager->calculateConfigChangeSet($result); |
364
|
|
|
$this->assertEquals( |
365
|
|
|
[], |
366
|
|
|
$this->configManager->getConfigChangeSet($result) |
367
|
|
|
); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
public function getConfigCacheProvider() |
371
|
|
|
{ |
372
|
|
|
return [ |
373
|
|
|
'entity' => [ |
374
|
|
|
new EntityConfigId('entity', self::ENTITY_CLASS), |
375
|
|
|
$this->getConfig(new EntityConfigId('entity', self::ENTITY_CLASS)) |
376
|
|
|
], |
377
|
|
|
'field' => [ |
378
|
|
|
new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int'), |
379
|
|
|
$this->getConfig(new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int')) |
380
|
|
|
], |
381
|
|
|
]; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @dataProvider getConfigNotCachedProvider |
386
|
|
|
*/ |
387
|
|
|
public function testGetConfigNotCached(ConfigIdInterface $configId, $getModelResult, $expectedConfig) |
388
|
|
|
{ |
389
|
|
|
$this->modelManager->expects($this->any()) |
390
|
|
|
->method('checkDatabase') |
391
|
|
|
->willReturn(true); |
392
|
|
|
if ($configId instanceof FieldConfigId) { |
393
|
|
|
$this->configCache->expects($this->exactly(2)) |
394
|
|
|
->method('getConfigurable') |
395
|
|
|
->willReturnMap( |
396
|
|
|
[ |
397
|
|
|
[$configId->getClassName(), null, true], |
398
|
|
|
[$configId->getClassName(), $configId->getFieldName(), true], |
399
|
|
|
] |
400
|
|
|
); |
401
|
|
|
$this->configCache->expects($this->once()) |
402
|
|
|
->method('getFieldConfig') |
403
|
|
|
->with($configId->getScope(), $configId->getClassName(), $configId->getFieldName()) |
404
|
|
|
->willReturn(null); |
405
|
|
|
} else { |
406
|
|
|
$this->configCache->expects($this->once()) |
407
|
|
|
->method('getConfigurable') |
408
|
|
|
->with($configId->getClassName()) |
409
|
|
|
->willReturn(true); |
410
|
|
|
$this->configCache->expects($this->once()) |
411
|
|
|
->method('getEntityConfig') |
412
|
|
|
->with($configId->getScope(), $configId->getClassName()) |
413
|
|
|
->willReturn(null); |
414
|
|
|
} |
415
|
|
|
$this->configCache->expects($this->once()) |
416
|
|
|
->method('saveConfig') |
417
|
|
|
->with($this->equalTo($expectedConfig)); |
418
|
|
|
if ($configId instanceof FieldConfigId) { |
419
|
|
|
$this->modelManager->expects($this->never()) |
420
|
|
|
->method('getEntityModel'); |
421
|
|
|
$this->modelManager->expects($this->once()) |
422
|
|
|
->method('getFieldModel') |
423
|
|
|
->with($configId->getClassName(), $configId->getFieldName()) |
424
|
|
|
->willReturn($getModelResult); |
425
|
|
|
} else { |
426
|
|
|
$this->modelManager->expects($this->once()) |
427
|
|
|
->method('getEntityModel') |
428
|
|
|
->with($configId->getClassName()) |
429
|
|
|
->willReturn($getModelResult); |
430
|
|
|
$this->modelManager->expects($this->never()) |
431
|
|
|
->method('getFieldModel'); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
$result = $this->configManager->getConfig($configId); |
435
|
|
|
|
436
|
|
|
$this->assertEquals($expectedConfig, $result); |
437
|
|
|
$this->configManager->calculateConfigChangeSet($result); |
438
|
|
|
$this->assertEquals( |
439
|
|
|
[], |
440
|
|
|
$this->configManager->getConfigChangeSet($result) |
441
|
|
|
); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function getConfigNotCachedProvider() |
445
|
|
|
{ |
446
|
|
|
return [ |
447
|
|
|
'entity' => [ |
448
|
|
|
new EntityConfigId('entity', self::ENTITY_CLASS), |
449
|
|
|
$this->createEntityConfigModel(self::ENTITY_CLASS), |
450
|
|
|
$this->getConfig(new EntityConfigId('entity', self::ENTITY_CLASS)) |
451
|
|
|
], |
452
|
|
|
'field' => [ |
453
|
|
|
new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int'), |
454
|
|
|
$this->createFieldConfigModel( |
455
|
|
|
$this->createEntityConfigModel(self::ENTITY_CLASS), |
456
|
|
|
'id', |
457
|
|
|
'int' |
458
|
|
|
), |
459
|
|
|
$this->getConfig(new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int')) |
460
|
|
|
], |
461
|
|
|
]; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
public function testConfigChangeSet() |
465
|
|
|
{ |
466
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
467
|
|
|
$originalConfig = $this->getConfig( |
468
|
|
|
$configId, |
469
|
|
|
[ |
470
|
|
|
'item1' => true, |
471
|
|
|
'item11' => true, |
472
|
|
|
'item12' => true, |
473
|
|
|
'item2' => 123, |
474
|
|
|
'item21' => 123, |
475
|
|
|
'item22' => 123, |
476
|
|
|
'item3' => 'val2', |
477
|
|
|
'item4' => 'val4', |
478
|
|
|
'item6' => null, |
479
|
|
|
'item7' => 'val7' |
480
|
|
|
] |
481
|
|
|
); |
482
|
|
|
$this->configCache->expects($this->once()) |
483
|
|
|
->method('getEntityConfig') |
484
|
|
|
->willReturn($originalConfig); |
485
|
|
|
$this->configManager->getConfig($configId); |
486
|
|
|
|
487
|
|
|
$changedConfig = $this->getConfig( |
488
|
|
|
$configId, |
489
|
|
|
[ |
490
|
|
|
'item1' => true, |
491
|
|
|
'item11' => 1, |
492
|
|
|
'item12' => false, |
493
|
|
|
'item2' => 123, |
494
|
|
|
'item21' => '123', |
495
|
|
|
'item22' => 456, |
496
|
|
|
'item3' => 'val21', |
497
|
|
|
'item5' => 'val5', |
498
|
|
|
'item6' => 'val6', |
499
|
|
|
'item7' => null |
500
|
|
|
] |
501
|
|
|
); |
502
|
|
|
$this->configManager->persist($changedConfig); |
503
|
|
|
|
504
|
|
|
$this->configManager->calculateConfigChangeSet($changedConfig); |
505
|
|
|
$this->assertEquals( |
506
|
|
|
[ |
507
|
|
|
'item12' => [true, false], |
508
|
|
|
'item22' => [123, 456], |
509
|
|
|
'item3' => ['val2', 'val21'], |
510
|
|
|
'item5' => [null, 'val5'], |
511
|
|
|
'item6' => [null, 'val6'], |
512
|
|
|
'item7' => ['val7', null] |
513
|
|
|
], |
514
|
|
|
$this->configManager->getConfigChangeSet($changedConfig) |
515
|
|
|
); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
public function testGetIdsNoDatabase() |
519
|
|
|
{ |
520
|
|
|
$this->modelManager->expects($this->any()) |
521
|
|
|
->method('checkDatabase') |
522
|
|
|
->willReturn(false); |
523
|
|
|
$result = $this->configManager->getIds('entity'); |
524
|
|
|
$this->assertEquals([], $result); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
/** |
528
|
|
|
* @dataProvider getIdsProvider |
529
|
|
|
*/ |
530
|
|
|
public function testGetIds($scope, $className, $withHidden, $expectedIds) |
531
|
|
|
{ |
532
|
|
|
$models = [ |
533
|
|
|
$this->createEntityConfigModel('EntityClass1'), |
534
|
|
|
$this->createEntityConfigModel('EntityClass2'), |
535
|
|
|
$this->createEntityConfigModel('HiddenEntity', ConfigModel::MODE_HIDDEN), |
536
|
|
|
]; |
537
|
|
|
$entityModel = $this->createEntityConfigModel('EntityClass1'); |
538
|
|
|
$fieldModels = [ |
539
|
|
|
$this->createFieldConfigModel($entityModel, 'f1', 'int'), |
540
|
|
|
$this->createFieldConfigModel($entityModel, 'f2', 'int'), |
541
|
|
|
$this->createFieldConfigModel($entityModel, 'hiddenField', 'int', ConfigModel::MODE_HIDDEN), |
542
|
|
|
]; |
543
|
|
|
|
544
|
|
|
$this->modelManager->expects($this->any()) |
545
|
|
|
->method('checkDatabase') |
546
|
|
|
->willReturn(true); |
547
|
|
|
$this->modelManager->expects($this->once()) |
548
|
|
|
->method('getModels') |
549
|
|
|
->with($className) |
550
|
|
|
->willReturn($className ? $fieldModels : $models); |
551
|
|
|
|
552
|
|
|
$result = $this->configManager->getIds($scope, $className, $withHidden); |
553
|
|
|
$this->assertEquals($expectedIds, array_values($result)); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
public function getIdsProvider() |
557
|
|
|
{ |
558
|
|
|
return [ |
559
|
|
|
[ |
560
|
|
|
'entity', |
561
|
|
|
null, |
562
|
|
|
true, |
563
|
|
|
[ |
564
|
|
|
new EntityConfigId('entity', 'EntityClass1'), |
565
|
|
|
new EntityConfigId('entity', 'EntityClass2'), |
566
|
|
|
new EntityConfigId('entity', 'HiddenEntity'), |
567
|
|
|
] |
568
|
|
|
], |
569
|
|
|
[ |
570
|
|
|
'entity', |
571
|
|
|
null, |
572
|
|
|
false, |
573
|
|
|
[ |
574
|
|
|
new EntityConfigId('entity', 'EntityClass1'), |
575
|
|
|
new EntityConfigId('entity', 'EntityClass2'), |
576
|
|
|
] |
577
|
|
|
], |
578
|
|
|
[ |
579
|
|
|
'entity', |
580
|
|
|
'EntityClass1', |
581
|
|
|
true, |
582
|
|
|
[ |
583
|
|
|
new FieldConfigId('entity', 'EntityClass1', 'f1', 'int'), |
584
|
|
|
new FieldConfigId('entity', 'EntityClass1', 'f2', 'int'), |
585
|
|
|
new FieldConfigId('entity', 'EntityClass1', 'hiddenField', 'int'), |
586
|
|
|
] |
587
|
|
|
], |
588
|
|
|
[ |
589
|
|
|
'entity', |
590
|
|
|
'EntityClass1', |
591
|
|
|
false, |
592
|
|
|
[ |
593
|
|
|
new FieldConfigId('entity', 'EntityClass1', 'f1', 'int'), |
594
|
|
|
new FieldConfigId('entity', 'EntityClass1', 'f2', 'int'), |
595
|
|
|
] |
596
|
|
|
], |
597
|
|
|
]; |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
/** |
601
|
|
|
* @dataProvider getConfigsProvider |
602
|
|
|
*/ |
603
|
|
|
public function testGetConfigs($scope, $className, $withHidden, $expectedConfigs) |
604
|
|
|
{ |
605
|
|
|
$models = [ |
606
|
|
|
$this->createEntityConfigModel('EntityClass1'), |
607
|
|
|
$this->createEntityConfigModel('EntityClass2'), |
608
|
|
|
$this->createEntityConfigModel('HiddenEntity', ConfigModel::MODE_HIDDEN), |
609
|
|
|
]; |
610
|
|
|
$entityModel = $this->createEntityConfigModel('EntityClass1'); |
611
|
|
|
$fieldModels = [ |
612
|
|
|
$this->createFieldConfigModel($entityModel, 'f1', 'int'), |
613
|
|
|
$this->createFieldConfigModel($entityModel, 'f2', 'int'), |
614
|
|
|
$this->createFieldConfigModel($entityModel, 'hiddenField', 'int', ConfigModel::MODE_HIDDEN), |
615
|
|
|
]; |
616
|
|
|
|
617
|
|
|
$this->modelManager->expects($this->any()) |
618
|
|
|
->method('checkDatabase') |
619
|
|
|
->willReturn(true); |
620
|
|
|
$this->configCache->expects($this->any()) |
621
|
|
|
->method('getConfigurable') |
622
|
|
|
->willReturn(true); |
623
|
|
|
$this->modelManager->expects($this->once()) |
624
|
|
|
->method('getModels') |
625
|
|
|
->with($className) |
626
|
|
|
->willReturn($className ? $fieldModels : $models); |
627
|
|
|
if ($className) { |
628
|
|
|
$this->modelManager->expects($this->any()) |
629
|
|
|
->method('getFieldModel') |
630
|
|
|
->willReturnMap( |
631
|
|
|
[ |
632
|
|
|
[$className, 'f1', $fieldModels[0]], |
633
|
|
|
[$className, 'f2', $fieldModels[1]], |
634
|
|
|
[$className, 'hiddenField', $fieldModels[2]], |
635
|
|
|
] |
636
|
|
|
); |
637
|
|
|
} else { |
638
|
|
|
$this->modelManager->expects($this->any()) |
639
|
|
|
->method('getEntityModel') |
640
|
|
|
->willReturnMap( |
641
|
|
|
[ |
642
|
|
|
['EntityClass1', $models[0]], |
643
|
|
|
['EntityClass2', $models[1]], |
644
|
|
|
['HiddenEntity', $models[2]], |
645
|
|
|
] |
646
|
|
|
); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
$result = $this->configManager->getConfigs($scope, $className, $withHidden); |
650
|
|
|
$this->assertEquals($expectedConfigs, array_values($result)); |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
public function getConfigsProvider() |
654
|
|
|
{ |
655
|
|
|
return [ |
656
|
|
|
[ |
657
|
|
|
'entity', |
658
|
|
|
null, |
659
|
|
|
true, |
660
|
|
|
[ |
661
|
|
|
$this->getConfig(new EntityConfigId('entity', 'EntityClass1')), |
662
|
|
|
$this->getConfig(new EntityConfigId('entity', 'EntityClass2')), |
663
|
|
|
$this->getConfig(new EntityConfigId('entity', 'HiddenEntity')), |
664
|
|
|
] |
665
|
|
|
], |
666
|
|
|
[ |
667
|
|
|
'entity', |
668
|
|
|
null, |
669
|
|
|
false, |
670
|
|
|
[ |
671
|
|
|
$this->getConfig(new EntityConfigId('entity', 'EntityClass1')), |
672
|
|
|
$this->getConfig(new EntityConfigId('entity', 'EntityClass2')), |
673
|
|
|
] |
674
|
|
|
], |
675
|
|
|
[ |
676
|
|
|
'entity', |
677
|
|
|
'EntityClass1', |
678
|
|
|
true, |
679
|
|
|
[ |
680
|
|
|
$this->getConfig(new FieldConfigId('entity', 'EntityClass1', 'f1', 'int')), |
681
|
|
|
$this->getConfig(new FieldConfigId('entity', 'EntityClass1', 'f2', 'int')), |
682
|
|
|
$this->getConfig(new FieldConfigId('entity', 'EntityClass1', 'hiddenField', 'int')), |
683
|
|
|
] |
684
|
|
|
], |
685
|
|
|
[ |
686
|
|
|
'entity', |
687
|
|
|
'EntityClass1', |
688
|
|
|
false, |
689
|
|
|
[ |
690
|
|
|
$this->getConfig(new FieldConfigId('entity', 'EntityClass1', 'f1', 'int')), |
691
|
|
|
$this->getConfig(new FieldConfigId('entity', 'EntityClass1', 'f2', 'int')), |
692
|
|
|
] |
693
|
|
|
], |
694
|
|
|
]; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
View Code Duplication |
public function testClearEntityCache() |
698
|
|
|
{ |
699
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
700
|
|
|
$this->configCache->expects($this->once()) |
701
|
|
|
->method('deleteEntityConfig') |
702
|
|
|
->with($configId->getClassName()); |
703
|
|
|
$this->configManager->clearCache($configId); |
704
|
|
|
} |
705
|
|
|
|
706
|
|
View Code Duplication |
public function testClearFieldCache() |
707
|
|
|
{ |
708
|
|
|
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'field'); |
709
|
|
|
$this->configCache->expects($this->once()) |
710
|
|
|
->method('deleteFieldConfig') |
711
|
|
|
->with($configId->getClassName(), $configId->getFieldName()); |
712
|
|
|
$this->configManager->clearCache($configId); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
public function testClearCacheAll() |
716
|
|
|
{ |
717
|
|
|
$this->configCache->expects($this->once()) |
718
|
|
|
->method('deleteAllConfigs'); |
719
|
|
|
$this->configManager->clearCache(); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
public function testClearConfigurableCache() |
723
|
|
|
{ |
724
|
|
|
$this->configCache->expects($this->once()) |
725
|
|
|
->method('deleteAllConfigurable'); |
726
|
|
|
$this->modelManager->expects($this->once()) |
727
|
|
|
->method('clearCheckDatabase'); |
728
|
|
|
$this->configManager->clearConfigurableCache(); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
View Code Duplication |
public function testHasConfigEntityModelWithNoModel() |
732
|
|
|
{ |
733
|
|
|
$this->modelManager->expects($this->once()) |
734
|
|
|
->method('findEntityModel') |
735
|
|
|
->with(self::ENTITY_CLASS) |
736
|
|
|
->willReturn(null); |
737
|
|
|
|
738
|
|
|
$result = $this->configManager->hasConfigEntityModel(self::ENTITY_CLASS); |
739
|
|
|
$this->assertFalse($result); |
740
|
|
|
} |
741
|
|
|
|
742
|
|
View Code Duplication |
public function testHasConfigEntityModel() |
743
|
|
|
{ |
744
|
|
|
$this->modelManager->expects($this->once()) |
745
|
|
|
->method('findEntityModel') |
746
|
|
|
->with(self::ENTITY_CLASS) |
747
|
|
|
->willReturn($this->createEntityConfigModel(self::ENTITY_CLASS)); |
748
|
|
|
|
749
|
|
|
$result = $this->configManager->hasConfigEntityModel(self::ENTITY_CLASS); |
750
|
|
|
$this->assertTrue($result); |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
public function testHasConfigFieldModelWithNoModel() |
754
|
|
|
{ |
755
|
|
|
$this->modelManager->expects($this->once()) |
756
|
|
|
->method('findFieldModel') |
757
|
|
|
->with(self::ENTITY_CLASS, 'id') |
758
|
|
|
->willReturn(null); |
759
|
|
|
|
760
|
|
|
$result = $this->configManager->hasConfigFieldModel(self::ENTITY_CLASS, 'id'); |
761
|
|
|
$this->assertFalse($result); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
public function testHasConfigFieldModel() |
765
|
|
|
{ |
766
|
|
|
$this->modelManager->expects($this->once()) |
767
|
|
|
->method('findFieldModel') |
768
|
|
|
->with(self::ENTITY_CLASS, 'id') |
769
|
|
|
->willReturn( |
770
|
|
|
$this->createFieldConfigModel( |
771
|
|
|
$this->createEntityConfigModel(self::ENTITY_CLASS), |
772
|
|
|
'id', |
773
|
|
|
'int' |
774
|
|
|
) |
775
|
|
|
); |
776
|
|
|
|
777
|
|
|
$result = $this->configManager->hasConfigFieldModel(self::ENTITY_CLASS, 'id'); |
778
|
|
|
$this->assertTrue($result); |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
public function testGetConfigEntityModel() |
782
|
|
|
{ |
783
|
|
|
$model = $this->createEntityConfigModel(self::ENTITY_CLASS); |
784
|
|
|
|
785
|
|
|
$this->modelManager->expects($this->once()) |
786
|
|
|
->method('findEntityModel') |
787
|
|
|
->with(self::ENTITY_CLASS) |
788
|
|
|
->willReturn($model); |
789
|
|
|
|
790
|
|
|
$result = $this->configManager->getConfigEntityModel(self::ENTITY_CLASS); |
791
|
|
|
$this->assertSame($model, $result); |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
public function testGetConfigFieldModel() |
795
|
|
|
{ |
796
|
|
|
$model = $this->createFieldConfigModel( |
797
|
|
|
$this->createEntityConfigModel(self::ENTITY_CLASS), |
798
|
|
|
'id', |
799
|
|
|
'int' |
800
|
|
|
); |
801
|
|
|
|
802
|
|
|
$this->modelManager->expects($this->once()) |
803
|
|
|
->method('findFieldModel') |
804
|
|
|
->with(self::ENTITY_CLASS, 'id') |
805
|
|
|
->willReturn($model); |
806
|
|
|
|
807
|
|
|
$result = $this->configManager->getConfigFieldModel(self::ENTITY_CLASS, 'id'); |
808
|
|
|
$this->assertSame($model, $result); |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
/** |
812
|
|
|
* @dataProvider emptyNameProvider |
813
|
|
|
*/ |
814
|
|
|
public function testCreateConfigEntityModelForEmptyClassName($className) |
815
|
|
|
{ |
816
|
|
|
$model = $this->createEntityConfigModel($className); |
817
|
|
|
|
818
|
|
|
$this->modelManager->expects($this->never()) |
819
|
|
|
->method('findEntityModel'); |
820
|
|
|
$this->modelManager->expects($this->once()) |
821
|
|
|
->method('createEntityModel') |
822
|
|
|
->with($className, ConfigModel::MODE_DEFAULT) |
823
|
|
|
->willReturn($model); |
824
|
|
|
|
825
|
|
|
$result = $this->configManager->createConfigEntityModel($className); |
826
|
|
|
$this->assertSame($model, $result); |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
/** |
830
|
|
|
* @dataProvider emptyNameProvider |
831
|
|
|
*/ |
832
|
|
|
public function testCreateConfigEntityModelForEmptyClassNameAndMode($className) |
833
|
|
|
{ |
834
|
|
|
$mode = ConfigModel::MODE_HIDDEN; |
835
|
|
|
$model = $this->createEntityConfigModel($className, $mode); |
836
|
|
|
|
837
|
|
|
$this->modelManager->expects($this->never()) |
838
|
|
|
->method('findEntityModel'); |
839
|
|
|
$this->modelManager->expects($this->once()) |
840
|
|
|
->method('createEntityModel') |
841
|
|
|
->with($className, $mode) |
842
|
|
|
->willReturn($model); |
843
|
|
|
|
844
|
|
|
$result = $this->configManager->createConfigEntityModel($className, $mode); |
845
|
|
|
$this->assertSame($model, $result); |
846
|
|
|
} |
847
|
|
|
|
848
|
|
View Code Duplication |
public function testCreateConfigEntityModelForExistingModel() |
849
|
|
|
{ |
850
|
|
|
$model = $this->createEntityConfigModel(self::ENTITY_CLASS); |
851
|
|
|
|
852
|
|
|
$this->modelManager->expects($this->once()) |
853
|
|
|
->method('findEntityModel') |
854
|
|
|
->with(self::ENTITY_CLASS) |
855
|
|
|
->willReturn($model); |
856
|
|
|
$this->modelManager->expects($this->never()) |
857
|
|
|
->method('createEntityModel'); |
858
|
|
|
|
859
|
|
|
$result = $this->configManager->createConfigEntityModel(self::ENTITY_CLASS); |
860
|
|
|
$this->assertSame($model, $result); |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
/** |
864
|
|
|
* @dataProvider createConfigEntityModelProvider |
865
|
|
|
*/ |
866
|
|
|
public function testCreateConfigEntityModel( |
867
|
|
|
$mode, |
868
|
|
|
$hasMetadata, |
869
|
|
|
$metadataMode, |
870
|
|
|
$expectedMode, |
871
|
|
|
$cachedEntities, |
872
|
|
|
$expectedSavedCachedEntities |
873
|
|
|
) { |
874
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
875
|
|
|
$model = $this->createEntityConfigModel(self::ENTITY_CLASS, $expectedMode); |
876
|
|
|
|
877
|
|
|
$metadata = null; |
878
|
|
|
if ($hasMetadata) { |
879
|
|
|
$metadata = $this->getEntityMetadata( |
880
|
|
|
self::ENTITY_CLASS, |
881
|
|
|
['translatable' => 'labelVal', 'other' => 'otherVal'] |
882
|
|
|
); |
883
|
|
|
if (null !== $metadataMode) { |
884
|
|
|
$metadata->mode = $metadataMode; |
885
|
|
|
} |
886
|
|
|
} |
887
|
|
|
|
888
|
|
|
$this->modelManager->expects($this->once()) |
889
|
|
|
->method('findEntityModel') |
890
|
|
|
->with(self::ENTITY_CLASS) |
891
|
|
|
->willReturn(null); |
892
|
|
|
$this->modelManager->expects($this->once()) |
893
|
|
|
->method('createEntityModel') |
894
|
|
|
->with(self::ENTITY_CLASS, $expectedMode) |
895
|
|
|
->willReturn($model); |
896
|
|
|
$this->metadataFactory->expects($this->once()) |
897
|
|
|
->method('getMetadataForClass') |
898
|
|
|
->with(self::ENTITY_CLASS) |
899
|
|
|
->willReturn($metadata); |
900
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
901
|
|
|
$propertyConfigContainer->expects($this->once()) |
902
|
|
|
->method('getDefaultValues') |
903
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
904
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
905
|
|
|
$propertyConfigContainer->expects($this->once()) |
906
|
|
|
->method('getTranslatableValues') |
907
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
908
|
|
|
->willReturn(['translatable', 'translatable10', 'auto_generated']); |
909
|
|
|
$this->configProvider->expects($this->any()) |
910
|
|
|
->method('getPropertyConfig') |
911
|
|
|
->willReturn($propertyConfigContainer); |
912
|
|
|
|
913
|
|
|
$this->eventDispatcher->expects($this->once()) |
914
|
|
|
->method('dispatch') |
915
|
|
|
->with( |
916
|
|
|
Events::CREATE_ENTITY, |
917
|
|
|
new EntityConfigEvent(self::ENTITY_CLASS, $this->configManager) |
918
|
|
|
); |
919
|
|
|
|
920
|
|
|
$config = $this->getConfig( |
921
|
|
|
$configId, |
922
|
|
|
[ |
923
|
|
|
'translatable' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_translatable', |
924
|
|
|
'other10' => 'otherVal10', |
925
|
|
|
'translatable10' => 'labelVal10', |
926
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_auto_generated' |
927
|
|
|
] |
928
|
|
|
); |
929
|
|
|
if ($metadata) { |
930
|
|
|
$config->set('other', 'otherVal'); |
931
|
|
|
$config->set('translatable', 'labelVal'); |
932
|
|
|
} |
933
|
|
|
|
934
|
|
|
$this->configCache->expects($this->once()) |
935
|
|
|
->method('saveConfig') |
936
|
|
|
->with($config, true); |
937
|
|
|
|
938
|
|
|
$this->configCache->expects($this->once()) |
939
|
|
|
->method('saveConfigurable') |
940
|
|
|
->with(true, self::ENTITY_CLASS, null, true); |
941
|
|
|
|
942
|
|
|
$this->configCache->expects($this->once()) |
943
|
|
|
->method('getEntities') |
944
|
|
|
->with(true) |
945
|
|
|
->willReturn($cachedEntities); |
946
|
|
|
if (null === $expectedSavedCachedEntities) { |
947
|
|
|
$this->configCache->expects($this->never()) |
948
|
|
|
->method('saveEntities'); |
949
|
|
|
} else { |
950
|
|
|
$this->configCache->expects($this->once()) |
951
|
|
|
->method('saveEntities') |
952
|
|
|
->with($expectedSavedCachedEntities, true); |
953
|
|
|
} |
954
|
|
|
|
955
|
|
|
$result = $this->configManager->createConfigEntityModel(self::ENTITY_CLASS, $mode); |
956
|
|
|
|
957
|
|
|
$this->assertEquals($model, $result); |
958
|
|
|
$this->assertEquals([$config], $this->configManager->getUpdateConfig()); |
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
public function createConfigEntityModelProvider() |
962
|
|
|
{ |
963
|
|
|
return [ |
964
|
|
|
[ |
965
|
|
|
'mode' => null, |
966
|
|
|
'hasMetadata' => false, |
967
|
|
|
'metadataMode' => null, |
968
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
969
|
|
|
'cachedEntities' => null, |
970
|
|
|
'expectedSavedCachedEntities' => null |
971
|
|
|
], |
972
|
|
|
[ |
973
|
|
|
'mode' => null, |
974
|
|
|
'hasMetadata' => true, |
975
|
|
|
'metadataMode' => null, |
976
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
977
|
|
|
'cachedEntities' => null, |
978
|
|
|
'expectedSavedCachedEntities' => null |
979
|
|
|
], |
980
|
|
|
[ |
981
|
|
|
'mode' => null, |
982
|
|
|
'hasMetadata' => true, |
983
|
|
|
'metadataMode' => ConfigModel::MODE_HIDDEN, |
984
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
985
|
|
|
'cachedEntities' => null, |
986
|
|
|
'expectedSavedCachedEntities' => null |
987
|
|
|
], |
988
|
|
|
[ |
989
|
|
|
'mode' => ConfigModel::MODE_HIDDEN, |
990
|
|
|
'hasMetadata' => false, |
991
|
|
|
'metadataMode' => null, |
992
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
993
|
|
|
'cachedEntities' => null, |
994
|
|
|
'expectedSavedCachedEntities' => null |
995
|
|
|
], |
996
|
|
|
[ |
997
|
|
|
'mode' => ConfigModel::MODE_HIDDEN, |
998
|
|
|
'hasMetadata' => true, |
999
|
|
|
'metadataMode' => null, |
1000
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
1001
|
|
|
'cachedEntities' => null, |
1002
|
|
|
'expectedSavedCachedEntities' => null |
1003
|
|
|
], |
1004
|
|
|
[ |
1005
|
|
|
'mode' => ConfigModel::MODE_DEFAULT, |
1006
|
|
|
'hasMetadata' => true, |
1007
|
|
|
'metadataMode' => ConfigModel::MODE_HIDDEN, |
1008
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
1009
|
|
|
'cachedEntities' => null, |
1010
|
|
|
'expectedSavedCachedEntities' => null |
1011
|
|
|
], |
1012
|
|
|
[ |
1013
|
|
|
'mode' => null, |
1014
|
|
|
'hasMetadata' => false, |
1015
|
|
|
'metadataMode' => null, |
1016
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
1017
|
|
|
'cachedEntities' => [], |
1018
|
|
|
'expectedSavedCachedEntities' => [ |
1019
|
|
|
self::ENTITY_CLASS => ['i' => null, 'h' => false] |
1020
|
|
|
] |
1021
|
|
|
], |
1022
|
|
|
[ |
1023
|
|
|
'mode' => ConfigModel::MODE_HIDDEN, |
1024
|
|
|
'hasMetadata' => false, |
1025
|
|
|
'metadataMode' => null, |
1026
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
1027
|
|
|
'cachedEntities' => [ |
1028
|
|
|
'Test\AnotherEntity' => ['i' => 123, 'h' => false] |
1029
|
|
|
], |
1030
|
|
|
'expectedSavedCachedEntities' => [ |
1031
|
|
|
'Test\AnotherEntity' => ['i' => 123, 'h' => false], |
1032
|
|
|
self::ENTITY_CLASS => ['i' => null, 'h' => true] |
1033
|
|
|
] |
1034
|
|
|
] |
1035
|
|
|
]; |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
public function testCreateConfigFieldModelForExistingModel() |
1039
|
|
|
{ |
1040
|
|
|
$model = $this->createFieldConfigModel( |
1041
|
|
|
$this->createEntityConfigModel(self::ENTITY_CLASS), |
1042
|
|
|
'id', |
1043
|
|
|
'int' |
1044
|
|
|
); |
1045
|
|
|
|
1046
|
|
|
$this->modelManager->expects($this->once()) |
1047
|
|
|
->method('findFieldModel') |
1048
|
|
|
->with(self::ENTITY_CLASS, 'id') |
1049
|
|
|
->willReturn($model); |
1050
|
|
|
$this->modelManager->expects($this->never()) |
1051
|
|
|
->method('createFieldModel'); |
1052
|
|
|
|
1053
|
|
|
$result = $this->configManager->createConfigFieldModel(self::ENTITY_CLASS, 'id', 'int'); |
1054
|
|
|
$this->assertSame($model, $result); |
1055
|
|
|
} |
1056
|
|
|
|
1057
|
|
|
/** |
1058
|
|
|
* @dataProvider createConfigFieldModelProvider |
1059
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
1060
|
|
|
*/ |
1061
|
|
|
public function testCreateConfigFieldModel( |
1062
|
|
|
$mode, |
1063
|
|
|
$hasMetadata, |
1064
|
|
|
$metadataMode, |
1065
|
|
|
$expectedMode, |
1066
|
|
|
$cachedFields, |
1067
|
|
|
$expectedSavedCachedFields |
1068
|
|
|
) { |
1069
|
|
|
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int'); |
1070
|
|
|
$model = $this->createFieldConfigModel( |
1071
|
|
|
$this->createEntityConfigModel(self::ENTITY_CLASS), |
1072
|
|
|
'id', |
1073
|
|
|
'int' |
1074
|
|
|
); |
1075
|
|
|
|
1076
|
|
|
$metadata = null; |
1077
|
|
|
if ($hasMetadata) { |
1078
|
|
|
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS); |
1079
|
|
|
$idFieldMetadata = $this->getFieldMetadata(self::ENTITY_CLASS, 'id'); |
1080
|
|
|
$idFieldMetadata->defaultValues['entity'] = ['translatable' => 'labelVal', 'other' => 'otherVal']; |
1081
|
|
|
$metadata->addPropertyMetadata($idFieldMetadata); |
1082
|
|
|
if (null !== $metadataMode) { |
1083
|
|
|
$idFieldMetadata->mode = $metadataMode; |
1084
|
|
|
} |
1085
|
|
|
} |
1086
|
|
|
|
1087
|
|
|
$this->modelManager->expects($this->once()) |
1088
|
|
|
->method('findFieldModel') |
1089
|
|
|
->with(self::ENTITY_CLASS, 'id') |
1090
|
|
|
->willReturn(null); |
1091
|
|
|
$this->modelManager->expects($this->once()) |
1092
|
|
|
->method('createFieldModel') |
1093
|
|
|
->with(self::ENTITY_CLASS, 'id', 'int', $expectedMode) |
1094
|
|
|
->willReturn($model); |
1095
|
|
|
$this->metadataFactory->expects($this->once()) |
1096
|
|
|
->method('getMetadataForClass') |
1097
|
|
|
->with(self::ENTITY_CLASS) |
1098
|
|
|
->willReturn($metadata); |
1099
|
|
|
$this->metadataFactory->expects($this->once()) |
1100
|
|
|
->method('getMetadataForClass') |
1101
|
|
|
->with(self::ENTITY_CLASS) |
1102
|
|
|
->willReturn($metadata); |
1103
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1104
|
|
|
$propertyConfigContainer->expects($this->once()) |
1105
|
|
|
->method('getDefaultValues') |
1106
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD, 'int') |
1107
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
1108
|
|
|
$propertyConfigContainer->expects($this->once()) |
1109
|
|
|
->method('getTranslatableValues') |
1110
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD) |
1111
|
|
|
->willReturn(['translatable', 'translatable10', 'auto_generated']); |
1112
|
|
|
$this->configProvider->expects($this->any()) |
1113
|
|
|
->method('getPropertyConfig') |
1114
|
|
|
->willReturn($propertyConfigContainer); |
1115
|
|
|
$this->eventDispatcher->expects($this->once()) |
1116
|
|
|
->method('dispatch') |
1117
|
|
|
->with( |
1118
|
|
|
Events::CREATE_FIELD, |
1119
|
|
|
new FieldConfigEvent(self::ENTITY_CLASS, 'id', $this->configManager) |
1120
|
|
|
); |
1121
|
|
|
|
1122
|
|
|
$config = $this->getConfig( |
1123
|
|
|
$configId, |
1124
|
|
|
[ |
1125
|
|
|
'translatable' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.translatable', |
1126
|
|
|
'other10' => 'otherVal10', |
1127
|
|
|
'translatable10' => 'labelVal10', |
1128
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated' |
1129
|
|
|
] |
1130
|
|
|
); |
1131
|
|
|
if ($metadata) { |
1132
|
|
|
$config->set('other', 'otherVal'); |
1133
|
|
|
$config->set('translatable', 'labelVal'); |
1134
|
|
|
} |
1135
|
|
|
|
1136
|
|
|
$this->configCache->expects($this->once()) |
1137
|
|
|
->method('saveConfig') |
1138
|
|
|
->with($config, true); |
1139
|
|
|
|
1140
|
|
|
$this->configCache->expects($this->once()) |
1141
|
|
|
->method('saveConfigurable') |
1142
|
|
|
->with(true, self::ENTITY_CLASS, 'id', true); |
1143
|
|
|
|
1144
|
|
|
$this->configCache->expects($this->once()) |
1145
|
|
|
->method('getFields') |
1146
|
|
|
->with(self::ENTITY_CLASS, true) |
1147
|
|
|
->willReturn($cachedFields); |
1148
|
|
|
if (null === $expectedSavedCachedFields) { |
1149
|
|
|
$this->configCache->expects($this->never()) |
1150
|
|
|
->method('saveFields'); |
1151
|
|
|
} else { |
1152
|
|
|
$this->configCache->expects($this->once()) |
1153
|
|
|
->method('saveFields') |
1154
|
|
|
->with(self::ENTITY_CLASS, $expectedSavedCachedFields, true); |
1155
|
|
|
} |
1156
|
|
|
|
1157
|
|
|
$result = $this->configManager->createConfigFieldModel(self::ENTITY_CLASS, 'id', 'int', $mode); |
1158
|
|
|
|
1159
|
|
|
$this->assertEquals($model, $result); |
1160
|
|
|
$this->assertEquals( |
1161
|
|
|
[$config], |
1162
|
|
|
$this->configManager->getUpdateConfig() |
1163
|
|
|
); |
1164
|
|
|
} |
1165
|
|
|
|
1166
|
|
|
public function createConfigFieldModelProvider() |
1167
|
|
|
{ |
1168
|
|
|
return [ |
1169
|
|
|
[ |
1170
|
|
|
'mode' => null, |
1171
|
|
|
'hasMetadata' => false, |
1172
|
|
|
'metadataMode' => null, |
1173
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
1174
|
|
|
'cachedFields' => null, |
1175
|
|
|
'expectedSavedCachedFields' => null |
1176
|
|
|
], |
1177
|
|
|
[ |
1178
|
|
|
'mode' => null, |
1179
|
|
|
'hasMetadata' => true, |
1180
|
|
|
'metadataMode' => null, |
1181
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
1182
|
|
|
'cachedFields' => null, |
1183
|
|
|
'expectedSavedCachedFields' => null |
1184
|
|
|
], |
1185
|
|
|
[ |
1186
|
|
|
'mode' => null, |
1187
|
|
|
'hasMetadata' => true, |
1188
|
|
|
'metadataMode' => ConfigModel::MODE_HIDDEN, |
1189
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
1190
|
|
|
'cachedFields' => null, |
1191
|
|
|
'expectedSavedCachedFields' => null |
1192
|
|
|
], |
1193
|
|
|
[ |
1194
|
|
|
'mode' => ConfigModel::MODE_HIDDEN, |
1195
|
|
|
'hasMetadata' => false, |
1196
|
|
|
'metadataMode' => null, |
1197
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
1198
|
|
|
'cachedFields' => null, |
1199
|
|
|
'expectedSavedCachedFields' => null |
1200
|
|
|
], |
1201
|
|
|
[ |
1202
|
|
|
'mode' => ConfigModel::MODE_HIDDEN, |
1203
|
|
|
'hasMetadata' => true, |
1204
|
|
|
'metadataMode' => null, |
1205
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
1206
|
|
|
'cachedFields' => null, |
1207
|
|
|
'expectedSavedCachedFields' => null |
1208
|
|
|
], |
1209
|
|
|
[ |
1210
|
|
|
'mode' => ConfigModel::MODE_DEFAULT, |
1211
|
|
|
'hasMetadata' => true, |
1212
|
|
|
'metadataMode' => ConfigModel::MODE_HIDDEN, |
1213
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
1214
|
|
|
'cachedFields' => null, |
1215
|
|
|
'expectedSavedCachedFields' => null |
1216
|
|
|
], |
1217
|
|
|
[ |
1218
|
|
|
'mode' => null, |
1219
|
|
|
'hasMetadata' => false, |
1220
|
|
|
'metadataMode' => null, |
1221
|
|
|
'expectedMode' => ConfigModel::MODE_DEFAULT, |
1222
|
|
|
'cachedFields' => [], |
1223
|
|
|
'expectedSavedCachedFields' => [ |
1224
|
|
|
'id' => ['i' => null, 'h' => false, 't' => 'int'] |
1225
|
|
|
] |
1226
|
|
|
], |
1227
|
|
|
[ |
1228
|
|
|
'mode' => ConfigModel::MODE_HIDDEN, |
1229
|
|
|
'hasMetadata' => false, |
1230
|
|
|
'metadataMode' => null, |
1231
|
|
|
'expectedMode' => ConfigModel::MODE_HIDDEN, |
1232
|
|
|
'cachedFields' => [ |
1233
|
|
|
'anotherField' => ['i' => 123, 'h' => false, 't' => 'string'] |
1234
|
|
|
], |
1235
|
|
|
'expectedSavedCachedFields' => [ |
1236
|
|
|
'anotherField' => ['i' => 123, 'h' => false, 't' => 'string'], |
1237
|
|
|
'id' => ['i' => null, 'h' => true, 't' => 'int'] |
1238
|
|
|
] |
1239
|
|
|
] |
1240
|
|
|
]; |
1241
|
|
|
} |
1242
|
|
|
|
1243
|
|
|
public function testUpdateConfigEntityModelWithNoForce() |
1244
|
|
|
{ |
1245
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
1246
|
|
|
$metadata = $this->getEntityMetadata( |
1247
|
|
|
self::ENTITY_CLASS, |
1248
|
|
|
[ |
1249
|
|
|
'translatable1' => 'labelVal1', |
1250
|
|
|
'other1' => 'otherVal1', |
1251
|
|
|
'translatable2' => 'labelVal2', |
1252
|
|
|
'other2' => 'otherVal2', |
1253
|
|
|
] |
1254
|
|
|
); |
1255
|
|
|
|
1256
|
|
|
$this->modelManager->expects($this->once()) |
1257
|
|
|
->method('findEntityModel') |
1258
|
|
|
->with(self::ENTITY_CLASS) |
1259
|
|
|
->willReturn($this->createEntityConfigModel(self::ENTITY_CLASS)); |
1260
|
|
|
$this->metadataFactory->expects($this->any()) |
1261
|
|
|
->method('getMetadataForClass') |
1262
|
|
|
->with(self::ENTITY_CLASS) |
1263
|
|
|
->willReturn($metadata); |
1264
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1265
|
|
|
$propertyConfigContainer->expects($this->once()) |
1266
|
|
|
->method('getDefaultValues') |
1267
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1268
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
1269
|
|
|
$propertyConfigContainer->expects($this->once()) |
1270
|
|
|
->method('getTranslatableValues') |
1271
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1272
|
|
|
->willReturn(['translatable1', 'translatable2', 'translatable10', 'auto_generated']); |
1273
|
|
|
$this->configProvider->expects($this->any()) |
1274
|
|
|
->method('getPropertyConfig') |
1275
|
|
|
->willReturn($propertyConfigContainer); |
1276
|
|
|
$config = $this->getConfig( |
1277
|
|
|
$configId, |
1278
|
|
|
[ |
1279
|
|
|
'translatable2' => 'labelVal2_old', |
1280
|
|
|
'other2' => 'otherVal2_old' |
1281
|
|
|
] |
1282
|
|
|
); |
1283
|
|
|
$this->configProvider->expects($this->once()) |
1284
|
|
|
->method('getConfig') |
1285
|
|
|
->with(self::ENTITY_CLASS) |
1286
|
|
|
->willReturn($config); |
1287
|
|
|
|
1288
|
|
|
$this->eventDispatcher->expects($this->once()) |
1289
|
|
|
->method('dispatch') |
1290
|
|
|
->with(Events::UPDATE_ENTITY); |
1291
|
|
|
|
1292
|
|
|
$expectedConfig = $this->getConfig( |
1293
|
|
|
$configId, |
1294
|
|
|
[ |
1295
|
|
|
'translatable2' => 'labelVal2_old', |
1296
|
|
|
'other2' => 'otherVal2_old', |
1297
|
|
|
'translatable10' => 'labelVal10', |
1298
|
|
|
'other10' => 'otherVal10', |
1299
|
|
|
'translatable1' => 'labelVal1', |
1300
|
|
|
'other1' => 'otherVal1', |
1301
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_auto_generated' |
1302
|
|
|
] |
1303
|
|
|
); |
1304
|
|
|
|
1305
|
|
|
$this->configManager->updateConfigEntityModel(self::ENTITY_CLASS); |
1306
|
|
|
$this->assertEquals( |
1307
|
|
|
$expectedConfig, |
1308
|
|
|
$this->configManager->getUpdateConfig()[0] |
1309
|
|
|
); |
1310
|
|
|
} |
1311
|
|
|
|
1312
|
|
|
public function testUpdateConfigEntityModelWithForce() |
1313
|
|
|
{ |
1314
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
1315
|
|
|
$metadata = $this->getEntityMetadata( |
1316
|
|
|
self::ENTITY_CLASS, |
1317
|
|
|
[ |
1318
|
|
|
'translatable1' => 'labelVal1', |
1319
|
|
|
'other1' => 'otherVal1', |
1320
|
|
|
'translatable2' => 'labelVal2', |
1321
|
|
|
'other2' => 'otherVal2', |
1322
|
|
|
] |
1323
|
|
|
); |
1324
|
|
|
|
1325
|
|
|
$this->modelManager->expects($this->once()) |
1326
|
|
|
->method('findEntityModel') |
1327
|
|
|
->with(self::ENTITY_CLASS) |
1328
|
|
|
->willReturn($this->createEntityConfigModel(self::ENTITY_CLASS)); |
1329
|
|
|
$this->metadataFactory->expects($this->any()) |
1330
|
|
|
->method('getMetadataForClass') |
1331
|
|
|
->with(self::ENTITY_CLASS) |
1332
|
|
|
->willReturn($metadata); |
1333
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1334
|
|
|
$propertyConfigContainer->expects($this->once()) |
1335
|
|
|
->method('getDefaultValues') |
1336
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1337
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
1338
|
|
|
$propertyConfigContainer->expects($this->once()) |
1339
|
|
|
->method('getTranslatableValues') |
1340
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1341
|
|
|
->willReturn(['translatable1', 'translatable2', 'translatable10', 'auto_generated']); |
1342
|
|
|
$this->configProvider->expects($this->any()) |
1343
|
|
|
->method('getPropertyConfig') |
1344
|
|
|
->willReturn($propertyConfigContainer); |
1345
|
|
|
$config = $this->getConfig( |
1346
|
|
|
$configId, |
1347
|
|
|
[ |
1348
|
|
|
'translatable2' => 'labelVal2_old', |
1349
|
|
|
'other2' => 'otherVal2_old' |
1350
|
|
|
] |
1351
|
|
|
); |
1352
|
|
|
$this->configProvider->expects($this->once()) |
1353
|
|
|
->method('getConfig') |
1354
|
|
|
->with(self::ENTITY_CLASS) |
1355
|
|
|
->willReturn($config); |
1356
|
|
|
|
1357
|
|
|
$expectedConfig = $this->getConfig( |
1358
|
|
|
$configId, |
1359
|
|
|
[ |
1360
|
|
|
'translatable2' => 'labelVal2', |
1361
|
|
|
'other2' => 'otherVal2', |
1362
|
|
|
'translatable10' => 'labelVal10', |
1363
|
|
|
'other10' => 'otherVal10', |
1364
|
|
|
'translatable1' => 'labelVal1', |
1365
|
|
|
'other1' => 'otherVal1', |
1366
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_auto_generated' |
1367
|
|
|
] |
1368
|
|
|
); |
1369
|
|
|
|
1370
|
|
|
$this->configManager->updateConfigEntityModel(self::ENTITY_CLASS, true); |
1371
|
|
|
$this->assertEquals( |
1372
|
|
|
$expectedConfig, |
1373
|
|
|
$this->configManager->getUpdateConfig()[0] |
1374
|
|
|
); |
1375
|
|
|
} |
1376
|
|
|
|
1377
|
|
|
/** |
1378
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
1379
|
|
|
*/ |
1380
|
|
|
public function testUpdateConfigEntityModelWithForceForCustomEntity() |
1381
|
|
|
{ |
1382
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
1383
|
|
|
$metadata = $this->getEntityMetadata( |
1384
|
|
|
self::ENTITY_CLASS, |
1385
|
|
|
[ |
1386
|
|
|
'translatable1' => 'labelVal1', |
1387
|
|
|
'other1' => 'otherVal1', |
1388
|
|
|
'translatable2' => 'labelVal2', |
1389
|
|
|
'other2' => 'otherVal2', |
1390
|
|
|
] |
1391
|
|
|
); |
1392
|
|
|
|
1393
|
|
|
$this->modelManager->expects($this->once()) |
1394
|
|
|
->method('findEntityModel') |
1395
|
|
|
->with(self::ENTITY_CLASS) |
1396
|
|
|
->willReturn($this->createEntityConfigModel(self::ENTITY_CLASS)); |
1397
|
|
|
$this->metadataFactory->expects($this->any()) |
1398
|
|
|
->method('getMetadataForClass') |
1399
|
|
|
->with(self::ENTITY_CLASS) |
1400
|
|
|
->willReturn($metadata); |
1401
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1402
|
|
|
$propertyConfigContainer->expects($this->once()) |
1403
|
|
|
->method('getDefaultValues') |
1404
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1405
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
1406
|
|
|
$propertyConfigContainer->expects($this->once()) |
1407
|
|
|
->method('getTranslatableValues') |
1408
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1409
|
|
|
->willReturn(['translatable1', 'translatable2', 'translatable10', 'auto_generated']); |
1410
|
|
|
$this->configProvider->expects($this->any()) |
1411
|
|
|
->method('getPropertyConfig') |
1412
|
|
|
->willReturn($propertyConfigContainer); |
1413
|
|
|
$config = $this->getConfig( |
1414
|
|
|
$configId, |
1415
|
|
|
[ |
1416
|
|
|
'translatable2' => 'labelVal2_old', |
1417
|
|
|
'other2' => 'otherVal2_old' |
1418
|
|
|
] |
1419
|
|
|
); |
1420
|
|
|
$this->configProvider->expects($this->once()) |
1421
|
|
|
->method('getConfig') |
1422
|
|
|
->with(self::ENTITY_CLASS) |
1423
|
|
|
->willReturn($config); |
1424
|
|
|
$this->eventDispatcher->expects($this->once()) |
1425
|
|
|
->method('dispatch') |
1426
|
|
|
->with(Events::UPDATE_ENTITY); |
1427
|
|
|
$extendConfig = $this->getConfig(new EntityConfigId('extend', self::ENTITY_CLASS)); |
1428
|
|
|
$extendConfig->set('owner', ExtendScope::OWNER_CUSTOM); |
1429
|
|
|
$extendConfigProvider = $this->getConfigProviderMock(); |
1430
|
|
|
$extendConfigProvider->expects($this->any()) |
1431
|
|
|
->method('getScope') |
1432
|
|
|
->willReturn('extend'); |
1433
|
|
|
$this->configManager->addProvider($extendConfigProvider); |
1434
|
|
|
$extendConfigProvider->expects($this->once()) |
1435
|
|
|
->method('hasConfig') |
1436
|
|
|
->with(self::ENTITY_CLASS) |
1437
|
|
|
->willReturn(true); |
1438
|
|
|
$extendConfigProvider->expects($this->exactly(2)) |
1439
|
|
|
->method('getConfig') |
1440
|
|
|
->with(self::ENTITY_CLASS) |
1441
|
|
|
->willReturn($extendConfig); |
1442
|
|
|
$extendPropertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1443
|
|
|
$extendPropertyConfigContainer->expects($this->once()) |
1444
|
|
|
->method('getDefaultValues') |
1445
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1446
|
|
|
->willReturn(['owner' => ExtendScope::OWNER_SYSTEM]); |
1447
|
|
|
$extendPropertyConfigContainer->expects($this->once()) |
1448
|
|
|
->method('getTranslatableValues') |
1449
|
|
|
->with(PropertyConfigContainer::TYPE_ENTITY) |
1450
|
|
|
->willReturn([]); |
1451
|
|
|
$extendConfigProvider->expects($this->any()) |
1452
|
|
|
->method('getPropertyConfig') |
1453
|
|
|
->willReturn($extendPropertyConfigContainer); |
1454
|
|
|
$extendConfigProvider->expects($this->never()) |
1455
|
|
|
->method('persist'); |
1456
|
|
|
$expectedConfig = $this->getConfig( |
1457
|
|
|
$configId, |
1458
|
|
|
[ |
1459
|
|
|
'translatable2' => 'labelVal2_old', |
1460
|
|
|
'other2' => 'otherVal2_old', |
1461
|
|
|
'translatable10' => 'labelVal10', |
1462
|
|
|
'other10' => 'otherVal10', |
1463
|
|
|
'translatable1' => 'labelVal1', |
1464
|
|
|
'other1' => 'otherVal1', |
1465
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_auto_generated' |
1466
|
|
|
] |
1467
|
|
|
); |
1468
|
|
|
|
1469
|
|
|
$this->configManager->updateConfigEntityModel(self::ENTITY_CLASS, true); |
1470
|
|
|
$this->assertEquals( |
1471
|
|
|
$expectedConfig, |
1472
|
|
|
$this->configManager->getUpdateConfig()[0] |
1473
|
|
|
); |
1474
|
|
|
} |
1475
|
|
|
|
1476
|
|
View Code Duplication |
public function testUpdateConfigFieldModelWithNoForce() |
1477
|
|
|
{ |
1478
|
|
|
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int'); |
1479
|
|
|
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS); |
1480
|
|
|
$idFieldMetadata = $this->getFieldMetadata( |
1481
|
|
|
self::ENTITY_CLASS, |
1482
|
|
|
'id', |
1483
|
|
|
[ |
1484
|
|
|
'translatable1' => 'labelVal1', |
1485
|
|
|
'other1' => 'otherVal1', |
1486
|
|
|
'translatable2' => 'labelVal2', |
1487
|
|
|
'other2' => 'otherVal2', |
1488
|
|
|
] |
1489
|
|
|
); |
1490
|
|
|
$metadata->addPropertyMetadata($idFieldMetadata); |
1491
|
|
|
|
1492
|
|
|
$this->metadataFactory->expects($this->once()) |
1493
|
|
|
->method('getMetadataForClass') |
1494
|
|
|
->with(self::ENTITY_CLASS) |
1495
|
|
|
->willReturn($metadata); |
1496
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1497
|
|
|
$propertyConfigContainer->expects($this->once()) |
1498
|
|
|
->method('getDefaultValues') |
1499
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD, 'int') |
1500
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
1501
|
|
|
$propertyConfigContainer->expects($this->once()) |
1502
|
|
|
->method('getTranslatableValues') |
1503
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD) |
1504
|
|
|
->willReturn(['translatable1', 'translatable2', 'translatable10', 'auto_generated']); |
1505
|
|
|
$this->configProvider->expects($this->any()) |
1506
|
|
|
->method('getPropertyConfig') |
1507
|
|
|
->willReturn($propertyConfigContainer); |
1508
|
|
|
$config = $this->getConfig( |
1509
|
|
|
$configId, |
1510
|
|
|
[ |
1511
|
|
|
'translatable2' => 'labelVal2_old', |
1512
|
|
|
'other2' => 'otherVal2_old' |
1513
|
|
|
] |
1514
|
|
|
); |
1515
|
|
|
$this->configProvider->expects($this->once()) |
1516
|
|
|
->method('getConfig') |
1517
|
|
|
->with(self::ENTITY_CLASS) |
1518
|
|
|
->willReturn($config); |
1519
|
|
|
|
1520
|
|
|
$expectedConfig = $this->getConfig( |
1521
|
|
|
$configId, |
1522
|
|
|
[ |
1523
|
|
|
'translatable2' => 'labelVal2_old', |
1524
|
|
|
'other2' => 'otherVal2_old', |
1525
|
|
|
'translatable10' => 'labelVal10', |
1526
|
|
|
'other10' => 'otherVal10', |
1527
|
|
|
'translatable1' => 'labelVal1', |
1528
|
|
|
'other1' => 'otherVal1', |
1529
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated' |
1530
|
|
|
] |
1531
|
|
|
); |
1532
|
|
|
|
1533
|
|
|
$this->configManager->updateConfigFieldModel(self::ENTITY_CLASS, 'id'); |
1534
|
|
|
$this->assertEquals( |
1535
|
|
|
$expectedConfig, |
1536
|
|
|
$this->configManager->getUpdateConfig()[0] |
1537
|
|
|
); |
1538
|
|
|
} |
1539
|
|
|
|
1540
|
|
View Code Duplication |
public function testUpdateConfigFieldModelWithForce() |
1541
|
|
|
{ |
1542
|
|
|
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int'); |
1543
|
|
|
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS); |
1544
|
|
|
$idFieldMetadata = $this->getFieldMetadata( |
1545
|
|
|
self::ENTITY_CLASS, |
1546
|
|
|
'id', |
1547
|
|
|
[ |
1548
|
|
|
'translatable1' => 'labelVal1', |
1549
|
|
|
'other1' => 'otherVal1', |
1550
|
|
|
'translatable2' => 'labelVal2', |
1551
|
|
|
'other2' => 'otherVal2', |
1552
|
|
|
] |
1553
|
|
|
); |
1554
|
|
|
$metadata->addPropertyMetadata($idFieldMetadata); |
1555
|
|
|
|
1556
|
|
|
$this->metadataFactory->expects($this->once()) |
1557
|
|
|
->method('getMetadataForClass') |
1558
|
|
|
->with(self::ENTITY_CLASS) |
1559
|
|
|
->willReturn($metadata); |
1560
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1561
|
|
|
$propertyConfigContainer->expects($this->once()) |
1562
|
|
|
->method('getDefaultValues') |
1563
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD, 'int') |
1564
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
1565
|
|
|
$propertyConfigContainer->expects($this->once()) |
1566
|
|
|
->method('getTranslatableValues') |
1567
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD) |
1568
|
|
|
->willReturn(['translatable1', 'translatable2', 'translatable10', 'auto_generated']); |
1569
|
|
|
$this->configProvider->expects($this->any()) |
1570
|
|
|
->method('getPropertyConfig') |
1571
|
|
|
->willReturn($propertyConfigContainer); |
1572
|
|
|
$config = $this->getConfig( |
1573
|
|
|
$configId, |
1574
|
|
|
[ |
1575
|
|
|
'translatable2' => 'labelVal2_old', |
1576
|
|
|
'other2' => 'otherVal2_old' |
1577
|
|
|
] |
1578
|
|
|
); |
1579
|
|
|
$this->configProvider->expects($this->once()) |
1580
|
|
|
->method('getConfig') |
1581
|
|
|
->with(self::ENTITY_CLASS) |
1582
|
|
|
->willReturn($config); |
1583
|
|
|
|
1584
|
|
|
$expectedConfig = $this->getConfig( |
1585
|
|
|
$configId, |
1586
|
|
|
[ |
1587
|
|
|
'translatable2' => 'labelVal2', |
1588
|
|
|
'other2' => 'otherVal2', |
1589
|
|
|
'translatable10' => 'labelVal10', |
1590
|
|
|
'other10' => 'otherVal10', |
1591
|
|
|
'translatable1' => 'labelVal1', |
1592
|
|
|
'other1' => 'otherVal1', |
1593
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated' |
1594
|
|
|
] |
1595
|
|
|
); |
1596
|
|
|
|
1597
|
|
|
$this->configManager->updateConfigFieldModel(self::ENTITY_CLASS, 'id', true); |
1598
|
|
|
$this->assertEquals( |
1599
|
|
|
$expectedConfig, |
1600
|
|
|
$this->configManager->getUpdateConfig()[0] |
1601
|
|
|
); |
1602
|
|
|
} |
1603
|
|
|
|
1604
|
|
|
public function testUpdateConfigFieldModelWithForceForCustomField() |
1605
|
|
|
{ |
1606
|
|
|
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int'); |
1607
|
|
|
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS); |
1608
|
|
|
$idFieldMetadata = $this->getFieldMetadata( |
1609
|
|
|
self::ENTITY_CLASS, |
1610
|
|
|
'id', |
1611
|
|
|
[ |
1612
|
|
|
'translatable1' => 'labelVal1', |
1613
|
|
|
'other1' => 'otherVal1', |
1614
|
|
|
'translatable2' => 'labelVal2', |
1615
|
|
|
'other2' => 'otherVal2', |
1616
|
|
|
] |
1617
|
|
|
); |
1618
|
|
|
$metadata->addPropertyMetadata($idFieldMetadata); |
1619
|
|
|
|
1620
|
|
|
$this->metadataFactory->expects($this->once()) |
1621
|
|
|
->method('getMetadataForClass') |
1622
|
|
|
->with(self::ENTITY_CLASS) |
1623
|
|
|
->willReturn($metadata); |
1624
|
|
|
$propertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1625
|
|
|
$propertyConfigContainer->expects($this->once()) |
1626
|
|
|
->method('getDefaultValues') |
1627
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD, 'int') |
1628
|
|
|
->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); |
1629
|
|
|
$propertyConfigContainer->expects($this->once()) |
1630
|
|
|
->method('getTranslatableValues') |
1631
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD) |
1632
|
|
|
->willReturn(['translatable1', 'translatable2', 'translatable10', 'auto_generated']); |
1633
|
|
|
$this->configProvider->expects($this->any()) |
1634
|
|
|
->method('getPropertyConfig') |
1635
|
|
|
->willReturn($propertyConfigContainer); |
1636
|
|
|
$config = $this->getConfig( |
1637
|
|
|
$configId, |
1638
|
|
|
[ |
1639
|
|
|
'translatable2' => 'labelVal2_old', |
1640
|
|
|
'other2' => 'otherVal2_old' |
1641
|
|
|
] |
1642
|
|
|
); |
1643
|
|
|
$this->configProvider->expects($this->once()) |
1644
|
|
|
->method('getConfig') |
1645
|
|
|
->with(self::ENTITY_CLASS) |
1646
|
|
|
->willReturn($config); |
1647
|
|
|
|
1648
|
|
|
$extendConfig = $this->getConfig(new FieldConfigId('extend', self::ENTITY_CLASS, 'id')); |
1649
|
|
|
$extendConfig->set('owner', ExtendScope::OWNER_CUSTOM); |
1650
|
|
|
$extendConfigProvider = $this->getConfigProviderMock(); |
1651
|
|
|
$extendConfigProvider->expects($this->any()) |
1652
|
|
|
->method('getScope') |
1653
|
|
|
->willReturn('extend'); |
1654
|
|
|
$this->configManager->addProvider($extendConfigProvider); |
1655
|
|
|
$extendConfigProvider->expects($this->once()) |
1656
|
|
|
->method('hasConfig') |
1657
|
|
|
->with(self::ENTITY_CLASS, 'id') |
1658
|
|
|
->willReturn(true); |
1659
|
|
|
$extendConfigProvider->expects($this->exactly(2)) |
1660
|
|
|
->method('getConfig') |
1661
|
|
|
->with(self::ENTITY_CLASS, 'id') |
1662
|
|
|
->willReturn($extendConfig); |
1663
|
|
|
$extendPropertyConfigContainer = $this->getPropertyConfigContainerMock(); |
1664
|
|
|
$extendPropertyConfigContainer->expects($this->once()) |
1665
|
|
|
->method('getDefaultValues') |
1666
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD) |
1667
|
|
|
->willReturn(['owner' => ExtendScope::OWNER_SYSTEM]); |
1668
|
|
|
$extendPropertyConfigContainer->expects($this->once()) |
1669
|
|
|
->method('getTranslatableValues') |
1670
|
|
|
->with(PropertyConfigContainer::TYPE_FIELD) |
1671
|
|
|
->willReturn([]); |
1672
|
|
|
$extendConfigProvider->expects($this->any()) |
1673
|
|
|
->method('getPropertyConfig') |
1674
|
|
|
->willReturn($extendPropertyConfigContainer); |
1675
|
|
|
$extendConfigProvider->expects($this->never()) |
1676
|
|
|
->method('persist'); |
1677
|
|
|
|
1678
|
|
|
$expectedConfig = $this->getConfig( |
1679
|
|
|
$configId, |
1680
|
|
|
[ |
1681
|
|
|
'translatable2' => 'labelVal2_old', |
1682
|
|
|
'other2' => 'otherVal2_old', |
1683
|
|
|
'translatable10' => 'labelVal10', |
1684
|
|
|
'other10' => 'otherVal10', |
1685
|
|
|
'translatable1' => 'labelVal1', |
1686
|
|
|
'other1' => 'otherVal1', |
1687
|
|
|
'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated' |
1688
|
|
|
] |
1689
|
|
|
); |
1690
|
|
|
|
1691
|
|
|
$this->configManager->updateConfigFieldModel(self::ENTITY_CLASS, 'id', true); |
1692
|
|
|
$this->assertEquals( |
1693
|
|
|
$expectedConfig, |
1694
|
|
|
$this->configManager->getUpdateConfig()[0] |
1695
|
|
|
); |
1696
|
|
|
} |
1697
|
|
|
|
1698
|
|
|
public function testPersistAndMerge() |
1699
|
|
|
{ |
1700
|
|
|
$configId = new EntityConfigId('entity', self::ENTITY_CLASS); |
1701
|
|
|
$config1 = $this->getConfig($configId, ['val1' => '1', 'val2' => '1']); |
1702
|
|
|
$config2 = $this->getConfig($configId, ['val2' => '2_new', 'val3' => '3']); |
1703
|
|
|
$expectedConfig = $this->getConfig($configId, ['val1' => '1', 'val2' => '2_new', 'val3' => '3']); |
1704
|
|
|
|
1705
|
|
|
$this->configManager->persist($config1); |
1706
|
|
|
$this->configManager->merge($config2); |
1707
|
|
|
$toBePersistedConfigs = $this->configManager->getUpdateConfig(); |
1708
|
|
|
|
1709
|
|
|
$this->assertEquals([$expectedConfig], $toBePersistedConfigs); |
1710
|
|
|
} |
1711
|
|
|
|
1712
|
|
|
protected function createEntityConfigModel( |
1713
|
|
|
$className, |
1714
|
|
|
$mode = ConfigModel::MODE_DEFAULT |
1715
|
|
|
) { |
1716
|
|
|
$result = new EntityConfigModel($className); |
1717
|
|
|
$result->setMode($mode); |
1718
|
|
|
|
1719
|
|
|
return $result; |
1720
|
|
|
} |
1721
|
|
|
|
1722
|
|
|
protected function createFieldConfigModel( |
1723
|
|
|
EntityConfigModel $entityConfigModel, |
1724
|
|
|
$fieldName, |
1725
|
|
|
$fieldType, |
1726
|
|
|
$mode = ConfigModel::MODE_DEFAULT |
1727
|
|
|
) { |
1728
|
|
|
$result = new FieldConfigModel($fieldName, $fieldType); |
1729
|
|
|
$result->setEntity($entityConfigModel); |
1730
|
|
|
$result->setMode($mode); |
1731
|
|
|
|
1732
|
|
|
return $result; |
1733
|
|
|
} |
1734
|
|
|
|
1735
|
|
|
/** |
1736
|
|
|
* @param string $className |
1737
|
|
|
* @param array|null $defaultValues |
1738
|
|
|
* |
1739
|
|
|
* @return EntityMetadata |
1740
|
|
|
*/ |
1741
|
|
View Code Duplication |
protected function getEntityMetadata($className, $defaultValues = null) |
1742
|
|
|
{ |
1743
|
|
|
$metadata = new EntityMetadata($className); |
1744
|
|
|
$metadata->mode = ConfigModel::MODE_DEFAULT; |
1745
|
|
|
if (null !== $defaultValues) { |
1746
|
|
|
$metadata->defaultValues['entity'] = $defaultValues; |
1747
|
|
|
} |
1748
|
|
|
|
1749
|
|
|
return $metadata; |
1750
|
|
|
} |
1751
|
|
|
|
1752
|
|
|
/** |
1753
|
|
|
* @param string $className |
1754
|
|
|
* @param string $fieldName |
1755
|
|
|
* @param array|null $defaultValues |
1756
|
|
|
* |
1757
|
|
|
* @return FieldMetadata |
1758
|
|
|
*/ |
1759
|
|
View Code Duplication |
protected function getFieldMetadata($className, $fieldName, $defaultValues = null) |
1760
|
|
|
{ |
1761
|
|
|
$metadata = new FieldMetadata($className, $fieldName); |
1762
|
|
|
if (null !== $defaultValues) { |
1763
|
|
|
$metadata->defaultValues['entity'] = $defaultValues; |
1764
|
|
|
} |
1765
|
|
|
|
1766
|
|
|
return $metadata; |
1767
|
|
|
} |
1768
|
|
|
|
1769
|
|
|
/** |
1770
|
|
|
* @param ConfigIdInterface $configId |
1771
|
|
|
* @param array|null $values |
1772
|
|
|
* |
1773
|
|
|
* @return Config |
1774
|
|
|
*/ |
1775
|
|
|
protected function getConfig(ConfigIdInterface $configId, array $values = null) |
1776
|
|
|
{ |
1777
|
|
|
$config = new Config($configId); |
1778
|
|
|
if (null !== $values) { |
1779
|
|
|
$config->setValues($values); |
1780
|
|
|
} |
1781
|
|
|
|
1782
|
|
|
return $config; |
1783
|
|
|
} |
1784
|
|
|
|
1785
|
|
|
/** |
1786
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
1787
|
|
|
*/ |
1788
|
|
|
protected function getPropertyConfigContainerMock() |
1789
|
|
|
{ |
1790
|
|
|
return $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Provider\PropertyConfigContainer') |
1791
|
|
|
->disableOriginalConstructor() |
1792
|
|
|
->getMock(); |
1793
|
|
|
} |
1794
|
|
|
|
1795
|
|
|
/** |
1796
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
1797
|
|
|
*/ |
1798
|
|
|
protected function getConfigProviderMock() |
1799
|
|
|
{ |
1800
|
|
|
return $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider') |
1801
|
|
|
->disableOriginalConstructor() |
1802
|
|
|
->getMock(); |
1803
|
|
|
} |
1804
|
|
|
|
1805
|
|
|
public function emptyNameProvider() |
1806
|
|
|
{ |
1807
|
|
|
return [ |
1808
|
|
|
[null], |
1809
|
|
|
[''], |
1810
|
|
|
]; |
1811
|
|
|
} |
1812
|
|
|
} |
1813
|
|
|
|