comparison core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
70 * @var \Drupal\field\FieldStorageConfigInterface|\PHPUnit_Framework_MockObject_MockObject 70 * @var \Drupal\field\FieldStorageConfigInterface|\PHPUnit_Framework_MockObject_MockObject
71 */ 71 */
72 protected $fieldStorage; 72 protected $fieldStorage;
73 73
74 /** 74 /**
75 * The typed configuration manager used for testing.
76 *
77 * @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
78 */
79 protected $typedConfigManager;
80
81 /**
82 * The mock field type plugin manager; 75 * The mock field type plugin manager;
83 * 76 *
84 * @var \Drupal\Core\Field\FieldTypePluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject 77 * @var \Drupal\Core\Field\FieldTypePluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject
85 */ 78 */
86 protected $fieldTypePluginManager; 79 protected $fieldTypePluginManager;
95 $this->entityManager = new EntityManager(); 88 $this->entityManager = new EntityManager();
96 $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); 89 $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
97 $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class); 90 $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
98 91
99 $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); 92 $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
100
101 $this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
102 93
103 $this->fieldTypePluginManager = $this->getMock('Drupal\Core\Field\FieldTypePluginManagerInterface'); 94 $this->fieldTypePluginManager = $this->getMock('Drupal\Core\Field\FieldTypePluginManagerInterface');
104 95
105 $container = new ContainerBuilder(); 96 $container = new ContainerBuilder();
106 $container->set('entity.manager', $this->entityManager); 97 $container->set('entity.manager', $this->entityManager);
107 $container->set('entity_field.manager', $this->entityFieldManager); 98 $container->set('entity_field.manager', $this->entityFieldManager);
108 $container->set('entity_type.manager', $this->entityTypeManager); 99 $container->set('entity_type.manager', $this->entityTypeManager);
109 $container->set('uuid', $this->uuid); 100 $container->set('uuid', $this->uuid);
110 $container->set('config.typed', $this->typedConfigManager);
111 $container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager); 101 $container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
112 // Inject the container into entity.manager so it can defer to 102 // Inject the container into entity.manager so it can defer to
113 // entity_type.manager, etc. 103 // entity_type.manager, etc.
114 $this->entityManager->setContainer($container); 104 $this->entityManager->setContainer($container);
115 \Drupal::setContainer($container); 105 \Drupal::setContainer($container);
249 'bundle' => 'test_bundle', 239 'bundle' => 'test_bundle',
250 'field_type' => 'test_field', 240 'field_type' => 'test_field',
251 'dependencies' => [ 241 'dependencies' => [
252 'module' => [ 242 'module' => [
253 'fruiter', 243 'fruiter',
254 ] 244 ],
255 ], 245 ],
256 'third_party_settings' => [ 246 'third_party_settings' => [
257 'fruiter' => [ 247 'fruiter' => [
258 'fruit' => 'apple', 248 'fruit' => 'apple',
259 ] 249 ],
260 ] 250 ],
261 ]); 251 ]);
262 $changed = $field->onDependencyRemoval(['module' => ['fruiter']]); 252 $changed = $field->onDependencyRemoval(['module' => ['fruiter']]);
263 $this->assertTrue($changed); 253 $this->assertTrue($changed);
264 } 254 }
265 255
297 ->will($this->returnValue($this->entityType)); 287 ->will($this->returnValue($this->entityType));
298 $this->entityType->expects($this->once()) 288 $this->entityType->expects($this->once())
299 ->method('getKey') 289 ->method('getKey')
300 ->with('id') 290 ->with('id')
301 ->will($this->returnValue('id')); 291 ->will($this->returnValue('id'));
302 $this->typedConfigManager->expects($this->once()) 292 $this->entityType->expects($this->once())
303 ->method('getDefinition') 293 ->method('getPropertiesToExport')
304 ->will($this->returnValue(['mapping' => array_fill_keys(array_keys($expected), '')])); 294 ->with('test_entity_type.test_bundle.field_test')
295 ->will($this->returnValue(array_combine(array_keys($expected), array_keys($expected))));
305 296
306 $export = $field->toArray(); 297 $export = $field->toArray();
307 $this->assertEquals($expected, $export); 298 $this->assertEquals($expected, $export);
308 } 299 }
309 300