Commit 5da0092f authored by alexpott's avatar alexpott

Issue #2683431 by penyaskito, EclipseGc, dawehner: PathItem doesn't return...

Issue #2683431 by penyaskito, EclipseGc, dawehner: PathItem doesn't return correct main property from mainPropertyName()
parent 5e619253
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\field\Kernel;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\entity_test\Entity\EntityTest;
......@@ -84,4 +85,41 @@ public function testCreateInstanceWithConfig() {
$this->assertEqual($instance->getFieldDefinition()->getDefaultValue($entity), [['value' => 8675309]], 'Instance default_value is 8675309');
}
/**
* Tests all field items provide an existing main property.
*/
public function testMainProperty() {
// Let's enable all Drupal modules in Drupal core, so we test any field
// type plugin.
$this->enableAllCoreModules();
/** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
foreach ($field_type_manager->getDefinitions() as $plugin_id => $definition) {
$class = $definition['class'];
$property = $class::mainPropertyName();
$storage_definition = BaseFieldDefinition::create($plugin_id);
$property_definitions = $class::propertyDefinitions($storage_definition);
$properties = implode(', ', array_keys($property_definitions));
if (!empty($property_definitions)) {
$message = sprintf("%s property %s found in %s", $plugin_id, $property, $properties);
$this->assertArrayHasKey($property, $class::propertyDefinitions($storage_definition), $message);
}
}
}
/**
* Enable all core modules.
*/
protected function enableAllCoreModules() {
$listing = new ExtensionDiscovery(\Drupal::root());
$module_list = $listing->scan('module', FALSE);
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
$module_handler = $this->container->get('module_handler');
$module_list = array_filter(array_keys($module_list), function ($module) use ($module_handler, $module_list) {
return !$module_handler->moduleExists($module) && substr($module_list[$module]->getPath(), 0, 4) === 'core';
});
$this->enableModules($module_list);
}
}
......@@ -90,4 +90,11 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
return $values;
}
/**
* {@inheritdoc}
*/
public static function mainPropertyName() {
return 'alias';
}
}
......@@ -77,4 +77,11 @@ public function isEmpty() {
return empty($item['shape']) && empty($item['color']);
}
/**
* {@inheritdoc}
*/
public static function mainPropertyName() {
return 'shape';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment