diff --git a/core/core.services.yml b/core/core.services.yml index 7abab67..07c0997 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1059,3 +1059,6 @@ services: arguments: ['@module_handler'] tags: - { name: mime_type_guesser } + plugin.manager.entity.display_component_handler: + class: Drupal\Core\Entity\DisplayComponentHandlerPluginManager + parent: default_plugin_manager diff --git a/core/lib/Drupal/Core/Entity/Annotation/DisplayComponent.php b/core/lib/Drupal/Core/Entity/Annotation/DisplayComponent.php new file mode 100644 index 0000000..e2178c2 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Annotation/DisplayComponent.php @@ -0,0 +1,26 @@ +context = $context; + } + + /** + * {@inheritdoc} + */ + public function prepareDisplayComponents(array &$components, array &$hidden_components) { + } + + /** + * {@inheritdoc} + */ + public function hasElement($name) { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function massageIn($name, array $options) { + return $options; + } + + /** + * {@inheritdoc} + */ + public function massageOut($properties) { + return $properties; + } + + /** + * {@inheritdoc} + */ + public function getRenderer($name, array $options) { + } + +} diff --git a/core/lib/Drupal/Core/Entity/DisplayComponentHandlerInterface.php b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerInterface.php new file mode 100644 index 0000000..675fe98 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerInterface.php @@ -0,0 +1,88 @@ +alterInfo('display_component_handler_info'); + $this->setCacheBackend($cache_backend, 'display_component_handlers'); + } + + /** + * {@inheritdoc} + */ + public function getInstance(array $options) { + $plugin_id = $options['type']; + + if (!isset($this->plugins[$plugin_id]) && !array_key_exists($plugin_id, $this->plugins)) { + $this->plugins[$plugin_id] = $this->discovery->getDefinition($plugin_id) ? $this->createInstance($plugin_id) : NULL; + } + + return $this->plugins[$plugin_id]; + } + +} diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 6339c18..cd48873 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -121,33 +121,6 @@ public function __construct(array $values, $entity_type) { /** * {@inheritdoc} */ - public function getRenderer($field_name) { - if (isset($this->plugins[$field_name])) { - return $this->plugins[$field_name]; - } - - // Instantiate the widget object from the stored display properties. - if (($configuration = $this->getComponent($field_name)) && isset($configuration['type']) && ($definition = $this->getFieldDefinition($field_name))) { - $widget = $this->pluginManager->getInstance(array( - 'field_definition' => $definition, - 'form_mode' => $this->originalMode, - // No need to prepare, defaults have been merged in setComponent(). - 'prepare' => FALSE, - 'configuration' => $configuration - )); - } - else { - $widget = NULL; - } - - // Persist the widget object. - $this->plugins[$field_name] = $widget; - return $widget; - } - - /** - * {@inheritdoc} - */ public function buildForm(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state) { // Set #parents to 'top-level' by default. $form += array('#parents' => array()); diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index 57041e9..0e2689c 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -169,33 +169,6 @@ public function __construct(array $values, $entity_type) { /** * {@inheritdoc} */ - public function getRenderer($field_name) { - if (isset($this->plugins[$field_name])) { - return $this->plugins[$field_name]; - } - - // Instantiate the formatter object from the stored display properties. - if (($configuration = $this->getComponent($field_name)) && isset($configuration['type']) && ($definition = $this->getFieldDefinition($field_name))) { - $formatter = $this->pluginManager->getInstance(array( - 'field_definition' => $definition, - 'view_mode' => $this->originalMode, - // No need to prepare, defaults have been merged in setComponent(). - 'prepare' => FALSE, - 'configuration' => $configuration - )); - } - else { - $formatter = NULL; - } - - // Persist the formatter object. - $this->plugins[$field_name] = $formatter; - return $formatter; - } - - /** - * {@inheritdoc} - */ public function build(ContentEntityInterface $entity) { $build = $this->buildMultiple(array($entity)); return $build[0]; diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index c57b3a6..c694a89 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -79,6 +79,11 @@ protected $hidden = array(); /** + * The renderer objects used for this display, keyed by component name. + */ + protected $renderers = array(); + + /** * The original view or form mode that was requested (case of view/form modes * being configured to fall back to the 'default' display). * @@ -108,6 +113,18 @@ protected $pluginManager; /** + * A mapping of display elements and its corresponding handler. + */ + protected $handlers; + + /** + * The display component handler plugin manager. + * + * @var \Drupal\Core\Entity\DisplayComponentHandlerPluginManager + */ + protected $handlerManager; + + /** * {@inheritdoc} */ public function __construct(array $values, $entity_type) { @@ -129,6 +146,8 @@ public function __construct(array $values, $entity_type) { parent::__construct($values, $entity_type); + $this->handlerManager = \Drupal::service('plugin.manager.entity.display_component_handler'); + $this->originalMode = $this->mode; $this->init(); @@ -209,14 +228,30 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { * {@inheritdoc} */ public function toArray() { - $properties = parent::toArray(); - // Do not store options for fields whose display is not set to be - // configurable. - foreach ($this->getFieldDefinitions() as $field_name => $definition) { - if (!$definition->isDisplayConfigurable($this->displayContext)) { - unset($properties['content'][$field_name]); - unset($properties['hidden'][$field_name]); - } + $names = array( + 'uuid', + 'targetEntityType', + 'bundle', + 'mode', + 'content', + 'hidden', + 'status', + 'dependencies' + ); + $properties = array( + 'id' => $this->id(), + ); + foreach ($names as $name) { + $properties[$name] = $this->get($name); + } + + // Let the component handlers add missing components. + if (!$this->handlerManager) { + $this->handlerManager = \Drupal::service('plugin.manager.entity.display_component_handler'); + } + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $properties = $this->getComponentHandler($type)->massageOut($properties); } return $properties; @@ -231,40 +266,10 @@ public function toArray() { * - or that are not supposed to be configurable. */ protected function init() { - // Fill in defaults for extra fields. - $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; - $extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle); - $extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array(); - foreach ($extra_fields as $name => $definition) { - if (!isset($this->content[$name]) && !isset($this->hidden[$name])) { - // Extra fields are visible by default unless they explicitly say so. - if (!isset($definition['visible']) || $definition['visible'] == TRUE) { - $this->content[$name] = array( - 'weight' => $definition['weight'] - ); - } - else { - $this->hidden[$name] = TRUE; - } - } - } - - // Fill in defaults for fields. - $fields = $this->getFieldDefinitions(); - foreach ($fields as $name => $definition) { - if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) { - $options = $definition->getDisplayOptions($this->displayContext); - - if (!empty($options['type']) && $options['type'] == 'hidden') { - $this->hidden[$name] = TRUE; - } - elseif ($options) { - $this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getType(), $options); - } - // Note: (base) fields that do not specify display options are not - // tracked in the display at all, in order to avoid cluttering the - // configuration that gets saved back. - } + // Let the component handlers add missing components. + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $this->getComponentHandler($type)->prepareDisplayComponents($this->content, $this->hidden); } } @@ -301,14 +306,16 @@ public function setComponent($name, array $options = array()) { $options['weight'] = isset($max) ? $max + 1 : 0; } - // For a field, fill in default options. - if ($field_definition = $this->getFieldDefinition($name)) { - $options = $this->pluginManager->prepareConfiguration($field_definition->getType(), $options); + // Massage in some values. + $handler = $this->getComponentHandlerByElementName($name); + if ($handler) { + // @todo sometimes handler not found. + $options = $handler->massageIn($name, $options); } $this->content[$name] = $options; unset($this->hidden[$name]); - unset($this->plugins[$name]); + unset($this->renderers[$name]); return $this; } @@ -410,4 +417,69 @@ public function onDependencyRemoval(array $dependencies) { } } + /** + * Finds component handler by element name. + * + * @param string $name + * The element name. + * + * @return \Drupal\Core\Entity\DisplayComponentHandlerInterface + */ + public function getComponentHandlerByElementName($name) { + if (!isset($this->handlers[$name])) { + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $handler = $this->getComponentHandler($type); + if ($handler && $handler->hasElement($name)) { + break; + } + $handler = NULL; + } + $this->handlers[$name] = $handler; + } + + return $this->handlers[$name]; + } + + /** + * Instantiates component handler. + * + * @param string $type + * The type of component handler (field, extra_field). + * + * @return \Drupal\Core\Entity\DisplayComponentHandlerInterface + */ + public function getComponentHandler($type) { + $handler = $this->handlerManager->getInstance(array('type' => $type)); + if ($handler) { + $handler->setContext(array( + 'entity_type' => $this->targetEntityType, + 'bundle' => $this->bundle, + 'mode' => $this->originalMode, + 'display_context' => $this->displayContext, + )); + } + return $handler; + } + + /**+ + * {@inheritdoc} + */ + public function getRenderer($name) { + if (!isset($this->content[$name])) { + return NULL; + } + + if (!array_key_exists($name, $this->renderers)) { + if ($handler = $this->getComponentHandlerByElementName($name)) { + $options = $this->getComponent($name); + $this->renderers[$name] = $handler->getRenderer($name, $options); + } + else { + $this->renderers[$name] = NULL; + } + } + return $this->renderers[$name]; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase_BACK.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase_BACK.php new file mode 100644 index 0000000..55ba736 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase_BACK.php @@ -0,0 +1,480 @@ +entityManager()->getDefinition($values['targetEntityType'])->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + throw new \InvalidArgumentException('EntityDisplay entities can only handle content entity types.'); + } + + if (!isset($this->displayContext)) { + throw new \RuntimeException('Missing display context type.'); + } + + parent::__construct($values, $entity_type); + + $this->handlerManager = \Drupal::service('plugin.manager.entity.display_component_handler'); + + $this->originalMode = $this->mode; + + $this->init(); + } + + /** + * {@inheritdoc} + */ + public function id() { + return $this->targetEntityType . '.' . $this->bundle . '.' . $this->mode; + } + + /** + * {@inheritdoc} + */ + public function preSave(EntityStorageInterface $storage, $update = TRUE) { + // Sort elements by weight before saving. + uasort($this->content, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); + parent::preSave($storage, $update); + } + + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + parent::calculateDependencies(); + $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType); + + $bundle_entity_type_id = $target_entity_type->getBundleEntityType(); + if ($bundle_entity_type_id != 'bundle') { + // If the target entity type uses entities to manage its bundles then + // depend on the bundle entity. + $bundle_entity = \Drupal::entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle); + $this->addDependency('entity', $bundle_entity->getConfigDependencyName()); + } + else { + // Depend on the provider of the entity type. + $this->addDependency('module', $target_entity_type->getProvider()); + } + // Create dependencies on both hidden and visible fields. + $fields = $this->content + $this->hidden; + foreach ($fields as $field_name => $component) { + $field = FieldConfig::loadByName($this->targetEntityType, $this->bundle, $field_name); + if ($field) { + $this->addDependency('entity', $field->getConfigDependencyName()); + } + // Create a dependency on the module that provides the component. + if ($plugin = $this->getRenderer($field_name)) { + $definition = $plugin->getPluginDefinition(); + $this->addDependency('module', $definition['provider']); + } + // Create dependencies on any modules providing third party settings. + if (isset($component['third_party_settings'])) { + foreach($component['third_party_settings'] as $module => $settings) { + $this->addDependency('module', $module); + } + } + } + // Depend on configured modes. + if ($this->mode != 'default') { + $mode_entity = \Drupal::entityManager()->getStorage('entity_' . $this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode); + $this->addDependency('entity', $mode_entity->getConfigDependencyName()); + } + return $this->dependencies; + } + + /** + * {@inheritdoc} + */ + public function postSave(EntityStorageInterface $storage, $update = TRUE) { + // Reset the render cache for the target entity type. + if (\Drupal::entityManager()->hasHandler($this->targetEntityType, 'view_builder')) { + \Drupal::entityManager()->getViewBuilder($this->targetEntityType)->resetCache(); + } + } + + /** + * {@inheritdoc} + */ + public function toArray() { +//<<<<<<< HEAD:core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php + $names = array( + 'uuid', + 'targetEntityType', + 'bundle', + 'mode', + 'content', + 'hidden', + 'status', + 'dependencies' + ); + $properties = array( + 'id' => $this->id(), + ); + foreach ($names as $name) { + $properties[$name] = $this->get($name); + } + + // Let the component handlers add missing components. + if (!$this->handlerManager) { + $this->handlerManager = \Drupal::service('plugin.manager.entity.display_component_handler'); + } + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $properties = $this->getComponentHandler($type)->massageOut($properties); + + /* +======= + $properties = parent::toArray(); + // Do not store options for fields whose display is not set to be + // configurable. + foreach ($this->getFieldDefinitions() as $field_name => $definition) { + if (!$definition->isDisplayConfigurable($this->displayContext)) { + unset($properties['content'][$field_name]); + unset($properties['hidden'][$field_name]); + } +>>>>>>> 8.1.x:core/lib/Drupal/Core/Entity/EntityDisplayBase.php + */ + } + + return $properties; + } + + /** + * Initializes the display. + * + * This fills in default options for components: + * - that are not explicitly known as either "visible" or "hidden" in the + * display, + * - or that are not supposed to be configurable. + */ + protected function init() { +//<<<<<<< HEAD:core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php + // Let the component handlers add missing components. + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $this->getComponentHandler($type)->prepareDisplayComponents($this->content, $this->hidden); + /* +======= + // Fill in defaults for extra fields. + $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; + $extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle); + $extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array(); + foreach ($extra_fields as $name => $definition) { + if (!isset($this->content[$name]) && !isset($this->hidden[$name])) { + // Extra fields are visible by default unless they explicitly say so. + if (!isset($definition['visible']) || $definition['visible'] == TRUE) { + $this->content[$name] = array( + 'weight' => $definition['weight'] + ); + } + else { + $this->hidden[$name] = TRUE; + } + } + } + + // Fill in defaults for fields. + $fields = $this->getFieldDefinitions(); + foreach ($fields as $name => $definition) { + if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) { + $options = $definition->getDisplayOptions($this->displayContext); + + if (!empty($options['type']) && $options['type'] == 'hidden') { + $this->hidden[$name] = TRUE; + } + elseif ($options) { + $this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getType(), $options); + } + // Note: (base) fields that do not specify display options are not + // tracked in the display at all, in order to avoid cluttering the + // configuration that gets saved back. + } +>>>>>>> 8.1.x:core/lib/Drupal/Core/Entity/EntityDisplayBase.php + */ + } + } + + /** + * {@inheritdoc} + */ + public function createCopy($mode) { + $display = $this->createDuplicate(); + $display->mode = $display->originalMode = $mode; + return $display; + } + + /** + * {@inheritdoc} + */ + public function getComponents() { + return $this->content; + } + + /** + * {@inheritdoc} + */ + public function getComponent($name) { + return isset($this->content[$name]) ? $this->content[$name] : NULL; + } + + /** + * {@inheritdoc} + */ + public function setComponent($name, array $options = array()) { + // If no weight specified, make sure the field sinks at the bottom. + if (!isset($options['weight'])) { + $max = $this->getHighestWeight(); + $options['weight'] = isset($max) ? $max + 1 : 0; + } + + // Massage in some values. + $handler = $this->getComponentHandlerByElementName($name); + if ($handler) { + // @todo sometimes handler not found. + $options = $handler->massageIn($name, $options); + } + + $this->content[$name] = $options; + unset($this->hidden[$name]); + unset($this->renderers[$name]); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function removeComponent($name) { + $this->hidden[$name] = TRUE; + unset($this->content[$name]); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getHighestWeight() { + $weights = array(); + + // Collect weights for the components in the display. + foreach ($this->content as $options) { + if (isset($options['weight'])) { + $weights[] = $options['weight']; + } + } + + // Let other modules feedback about their own additions. + $weights = array_merge($weights, \Drupal::moduleHandler()->invokeAll('field_info_max_weight', array($this->targetEntityType, $this->bundle, $this->displayContext, $this->mode))); + + return $weights ? max($weights) : NULL; + } + + /** + * Finds component handler by element name. + * + * @param string $name + * The element name. + * + * @return \Drupal\entity\DisplayComponentHandlerInterface + */ + public function getComponentHandlerByElementName($name) { + if (!isset($this->handlers[$name])) { + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $handler = $this->getComponentHandler($type); + if ($handler && $handler->hasElement($name)) { + break; + } + $handler = NULL; + } + $this->handlers[$name] = $handler; + } + + return $this->handlers[$name]; + } + + /** + * Instantiates component handler. + * +<<<<<<< HEAD:core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php + * @param string $type + * The type of component handler (field, extra_field). + * + * @return \Drupal\entity\DisplayComponentHandlerInterface + */ + public function getComponentHandler($type) { + $handler = $this->handlerManager->getInstance(array('type' => $type)); + if ($handler) { + $handler->setContext(array( + 'entity_type' => $this->targetEntityType, + 'bundle' => $this->bundle, + 'view_mode' => $this->originalMode, + 'display_context' => $this->displayContext, + )); + } + return $handler; + } + + /**+ + * {@inheritdoc} +======= + * @param FieldDefinitionInterface $definition + * A field definition. + * @return array|null +>>>>>>> 8.1.x:core/lib/Drupal/Core/Entity/EntityDisplayBase.php + */ + public function getRenderer($name) { + if (!isset($this->content[$name])) { + return NULL; + } + + if (!array_key_exists($name, $this->renderers)) { + if ($handler = $this->getComponentHandlerByElementName($name)) { + $options = $this->getComponent($name); + $this->renderers[$name] = $handler->getRenderer($name, $options); + } + else { + $this->renderers[$name] = NULL; + } + } + return $this->renderers[$name]; + } + + /** + * {@inheritdoc} + */ + public function onDependencyRemoval(array $dependencies) { + $changed = FALSE; + foreach ($dependencies['entity'] as $entity) { + if ($entity instanceof FieldConfigInterface) { + // Remove components for fields that are being deleted. + $this->removeComponent($entity->getName()); + unset($this->hidden[$entity->getName()]); + $changed = TRUE; + } + } + foreach ($this->getComponents() as $name => $component) { + if (isset($component['type']) && $definition = $this->pluginManager->getDefinition($component['type'], FALSE)) { + if (in_array($definition['provider'], $dependencies['module'])) { + // Revert to the defaults if the plugin that supplies the widget or + // formatter depends on a module that is being uninstalled. + $this->setComponent($name); + $changed = TRUE; + } + } + } + if ($changed) { + $this->save(); + } + } + +} diff --git a/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler b/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler new file mode 100644 index 0000000..17a092c --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler @@ -0,0 +1,50 @@ +getExtraFields($this->context['entity_type'], $this->context['bundle'], ($this->context['display_context'] == 'view' ? 'display' : $this->context['display_context'])); + foreach ($extra_fields as $name => $definition) { + if (!isset($components[$name]) && !isset($hidden_components[$name])) { + // Extra fields are visible by default unless they explicitly say so. + if (!isset($definition['visible']) || $definition['visible'] == TRUE) { + $components[$name] = array( + 'weight' => $definition['weight'] + ); + } + else { + $hidden_components[$name] = TRUE; + } + } + } + } + + /** + * {@inheritdoc} + */ + public function hasElement($name) { + $extra_fields = \Drupal::entityManager()->getExtraFields($this->context['entity_type'], $this->context['bundle'], ($this->context['display_context'] == 'view' ? 'display' : $this->context['display_context'])); + return isset($extra_fields[$name]); + } + +} diff --git a/core/modules/field/src/Plugin/DisplayComponent/FieldDisplayComponentHandler.php b/core/modules/field/src/Plugin/DisplayComponent/FieldDisplayComponentHandler.php new file mode 100644 index 0000000..5cd49c6 --- /dev/null +++ b/core/modules/field/src/Plugin/DisplayComponent/FieldDisplayComponentHandler.php @@ -0,0 +1,208 @@ +formatterPluginManager = $formatter_plugin_manager; + $this->widgetPluginManager = $widget_plugin_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, + $container->get('plugin.manager.field.formatter'), + $container->get('plugin.manager.field.widget') + ); + } + + /** + * {@inheritdoc} + */ + public function massageIn($name, array $options) { + $field_definition = $this->getFieldDefinition($name); + if (!isset($field_definition)) { + // The field in process of removal from display. + return $options; + } + if ($this->context['display_context'] == 'view') { + return $this->formatterPluginManager->prepareConfiguration($field_definition->getType(), $options); + } + else { + return $this->widgetPluginManager->prepareConfiguration($field_definition->getType(), $options); + } + } + + /** + * {@inheritdoc} + */ + public function massageOut($properties) { + // Do not store options for fields whose display is not set to be + // configurable. + foreach ($this->getFieldDefinitions() as $field_name => $definition) { + if (!$definition->isDisplayConfigurable($this->context['display_context'])) { + unset($properties['content'][$field_name]); + unset($properties['hidden'][$field_name]); + } + } + + return $properties; + } + + /** + * {@inheritdoc} + */ + public function prepareDisplayComponents(array &$components, array &$hidden_components) { + if ($this->context['display_context'] == 'view') { + $plugin_manager = $this->formatterPluginManager; + } + else { + $plugin_manager = $this->widgetPluginManager; + } + + // Fill in defaults for fields. + $fields = $this->getFieldDefinitions(); + foreach ($fields as $name => $definition) { + if (!$definition->isDisplayConfigurable($this->context['display_context']) || (!isset($components[$name]) && !isset($hidden_components[$name]))) { + $options = $definition->getDisplayOptions($this->context['display_context']); + + if (!empty($options['type']) && $options['type'] == 'hidden') { + $hidden_components[$name] = TRUE; + } + elseif ($options) { + $components[$name] = $plugin_manager->prepareConfiguration($definition->getType(), $options); + } + // Note: (base) fields that do not specify display options are not + // tracked in the display at all, in order to avoid cluttering the + // configuration that gets saved back. + } + } + } + + /** + * {@inheritdoc} + */ + public function getRenderer($name, array $options) { + if (isset($options['type']) && ($definition = $this->getFieldDefinition($name))) { + if ($this->context['display_context'] == 'view') { + $plugin_manager = $this->formatterPluginManager; + $mode_key = 'view_mode'; + } + else { + $plugin_manager = $this->widgetPluginManager; + $mode_key = 'form_mode'; + } + + return $plugin_manager->getInstance(array( + 'field_definition' => $definition, + $mode_key => $this->context['mode'], + // No need to prepare, defaults have been merged when the options were + // written in the display. + 'prepare' => FALSE, + 'configuration' => $options, + )); + } + return NULL; + } + + /** + * {@inheritdoc} + */ + public function hasElement($name) { + $field_defintion = $this->getFieldDefinition($name); + return isset($field_defintion); + } + + /** + * Returns the field definition of a field. + */ + protected function getFieldDefinition($field_name) { + $definitions = $this->getFieldDefinitions(); + return isset($definitions[$field_name]) ? $definitions[$field_name] : NULL; + } + + /** + * Returns the definitions of the fields that are candidate for display. + */ + protected function getFieldDefinitions() { + $entity_manager = \Drupal::entityManager(); + // Entity displays are sometimes created for non-content entities. + // @todo Prevent this in https://drupal.org/node/2095195. + //if (!$entity_manager->getDefinition($this->context['entity_type'])->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + // return array(); + //} + + if (!isset($this->fieldDefinitions)) { + $definitions = $entity_manager->getFieldDefinitions($this->context['entity_type'], $this->context['bundle']); + + // The display only cares about fields that specify display options. + // Discard base fields that are not rendered through formatters / widgets. + $display_context = $this->context['display_context']; + $this->fieldDefinitions = array_filter($definitions, function (FieldDefinitionInterface $definition) use ($display_context) { + return $definition->getDisplayOptions($display_context); + }); + } + + return $this->fieldDefinitions; + } + +} diff --git a/core/vendor/phpunit/php-code-coverage/tests/PHP/CodeCoverage/UtilTest.php b/core/vendor/phpunit/php-code-coverage/tests/PHP/CodeCoverage/UtilTest.php deleted file mode 100644 index e3d8f9f..0000000 --- a/core/vendor/phpunit/php-code-coverage/tests/PHP/CodeCoverage/UtilTest.php +++ /dev/null @@ -1,72 +0,0 @@ -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @category PHP - * @package CodeCoverage - * @subpackage Tests - * @author Sebastian Bergmann - * @copyright 2009-2014 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/php-code-coverage - * @since File available since Release 1.0.0 - */ - -/** - * Tests for the PHP_CodeCoverage_Util class. - * - * @category PHP - * @package CodeCoverage - * @subpackage Tests - * @author Sebastian Bergmann - * @copyright 2009-2014 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/php-code-coverage - * @since Class available since Release 1.0.0 - */ -class PHP_CodeCoverage_UtilTest extends PHPUnit_Framework_TestCase -{ - /** - * @covers PHP_CodeCoverage_Util::percent - */ - public function testPercent() - { - $this->assertEquals(100, PHP_CodeCoverage_Util::percent(100, 0)); - $this->assertEquals(100, PHP_CodeCoverage_Util::percent(100, 100)); - $this->assertEquals( - '100.00%', PHP_CodeCoverage_Util::percent(100, 100, true) - ); - } -} diff --git a/core/vendor/phpunit/php-code-coverage/tests/_files/CoverageFunctionParenthesesWhitespaceTest.php b/core/vendor/phpunit/php-code-coverage/tests/_files/CoverageFunctionParenthesesWhitespaceTest.php deleted file mode 100644 index becc6c8..0000000 --- a/core/vendor/phpunit/php-code-coverage/tests/_files/CoverageFunctionParenthesesWhitespaceTest.php +++ /dev/null @@ -1,11 +0,0 @@ -publicMethod(); - } -} diff --git a/core/vendor/phpunit/php-code-coverage/tests/_files/CoverageMethodParenthesesWhitespaceTest.php b/core/vendor/phpunit/php-code-coverage/tests/_files/CoverageMethodParenthesesWhitespaceTest.php deleted file mode 100644 index d1be1c6..0000000 --- a/core/vendor/phpunit/php-code-coverage/tests/_files/CoverageMethodParenthesesWhitespaceTest.php +++ /dev/null @@ -1,12 +0,0 @@ -publicMethod(); - } -} diff --git a/core/vendor/phpunit/php-code-coverage/tests/_files/NamespaceCoverageCoversClassPublicTest.php b/core/vendor/phpunit/php-code-coverage/tests/_files/NamespaceCoverageCoversClassPublicTest.php deleted file mode 100644 index 45f583b..0000000 --- a/core/vendor/phpunit/php-code-coverage/tests/_files/NamespaceCoverageCoversClassPublicTest.php +++ /dev/null @@ -1,15 +0,0 @@ -publicMethod(); - } -} diff --git a/core/vendor/phpunit/php-code-coverage/tests/_files/NamespaceCoverageCoversClassTest.php b/core/vendor/phpunit/php-code-coverage/tests/_files/NamespaceCoverageCoversClassTest.php deleted file mode 100644 index b336745..0000000 --- a/core/vendor/phpunit/php-code-coverage/tests/_files/NamespaceCoverageCoversClassTest.php +++ /dev/null @@ -1,20 +0,0 @@ -publicMethod(); - } -} diff --git a/core/vendor/phpunit/phpunit-mock-objects/tests/GeneratorTest.php b/core/vendor/phpunit/phpunit-mock-objects/tests/GeneratorTest.php deleted file mode 100644 index 6663ab4..0000000 --- a/core/vendor/phpunit/phpunit-mock-objects/tests/GeneratorTest.php +++ /dev/null @@ -1,142 +0,0 @@ -generator = new PHPUnit_Framework_MockObject_Generator; - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMock - * @expectedException PHPUnit_Framework_Exception - */ - public function testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock() - { - $this->generator->getMock('StdClass', array(0)); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMock - */ - public function testGetMockCanCreateNonExistingFunctions() - { - $mock = $this->generator->getMock('StdClass', array('testFunction')); - $this->assertTrue(method_exists($mock, 'testFunction')); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMock - * @expectedException PHPUnit_Framework_MockObject_RuntimeException - * @expectedExceptionMessage duplicates: "foo, foo" - */ - public function testGetMockGeneratorFails() - { - $mock = $this->generator->getMock('StdClass', array('foo', 'foo')); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass - */ - public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces() - { - $mock = $this->generator->getMockForAbstractClass('Countable'); - $this->assertTrue(method_exists($mock, 'count')); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass - */ - public function testGetMockForAbstractClassStubbingAbstractClass() - { - $mock = $this->generator->getMockForAbstractClass('AbstractMockTestClass'); - $this->assertTrue(method_exists($mock, 'doSomething')); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass - */ - public function testGetMockForAbstractClassWithNonExistentMethods() - { - $mock = $this->generator->getMockForAbstractClass( - 'AbstractMockTestClass', array(), '', true, - true, true, array('nonexistentMethod') - ); - - $this->assertTrue(method_exists($mock, 'nonexistentMethod')); - $this->assertTrue(method_exists($mock, 'doSomething')); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass - */ - public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMethodWhenNoMethodsWereInformed() - { - $mock = $this->generator->getMockForAbstractClass('AbstractMockTestClass'); - - $mock->expects($this->any()) - ->method('doSomething') - ->willReturn('testing'); - - $this->assertEquals('testing', $mock->doSomething()); - $this->assertEquals(1, $mock->returnAnything()); - } - - /** - * @dataProvider getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider - * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass - * @expectedException PHPUnit_Framework_Exception - */ - public function testGetMockForAbstractClassExpectingInvalidArgumentException($className, $mockClassName) - { - $mock = $this->generator->getMockForAbstractClass($className, array(), $mockClassName); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass - * @expectedException PHPUnit_Framework_MockObject_RuntimeException - */ - public function testGetMockForAbstractClassAnstractClassDoesNotExist() - { - $mock = $this->generator->getMockForAbstractClass('Tux'); - } - - /** - * Dataprovider for test "testGetMockForAbstractClassExpectingInvalidArgumentException" - */ - public static function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider() - { - return array( - 'className not a string' => array(array(), ''), - 'mockClassName not a string' => array('Countable', new StdClass), - ); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMockForTrait - * @requires PHP 5.4.0 - */ - public function testGetMockForTraitWithNonExistentMethodsAndNonAbstractMethods() - { - $mock = $this->generator->getMockForTrait( - 'AbstractTrait', array(), '', true, - true, true, array('nonexistentMethod') - ); - - $this->assertTrue(method_exists($mock, 'nonexistentMethod')); - $this->assertTrue(method_exists($mock, 'doSomething')); - $this->assertTrue($mock->mockableMethod()); - $this->assertTrue($mock->anotherMockableMethod()); - } - - /** - * @covers PHPUnit_Framework_MockObject_Generator::getMockForTrait - * @requires PHP 5.4.0 - */ - public function testGetMockForTraitStubbingAbstractMethod() - { - $mock = $this->generator->getMockForTrait('AbstractTrait'); - $this->assertTrue(method_exists($mock, 'doSomething')); - } -} diff --git a/core/vendor/phpunit/phpunit-mock-objects/tests/MockObject/nonexistent_class.phpt b/core/vendor/phpunit/phpunit-mock-objects/tests/MockObject/nonexistent_class.phpt deleted file mode 100644 index 5dbb385..0000000 --- a/core/vendor/phpunit/phpunit-mock-objects/tests/MockObject/nonexistent_class.phpt +++ /dev/null @@ -1,70 +0,0 @@ ---TEST-- -PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE) ---FILE-- -generate( - 'Foo', - array(), - 'MockFoo', - TRUE, - TRUE -); - -print $mock['code']; -?> ---EXPECTF-- -class Foo -{ -} - -class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject -{ - private $__phpunit_invocationMocker; - private $__phpunit_originalObject; - - public function __clone() - { - $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); - } - - public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) - { - return $this->__phpunit_getInvocationMocker()->expects($matcher); - } - - public function method() - { - $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount; - $expects = $this->expects($any); - return call_user_func_array(array($expects, 'method'), func_get_args()); - } - - public function __phpunit_setOriginalObject($originalObject) - { - $this->__phpunit_originalObject = $originalObject; - } - - public function __phpunit_getInvocationMocker() - { - if ($this->__phpunit_invocationMocker === NULL) { - $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; - } - - return $this->__phpunit_invocationMocker; - } - - public function __phpunit_hasMatchers() - { - return $this->__phpunit_getInvocationMocker()->hasMatchers(); - } - - public function __phpunit_verify() - { - $this->__phpunit_getInvocationMocker()->verify(); - $this->__phpunit_invocationMocker = NULL; - } -} diff --git a/core/vendor/phpunit/phpunit/tests/Util/TestTest.php b/core/vendor/phpunit/phpunit/tests/Util/TestTest.php deleted file mode 100644 index 99e55bd..0000000 --- a/core/vendor/phpunit/phpunit/tests/Util/TestTest.php +++ /dev/null @@ -1,538 +0,0 @@ -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit - * @author Sebastian Bergmann - * @copyright 2001-2014 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 3.3.6 - */ - -if (!defined('TEST_FILES_PATH')) { - define( - 'TEST_FILES_PATH', - dirname(__DIR__) . DIRECTORY_SEPARATOR . - '_files' . DIRECTORY_SEPARATOR - ); -} - -/** - * - * - * @package PHPUnit - * @author Sebastian Bergmann - * @copyright 2001-2014 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since Class available since Release 3.3.6 - */ -class Util_TestTest extends PHPUnit_Framework_TestCase -{ - /** - * @covers PHPUnit_Util_Test::getExpectedException - * @todo Split up in separate tests - */ - public function testGetExpectedException() - { - $this->assertSame( - array('class' => 'FooBarBaz', 'code' => null, 'message' => ''), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testOne') - ); - - $this->assertSame( - array('class' => 'Foo_Bar_Baz', 'code' => null, 'message' => ''), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testTwo') - ); - - $this->assertSame( - array('class' => 'Foo\Bar\Baz', 'code' => null, 'message' => ''), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testThree') - ); - - $this->assertSame( - array('class' => 'ほげ', 'code' => null, 'message' => ''), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFour') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => 1234, 'message' => 'Message'), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFive') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => 1234, 'message' => 'Message'), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSix') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => 'ExceptionCode', 'message' => 'Message'), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSeven') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => 0, 'message' => 'Message'), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testEight') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => ExceptionTest::ERROR_CODE, 'message' => ExceptionTest::ERROR_MESSAGE), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testNine') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => null, 'message' => ''), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSingleLine') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => My\Space\ExceptionNamespaceTest::ERROR_CODE, 'message' => My\Space\ExceptionNamespaceTest::ERROR_MESSAGE), - PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testConstants') - ); - - // Ensure the Class::CONST expression is only evaluated when the constant really exists - $this->assertSame( - array('class' => 'Class', 'code' => 'ExceptionTest::UNKNOWN_CODE_CONSTANT', 'message' => 'ExceptionTest::UNKNOWN_MESSAGE_CONSTANT'), - PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testUnknownConstants') - ); - - $this->assertSame( - array('class' => 'Class', 'code' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT', 'message' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT'), - PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testUnknownConstants') - ); - } - - /** - * @covers PHPUnit_Util_Test::getRequirements - * @dataProvider requirementsProvider - */ - public function testGetRequirements($test, $result) - { - $this->assertEquals( - $result, - PHPUnit_Util_Test::getRequirements('RequirementsTest', $test) - ); - } - - public function requirementsProvider() - { - return array( - array('testOne', array()), - array('testTwo', array('PHPUnit' => '1.0')), - array('testThree', array('PHP' => '2.0')), - array('testFour', array('PHPUnit'=>'2.0', 'PHP' => '1.0')), - array('testFive', array('PHP' => '5.4.0RC6')), - array('testSix', array('PHP' => '5.4.0-alpha1')), - array('testSeven', array('PHP' => '5.4.0beta2')), - array('testEight', array('PHP' => '5.4-dev')), - array('testNine', array('functions' => array('testFunc'))), - array('testTen', array('extensions' => array('testExt'))), - array('testEleven', array('OS' => '/Linux/i')), - array( - 'testSpace', - array( - 'extensions' => array('spl'), - 'OS' => '/.*/i' - ) - ), - array( - 'testAllPossibleRequirements', - array( - 'PHP' => '99-dev', - 'PHPUnit' => '9-dev', - 'OS' => '/DOESNOTEXIST/i', - 'functions' => array( - 'testFuncOne', - 'testFuncTwo', - ), - 'extensions' => array( - 'testExtOne', - 'testExtTwo', - ) - ) - ) - ); - } - - /** - * @covers PHPUnit_Util_Test::getRequirements - */ - public function testGetRequirementsMergesClassAndMethodDocBlocks() - { - $expectedAnnotations = array( - 'PHP' => '5.4', - 'PHPUnit' => '3.7', - 'OS' => '/WINNT/i', - 'functions' => array( - 'testFuncClass', - 'testFuncMethod', - ), - 'extensions' => array( - 'testExtClass', - 'testExtMethod', - ) - ); - - $this->assertEquals( - $expectedAnnotations, - PHPUnit_Util_Test::getRequirements('RequirementsClassDocBlockTest', 'testMethod') - ); - } - - /** - * @coversNothing - * @todo This test does not really test functionality of PHPUnit_Util_Test - */ - public function testGetProvidedDataRegEx() - { - $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider method', $matches); - $this->assertEquals(1, $result); - $this->assertEquals('method', $matches[1]); - - $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider class::method', $matches); - $this->assertEquals(1, $result); - $this->assertEquals('class::method', $matches[1]); - - $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\class::method', $matches); - $this->assertEquals(1, $result); - $this->assertEquals('namespace\class::method', $matches[1]); - - $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\namespace\class::method', $matches); - $this->assertEquals(1, $result); - $this->assertEquals('namespace\namespace\class::method', $matches[1]); - - $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider メソッド', $matches); - $this->assertEquals(1, $result); - $this->assertEquals('メソッド', $matches[1]); - } - - /** - * @covers PHPUnit_Util_Test::getDependencies - * @todo Not sure what this test tests (name is misleading at least) - */ - public function testParseAnnotation() - { - $this->assertEquals( - array('Foo', 'ほげ'), - PHPUnit_Util_Test::getDependencies(get_class($this), 'methodForTestParseAnnotation') - ); - } - - /** - * @depends Foo - * @depends ほげ - * @todo Remove fixture from test class - */ - public function methodForTestParseAnnotation() - { - } - - /** - * @covers PHPUnit_Util_Test::getDependencies - */ - public function testParseAnnotationThatIsOnlyOneLine() - { - $this->assertEquals( - array('Bar'), - PHPUnit_Util_Test::getDependencies(get_class($this), 'methodForTestParseAnnotationThatIsOnlyOneLine') - ); - } - - /** @depends Bar */ - public function methodForTestParseAnnotationThatIsOnlyOneLine() - { - // TODO Remove fixture from test class - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - * @covers PHPUnit_Util_Test::resolveElementToReflectionObjects - * @dataProvider getLinesToBeCoveredProvider - */ - public function testGetLinesToBeCovered($test, $lines) - { - if (strpos($test, 'Namespace') === 0) { - $expected = array( - TEST_FILES_PATH . 'NamespaceCoveredClass.php' => $lines - ); - } - - else if ($test === 'CoverageNoneTest') { - $expected = array(); - } - - else if ($test === 'CoverageNothingTest') { - $expected = false; - } - - else if ($test === 'CoverageFunctionTest') { - $expected = array( - TEST_FILES_PATH . 'CoveredFunction.php' => $lines - ); - } - - else { - $expected = array(TEST_FILES_PATH . 'CoveredClass.php' => $lines); - } - - $this->assertEquals( - $expected, - PHPUnit_Util_Test::getLinesToBeCovered( - $test, 'testSomething' - ) - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - * @covers PHPUnit_Util_Test::resolveElementToReflectionObjects - * @expectedException PHPUnit_Framework_CodeCoverageException - */ - public function testGetLinesToBeCovered2() - { - PHPUnit_Util_Test::getLinesToBeCovered( - 'NotExistingCoveredElementTest', 'testOne' - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - * @covers PHPUnit_Util_Test::resolveElementToReflectionObjects - * @expectedException PHPUnit_Framework_CodeCoverageException - */ - public function testGetLinesToBeCovered3() - { - PHPUnit_Util_Test::getLinesToBeCovered( - 'NotExistingCoveredElementTest', 'testTwo' - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - * @covers PHPUnit_Util_Test::resolveElementToReflectionObjects - * @expectedException PHPUnit_Framework_CodeCoverageException - */ - public function testGetLinesToBeCovered4() - { - PHPUnit_Util_Test::getLinesToBeCovered( - 'NotExistingCoveredElementTest', 'testThree' - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - */ - public function testGetLinesToBeCoveredSkipsNonExistantMethods() - { - $this->assertSame( - array(), - PHPUnit_Util_Test::getLinesToBeCovered( - 'NotExistingCoveredElementTest', - 'methodDoesNotExist' - ) - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - * @expectedException PHPUnit_Framework_CodeCoverageException - */ - public function testTwoCoversDefaultClassAnnoationsAreNotAllowed() - { - PHPUnit_Util_Test::getLinesToBeCovered( - 'CoverageTwoDefaultClassAnnotations', - 'testSomething' - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - */ - public function testFunctionParenthesesAreAllowed() - { - $this->assertSame( - array(TEST_FILES_PATH . 'CoveredFunction.php' => range(2, 4)), - PHPUnit_Util_Test::getLinesToBeCovered( - 'CoverageFunctionParenthesesTest', - 'testSomething' - ) - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - */ - public function testFunctionParenthesesAreAllowedWithWhitespace() - { - $this->assertSame( - array(TEST_FILES_PATH . 'CoveredFunction.php' => range(2, 4)), - PHPUnit_Util_Test::getLinesToBeCovered( - 'CoverageFunctionParenthesesWhitespaceTest', - 'testSomething' - ) - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - */ - public function testMethodParenthesesAreAllowed() - { - $this->assertSame( - array(TEST_FILES_PATH . 'CoveredClass.php' => range(31, 35)), - PHPUnit_Util_Test::getLinesToBeCovered( - 'CoverageMethodParenthesesTest', - 'testSomething' - ) - ); - } - - /** - * @covers PHPUnit_Util_Test::getLinesToBeCovered - */ - public function testMethodParenthesesAreAllowedWithWhitespace() - { - $this->assertSame( - array(TEST_FILES_PATH . 'CoveredClass.php' => range(31, 35)), - PHPUnit_Util_Test::getLinesToBeCovered( - 'CoverageMethodParenthesesWhitespaceTest', - 'testSomething' - ) - ); - } - - public function getLinesToBeCoveredProvider() - { - return array( - array( - 'CoverageNoneTest', - array() - ), - array( - 'CoverageClassExtendedTest', - array_merge(range(19, 36), range(2, 17)) - ), - array( - 'CoverageClassTest', - range(19, 36) - ), - array( - 'CoverageMethodTest', - range(31, 35) - ), - array( - 'CoverageMethodOneLineAnnotationTest', - range(31, 35) - ), - array( - 'CoverageNotPrivateTest', - array_merge(range(25, 29), range(31, 35)) - ), - array( - 'CoverageNotProtectedTest', - array_merge(range(21, 23), range(31, 35)) - ), - array( - 'CoverageNotPublicTest', - array_merge(range(21, 23), range(25, 29)) - ), - array( - 'CoveragePrivateTest', - range(21, 23) - ), - array( - 'CoverageProtectedTest', - range(25, 29) - ), - array( - 'CoveragePublicTest', - range(31, 35) - ), - array( - 'CoverageFunctionTest', - range(2, 4) - ), - array( - 'NamespaceCoverageClassExtendedTest', - array_merge(range(21, 38), range(4, 19)) - ), - array( - 'NamespaceCoverageClassTest', - range(21, 38) - ), - array( - 'NamespaceCoverageMethodTest', - range(33, 37) - ), - array( - 'NamespaceCoverageNotPrivateTest', - array_merge(range(27, 31), range(33, 37)) - ), - array( - 'NamespaceCoverageNotProtectedTest', - array_merge(range(23, 25), range(33, 37)) - ), - array( - 'NamespaceCoverageNotPublicTest', - array_merge(range(23, 25), range(27, 31)) - ), - array( - 'NamespaceCoveragePrivateTest', - range(23, 25) - ), - array( - 'NamespaceCoverageProtectedTest', - range(27, 31) - ), - array( - 'NamespaceCoveragePublicTest', - range(33, 37) - ), - array( - 'NamespaceCoverageCoversClassTest', - array_merge(range(23, 25), range(27, 31), range(33, 37), range(6, 8), range(10, 13), range(15, 18)) - ), - array( - 'NamespaceCoverageCoversClassPublicTest', - range(33, 37) - ), - array( - 'CoverageNothingTest', - false - ) - ); - } -} diff --git a/core/vendor/phpunit/phpunit/tests/_files/ExceptionInSetUpTest.php b/core/vendor/phpunit/phpunit/tests/_files/ExceptionInSetUpTest.php deleted file mode 100644 index 9c48030..0000000 --- a/core/vendor/phpunit/phpunit/tests/_files/ExceptionInSetUpTest.php +++ /dev/null @@ -1,35 +0,0 @@ -setUp = true; - throw new Exception; - } - - protected function assertPreConditions() - { - $this->assertPreConditions = true; - } - - public function testSomething() - { - $this->testSomething = true; - } - - protected function assertPostConditions() - { - $this->assertPostConditions = true; - } - - protected function tearDown() - { - $this->tearDown = true; - } -} diff --git a/core/vendor/phpunit/phpunit/tests/_files/ExceptionInTest.php b/core/vendor/phpunit/phpunit/tests/_files/ExceptionInTest.php deleted file mode 100644 index 4ca556e..0000000 --- a/core/vendor/phpunit/phpunit/tests/_files/ExceptionInTest.php +++ /dev/null @@ -1,35 +0,0 @@ -setUp = true; - } - - protected function assertPreConditions() - { - $this->assertPreConditions = true; - } - - public function testSomething() - { - $this->testSomething = true; - throw new Exception; - } - - protected function assertPostConditions() - { - $this->assertPostConditions = true; - } - - protected function tearDown() - { - $this->tearDown = true; - } -}