diff --git a/core/core.services.yml b/core/core.services.yml index a6663b4..b605968 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -639,6 +639,7 @@ services: arguments: ['@authentication', '@current_user'] route_enhancer.entity: class: Drupal\Core\Entity\Enhancer\EntityRouteEnhancer + arguments: ['@controller_resolver', '@entity.manager', '@form_builder'] tags: - { name: route_enhancer, priority: 20 } route_content_controller_subscriber: @@ -646,6 +647,12 @@ services: arguments: ['@content_negotiation'] tags: - { name: event_subscriber } + route_content_form_controller_subscriber: + class: Drupal\Core\EventSubscriber\ContentFormControllerSubscriber + arguments: ['@class_resolver', '@controller_resolver', '@form_builder'] + parent: container.trait + tags: + - { name: event_subscriber } route_special_attributes_subscriber: class: Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber tags: @@ -681,12 +688,7 @@ services: arguments: ['@title_resolver'] tags: - { name: render.main_content_renderer, format: drupal_modal } - controller.form: - class: Drupal\Core\Controller\HtmlFormController - arguments: ['@controller_resolver', '@form_builder', '@class_resolver'] - controller.entity_form: - class: Drupal\Core\Entity\HtmlEntityFormController - arguments: ['@controller_resolver', '@form_builder', '@entity.manager'] + router_listener: class: Symfony\Component\HttpKernel\EventListener\RouterListener tags: diff --git a/core/lib/Drupal/Core/Controller/FormController.php b/core/lib/Drupal/Core/Controller/FormController.php index dc191c0..a9b7a08 100644 --- a/core/lib/Drupal/Core/Controller/FormController.php +++ b/core/lib/Drupal/Core/Controller/FormController.php @@ -19,6 +19,12 @@ */ abstract class FormController { use DependencySerializationTrait; + /** + * The form definition. The format may vary depending on the child class. + * + * @var string + */ + protected $formDefinition; /** * The controller resolver. @@ -57,15 +63,14 @@ public function __construct(ControllerResolverInterface $controller_resolver, Fo * The render array that results from invoking the controller. */ public function getContentResult(Request $request) { - $form_arg = $this->getFormArgument($request); - $form_object = $this->getFormObject($request, $form_arg); + $form_object = $this->getFormObject($request, $this->formDefinition); // Add the form and form_state to trick the getArguments method of the // controller resolver. $form_state = new FormState(); - $request->attributes->set('form', []); + $request->attributes->set('form', array()); $request->attributes->set('form_state', $form_state); - $args = $this->controllerResolver->getArguments($request, [$form_object, 'buildForm']); + $args = $this->controllerResolver->getArguments($request, array($form_object, 'buildForm')); $request->attributes->remove('form'); $request->attributes->remove('form_state'); @@ -77,26 +82,6 @@ public function getContentResult(Request $request) { } /** - * Extracts the form argument string from a request. - * - * Depending on the type of form the argument string may be stored in a - * different request attribute. - * - * One example of a route definition is given below. - * @code - * defaults: - * _form: Drupal\example\Form\ExampleForm - * @endcode - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object from which to extract a form definition string. - * - * @return string - * The form definition string. - */ - abstract protected function getFormArgument(Request $request); - - /** * Returns the object used to build the form. * * @param \Symfony\Component\HttpFoundation\Request $request diff --git a/core/lib/Drupal/Core/Controller/HtmlFormController.php b/core/lib/Drupal/Core/Controller/HtmlFormController.php index 81a9b02..5951b32 100644 --- a/core/lib/Drupal/Core/Controller/HtmlFormController.php +++ b/core/lib/Drupal/Core/Controller/HtmlFormController.php @@ -9,7 +9,9 @@ use Drupal\Core\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; +use Drupal\Core\Controller\ControllerResolverInterface; /** * Wrapping controller for forms that serve as the main page body. @@ -17,6 +19,20 @@ class HtmlFormController extends FormController { /** + * The injection container for this object. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * The name of a class implementing FormInterface that defines a form. + * + * @var string + */ + protected $formClass; + + /** * The class resolver. * * @var \Drupal\Core\DependencyInjection\ClassResolverInterface; @@ -25,24 +41,12 @@ class HtmlFormController extends FormController { /** * Constructs a new \Drupal\Core\Routing\Enhancer\FormEnhancer object. - * - * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver - * The controller resolver. - * @param \Drupal\Core\Form\FormBuilderInterface $form_builder - * The form builder. - * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver - * The class resolver. */ - public function __construct(ControllerResolverInterface $controller_resolver, FormBuilderInterface $form_builder, ClassResolverInterface $class_resolver) { + public function __construct(ClassResolverInterface $class_resolver, ControllerResolverInterface $controller_resolver, ContainerInterface $container, $class, FormBuilderInterface $form_builder) { parent::__construct($controller_resolver, $form_builder); $this->classResolver = $class_resolver; - } - - /** - * @{inheritDoc} - */ - protected function getFormArgument(Request $request) { - return $request->attributes->get('_form'); + $this->container = $container; + $this->formDefinition = $class; } /** diff --git a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php index 7d1c643..d761556 100644 --- a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php +++ b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php @@ -7,6 +7,10 @@ namespace Drupal\Core\Entity\Enhancer; +use Drupal\Core\Controller\ControllerResolverInterface; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\HtmlEntityFormController; +use Drupal\Core\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -17,12 +21,50 @@ class EntityRouteEnhancer implements RouteEnhancerInterface { /** + * The controller resolver. + * + * @var \Drupal\Core\Controller\ControllerResolverInterface + */ + protected $resolver; + + /** + * The entity manager service. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $manager; + + /** + * The form builder. + * + * @var \Drupal\Core\Form\FormBuilderInterface + */ + protected $formBuilder; + + /** + * Constructs a new EntityRouteEnhancer object. + * + * @param \Drupal\Core\Controller\ControllerResolverInterface $resolver + * The controller resolver. + * @param \Drupal\Core\Entity\EntityManagerInterface $manager + * The entity manager. + * @param \Drupal\Core\Form\FormBuilderInterface $form_builder + * The form builder. + */ + public function __construct(ControllerResolverInterface $resolver, EntityManagerInterface $manager, FormBuilderInterface $form_builder) { + $this->resolver = $resolver; + $this->manager = $manager; + $this->formBuilder = $form_builder; + } + + /** * {@inheritdoc} */ public function enhance(array $defaults, Request $request) { if (empty($defaults['_controller'])) { if (!empty($defaults['_entity_form'])) { - $defaults['_controller'] = 'controller.entity_form:getContentResult'; + $wrapper = new HtmlEntityFormController($this->resolver, $this->manager, $this->formBuilder, $defaults['_entity_form']); + $defaults['_controller'] = array($wrapper, 'getContentResult'); } elseif (!empty($defaults['_entity_list'])) { $defaults['_controller'] = '\Drupal\Core\Entity\Controller\EntityListController::listing'; diff --git a/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php b/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php index bd659a9..e575e65 100644 --- a/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php +++ b/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php @@ -29,21 +29,17 @@ class HtmlEntityFormController extends FormController { * * @param \Drupal\Core\Controller\ControllerResolverInterface $resolver * The controller resolver. - * @param \Drupal\Core\Form\FormBuilderInterface $form_builder - * The form builder. * @param \Drupal\Core\Entity\EntityManagerInterface $manager * The entity manager. + * @param \Drupal\Core\Form\FormBuilderInterface $form_builder + * The form builder. + * @param string $form_definition + * The definition of this form, usually found in $defaults['_entity_form']. */ - public function __construct(ControllerResolverInterface $resolver, FormBuilderInterface $form_builder, EntityManagerInterface $manager) { + public function __construct(ControllerResolverInterface $resolver, EntityManagerInterface $manager, FormBuilderInterface $form_builder, $form_definition) { parent::__construct($resolver, $form_builder); $this->manager = $manager; - } - - /** - * @{inheritDoc} - */ - protected function getFormArgument(Request $request) { - return $request->attributes->get('_entity_form'); + $this->formDefinition = $form_definition; } /** @@ -75,7 +71,7 @@ protected function getFormObject(Request $request, $form_arg) { $entity = $request->attributes->get($entity_type); } else { - $entity = $this->manager->getStorage($entity_type)->create([]); + $entity = $this->manager->getStorage($entity_type)->create(array()); } return $this->manager->getFormObject($entity_type, $operation)->setEntity($entity); diff --git a/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php index 32f9565..f2b5128 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php @@ -54,20 +54,6 @@ public function onRequestDeriveFormat(GetResponseEvent $event) { } /** - * Sets the _controller on a request when a _form is defined. - * - * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event - * The event to process. - */ - public function onRequestDeriveFormWrapper(GetResponseEvent $event) { - $request = $event->getRequest(); - - if ($request->attributes->has('_form')) { - $request->attributes->set('_controller', 'controller.form:getContentResult'); - } - } - - /** * Registers the methods in this class that should be listeners. * * @return array @@ -75,7 +61,6 @@ public function onRequestDeriveFormWrapper(GetResponseEvent $event) { */ static function getSubscribedEvents() { $events[KernelEvents::REQUEST][] = array('onRequestDeriveFormat', 31); - $events[KernelEvents::REQUEST][] = array('onRequestDeriveFormWrapper', 29); return $events; } diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php index 373a0be..ed9270a 100644 --- a/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -323,14 +323,12 @@ public function render(&$elements, $is_root_call = FALSE) { // further and create and render new child elements, so provide a fresh // stack frame to collect those additions, merge them back to the element, // and then update the current frame to match the modified element state. - do { - self::$stack->push(new RenderStackFrame()); - $this->processPostRenderCache($elements); - $post_render_additions = self::$stack->pop(); - $elements['#cache']['tags'] = Cache::mergeTags($elements['#cache']['tags'], $post_render_additions->tags); - $elements['#attached'] = drupal_merge_attached($elements['#attached'], $post_render_additions->attached); - $elements['#post_render_cache'] = $post_render_additions->postRenderCache; - } while (!empty($elements['#post_render_cache'])); + self::$stack->push(new RenderStackFrame()); + $this->processPostRenderCache($elements); + $post_render_additions = self::$stack->pop(); + $elements['#cache']['tags'] = Cache::mergeTags($elements['#cache']['tags'], $post_render_additions->tags); + $elements['#attached'] = drupal_merge_attached($elements['#attached'], $post_render_additions->attached); + $elements['#post_render_cache'] = NestedArray::mergeDeep($elements['#post_render_cache'], $post_render_additions->postRenderCache); if (self::$stack->count() !== 1) { throw new \LogicException('A stray drupal_render() invocation with $is_root_call = TRUE is causing bubbling of attached assets to break.'); } @@ -402,7 +400,6 @@ protected function bubbleStack() { * #post_render_cache callbacks may modify: * - #markup: to replace placeholders * - #attached: to add libraries or JavaScript settings - * - #post_render_cache: to execute additional #post_render_cache callbacks * * Note that in either of these cases, #post_render_cache callbacks are * implicitly idempotent: a placeholder that has been replaced can't be @@ -410,6 +407,8 @@ protected function bubbleStack() { * * @param array &$elements * The structured array describing the data being rendered. + * + * @see drupal_render_collect_post_render_cache */ protected function processPostRenderCache(array &$elements) { if (isset($elements['#post_render_cache'])) { diff --git a/core/modules/block/block.module b/core/modules/block/block.module index e87818c..6506ab2 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -24,9 +24,9 @@ function block_help($route_name, RouteMatchInterface $route_match) { $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Placing and moving blocks') . '
'; - $output .= '
' . t('You can place a block by clicking on its title in the Place blocks list on the Block layout page. You can then choose the appropriate region from the Region dropdown menu. Once a block has been placed, it can also be moved to a different region by choosing a region from the Region dropdown menu on the Block layout page, or by dragging and dropping it to the right position.', array('!blocks' => \Drupal::url('block.admin_display'))) . '
'; + $output .= '
' . t('You can place a block by clicking on its title in the in the Place blocks list on the Block layout page. You can then choose the appropriate region from the Region dropdown menu. Once a block has been placed, it can also be moved to a different region by chosing a region from the Region dropdown menu on the Block layout page, or by dragging and dropping it to the right posititon.', array('!blocks' => \Drupal::url('block.admin_display'))) . '
'; $output .= '
' . t('Demonstrating block regions for a theme') . '
'; - $output .= '
' . t('You can see which region is where in a theme by clicking on the Demonstrate block regions link on the Block layout page. Regions are specific to each theme, so you need to toggle to a different theme first to demonstrate its block regions.', array('!blocks' => \Drupal::url('block.admin_display'))) . '
'; + $output .= '
' . t('You can see which region is where in a theme by clicking an the Demonstrate block regions link on the Block layout page. Regions are specific to each theme, so you need to toggle to a different theme first to demonstrate its block regions.', array('!blocks' => \Drupal::url('block.admin_display'))) . '
'; $output .= '
' . t('Toggling between different themes') . '
'; $output .= '
' . t('Blocks are placed and configured specifically for each theme. The Block layout page opens with the default theme, but you can toggle to other installed themes.') . '
'; $output .= '
' . t('Configuring block settings') . '
'; diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index d124ab1..04b6c70 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -15,6 +15,8 @@ use Drupal\Core\Ajax\HtmlCommand; use Drupal\editor\Ajax\EditorDialogSave; use Drupal\Core\Ajax\CloseModalDialogCommand; +use Drupal\Core\Entity\EntityStorageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides an image dialog for text editors. @@ -22,6 +24,29 @@ class EditorImageDialog extends FormBase { /** + * @var EntityStorageInterface $file_storage + */ + protected $fileStorage; + + /** + * The constructor. + * + * @param EntityStorageInterface $file_storage + */ + public function __construct(EntityStorageInterface $file_storage) { + $this->fileStorage = $file_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.manager')->getStorage('file') + ); + } + + /** * {@inheritdoc} */ public function getFormId() { @@ -208,7 +233,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // attributes and set data-entity-type to 'file'. $fid = $form_state->getValue(array('fid', 0)); if (!empty($fid)) { - $file = file_load($fid); + $file = $this->fileStorage->load($fid); $file_url = file_create_url($file->getFileUri()); // Transform absolute image URLs to relative image URLs: prevent problems // on multisite set-ups and prevent mixed content errors. diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 1d78fb3..09ac043 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -618,6 +618,7 @@ function file_file_download($uri) { */ function file_cron() { $age = \Drupal::config('system.file')->get('temporary_maximum_age'); + $file_storage = \Drupal::entityManager()->getStorage('file'); // Only delete temporary files if older than $age. Note that automatic cleanup // is disabled if $age set to 0. @@ -627,9 +628,10 @@ function file_cron() { ->condition('changed', REQUEST_TIME - $age, '<') ->range(0, 100) ->execute(); - $files = file_load_multiple($fids); + $files = $file_storage->loadMultiple($fids); + $file_usage = \Drupal::service('file.usage'); foreach ($files as $file) { - $references = \Drupal::service('file.usage')->listUsage($file); + $references = $file_usage->listUsage($file); if (empty($references)) { if (file_exists($file->getFileUri())) { $file->delete(); @@ -1215,7 +1217,8 @@ function template_preprocess_file_link(&$variables) { $file = $variables['file']; $options = array(); - $file_entity = ($file instanceof File) ? $file : file_load($file->fid); + $file_storage = \Drupal::entityManager()->getStorage('file'); + $file_entity = ($file instanceof FileInterface) ? $file : $file_storage->load($file->fid); $url = file_create_url($file_entity->getFileUri()); $mime_type = $file->getMimeType(); diff --git a/core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php b/core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php index 3c45fe4..2d37523 100644 --- a/core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php @@ -8,11 +8,62 @@ namespace Drupal\file\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FormatterBase; +use Drupal\Core\Entity\EntityStorageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\file\FileStorageInterface; /** * Base class for file formatters. */ -abstract class FileFormatterBase extends FormatterBase { +abstract class FileFormatterBase extends FormatterBase implements ContainerFactoryPluginInterface { + + /** + * @var EntityStorageInterface $file_storage + */ + protected $fileStorage; + + /** + * The FileFormatterBase constructor. + * + * @param string $plugin_id + * The plugin_id for the formatter. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * The definition of the field to which the formatter is associated. + * @param array $settings + * The formatter settings. + * @param string $label + * The formatter label display setting. + * @param string $view_mode + * The view mode. + * @param array $third_party_settings + * Any third party settings. + * @param FileStorageInterface $file_storage + * The file storage. + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, FileStorageInterface $file_storage) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); + $this->fileStorage = $file_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('entity.manager')->getStorage('file') + ); + } /** * {@inheritdoc} @@ -30,7 +81,7 @@ public function prepareView(array $entities_items) { } if ($fids) { - $files = file_load_multiple($fids); + $files = $this->fileStorage->loadMultiple($fids); foreach ($entities_items as $items) { foreach ($items as $item) { diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index d5a3e3d..d163c82 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -16,6 +16,7 @@ use Drupal\Core\Render\Element; use Drupal\file\Element\ManagedFile; use Drupal\Core\Url; +use Drupal\file\Entity\File; /** * Plugin implementation of the 'file_generic' widget. @@ -325,7 +326,7 @@ public static function validateMultipleCount($element, FormStateInterface $form_ $removed_files = array_slice($values['fids'], $keep); $removed_names = array(); foreach ($removed_files as $fid) { - $file = file_load($fid); + $file = File::load($fid); $removed_names[] = $file->getFilename(); } $args = array('%field' => $field_storage->getFieldName(), '@max' => $field_storage->getCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names)); diff --git a/core/modules/file/src/Tests/CopyTest.php b/core/modules/file/src/Tests/CopyTest.php index 3a3a727..56d74a3 100644 --- a/core/modules/file/src/Tests/CopyTest.php +++ b/core/modules/file/src/Tests/CopyTest.php @@ -17,6 +17,7 @@ class CopyTest extends FileManagedUnitTestBase { * Test file copying in the normal, base case. */ function testNormal() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $contents = $this->randomMachineName(10); $source = $this->createFile(NULL, $contents); $desired_uri = 'public://' . $this->randomMachineName(); @@ -39,7 +40,8 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $fid = $result->id(); + $this->assertFileUnchanged($result, $file_storage->load($fid)); } /** @@ -64,11 +66,12 @@ function testExistingRename() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('copy', 'insert')); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->id(), TRUE); - $loaded_target = file_load($target->id(), TRUE); - $loaded_result = file_load($result->id(), TRUE); + $loaded_source = $file_storage->load($source->id()); + $loaded_target = $file_storage->load($target->id()); + $loaded_result = $file_storage->load($result->id()); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -104,11 +107,12 @@ function testExistingReplace() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('load', 'copy', 'update')); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->id(), TRUE); - $loaded_target = file_load($target->id(), TRUE); - $loaded_result = file_load($result->id(), TRUE); + $loaded_source = $file_storage->load($source->id()); + $loaded_target = $file_storage->load($target->id()); + $loaded_result = $file_storage->load($result->id()); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -141,7 +145,8 @@ function testExistingError() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array()); - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->assertFileUnchanged($source, $file_storage->load($source->id())); + $this->assertFileUnchanged($target, $file_storage->load($target->id())); } } diff --git a/core/modules/file/src/Tests/DeleteTest.php b/core/modules/file/src/Tests/DeleteTest.php index f39239f..2290fe3 100644 --- a/core/modules/file/src/Tests/DeleteTest.php +++ b/core/modules/file/src/Tests/DeleteTest.php @@ -17,6 +17,7 @@ class DeleteTest extends FileManagedUnitTestBase { * Tries deleting a normal file (as opposed to a directory, symlink, etc). */ function testUnused() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $file = $this->createFile(); // Check that deletion removes the file and database record. @@ -24,13 +25,14 @@ function testUnused() { $file->delete(); $this->assertFileHooksCalled(array('delete')); $this->assertFalse(file_exists($file->getFileUri()), 'Test file has actually been deleted.'); - $this->assertFalse(file_load($file->id()), 'File was removed from the database.'); + $this->assertFalse($file_storage->load($file->id()), 'File was removed from the database.'); } /** * Tries deleting a file that is in use. */ function testInUse() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); $file_usage->add($file, 'testing', 'test', 1); @@ -40,7 +42,7 @@ function testInUse() { $usage = $file_usage->listUsage($file); $this->assertEqual($usage['testing']['test'], array(1 => 1), 'Test file is still in use.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); - $this->assertTrue(file_load($file->id()), 'File still exists in the database.'); + $this->assertTrue($file_storage->load($file->id()), 'File still exists in the database.'); // Clear out the call to hook_file_load(). file_test_reset(); @@ -50,7 +52,7 @@ function testInUse() { $this->assertFileHooksCalled(array('load', 'update')); $this->assertTrue(empty($usage), 'File usage data was removed.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); - $file = file_load($file->id()); + $file = $file_storage->load($file->id()); $this->assertTrue($file, 'File still exists in the database.'); $this->assertTrue($file->isTemporary(), 'File is temporary.'); file_test_reset(); @@ -69,6 +71,6 @@ function testInUse() { // file_cron() loads $this->assertFileHooksCalled(array('delete')); $this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.'); - $this->assertFalse(file_load($file->id()), 'File was removed from the database.'); + $this->assertFalse($file_storage->load($file->id()), 'File was removed from the database.'); } } diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php index 68c1179..07c5b89 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -57,7 +57,8 @@ function testNodeDisplay() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $node_file = $file_storage->load($node->{$field_name}->target_id); $file_link = array( '#theme' => 'file_link', '#file' => $node_file, diff --git a/core/modules/file/src/Tests/FileFieldPathTest.php b/core/modules/file/src/Tests/FileFieldPathTest.php index bf166ed..a22df25 100644 --- a/core/modules/file/src/Tests/FileFieldPathTest.php +++ b/core/modules/file/src/Tests/FileFieldPathTest.php @@ -17,6 +17,7 @@ class FileFieldPathTest extends FileFieldTestBase { * Tests the normal formatter display on node display. */ function testUploadPath() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; @@ -29,7 +30,7 @@ function testUploadPath() { // Check that the file was uploaded to the file root. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Change the path to contain multiple subdirectories. @@ -41,7 +42,8 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id, TRUE); + $file_storage->resetCache(array($node->{$field_name}->target_id)); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Check the path when used with tokens. @@ -54,7 +56,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); // Do token replacement using the same user which uploaded the file, not // the user running the test case. $data = array('user' => $this->admin_user); diff --git a/core/modules/file/src/Tests/FileFieldRSSContentTest.php b/core/modules/file/src/Tests/FileFieldRSSContentTest.php index 7f04ac2..a655c33 100644 --- a/core/modules/file/src/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/src/Tests/FileFieldRSSContentTest.php @@ -63,7 +63,8 @@ function testFileFieldRSSContent() { // Get the uploaded file from the node. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $node_file = $file_storage->load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); diff --git a/core/modules/file/src/Tests/FileFieldRevisionTest.php b/core/modules/file/src/Tests/FileFieldRevisionTest.php index bf607ee..4777799 100644 --- a/core/modules/file/src/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/src/Tests/FileFieldRevisionTest.php @@ -25,6 +25,7 @@ class FileFieldRevisionTest extends FileFieldTestBase { * should be deleted also. */ function testRevisions() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -40,7 +41,7 @@ function testRevisions() { // Check that the file exists on disk and in the database. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r1 = file_load($node->{$field_name}->target_id); + $node_file_r1 = $file_storage->load($node->{$field_name}->target_id); $node_vid_r1 = $node->getRevisionId(); $this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.'); $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.'); @@ -50,7 +51,7 @@ function testRevisions() { $this->replaceNodeFile($test_file, $field_name, $nid); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r2 = file_load($node->{$field_name}->target_id); + $node_file_r2 = $file_storage->load($node->{$field_name}->target_id); $node_vid_r2 = $node->getRevisionId(); $this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.'); $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.'); @@ -58,7 +59,7 @@ function testRevisions() { // Check that the original file is still in place on the first revision. $node = node_revision_load($node_vid_r1); - $current_file = file_load($node->{$field_name}->target_id); + $current_file = $file_storage->load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $current_file->id(), 'Original file still in place after replacing file in new revision.'); $this->assertFileExists($node_file_r1, 'Original file still in place after replacing file in new revision.'); $this->assertFileEntryExists($node_file_r1, 'Original file entry still in place after replacing file in new revision'); @@ -69,7 +70,7 @@ function testRevisions() { $this->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r3 = file_load($node->{$field_name}->target_id); + $node_file_r3 = $file_storage->load($node->{$field_name}->target_id); $node_vid_r3 = $node->getRevisionId(); $this->assertEqual($node_file_r2->id(), $node_file_r3->id(), 'Previous revision file still in place after creating a new revision without a new file.'); $this->assertFileIsPermanent($node_file_r3, 'New revision file is permanent.'); @@ -78,7 +79,7 @@ function testRevisions() { $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r4 = file_load($node->{$field_name}->target_id); + $node_file_r4 = $file_storage->load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $node_file_r4->id(), 'Original revision file still in place after reverting to the original revision.'); $this->assertFileIsPermanent($node_file_r4, 'Original revision file still permanent after reverting to the original revision.'); diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 0cf36c3..9d884b0 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -216,7 +216,8 @@ function assertFileExists($file, $message = NULL) { */ function assertFileEntryExists($file, $message = NULL) { $this->container->get('entity.manager')->getStorage('file')->resetCache(); - $db_file = file_load($file->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $db_file = $file_storage->load($file->id()); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); $this->assertEqual($db_file->getFileUri(), $file->getFileUri(), $message); } @@ -235,7 +236,8 @@ function assertFileNotExists($file, $message = NULL) { function assertFileEntryNotExists($file, $message) { $this->container->get('entity.manager')->getStorage('file')->resetCache(); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); - $this->assertFalse(file_load($file->id()), $message); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->assertFalse($file_storage->load($file->id()), $message); } /** diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php index 21d93af..44d072e 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -24,6 +24,7 @@ class FileFieldValidateTest extends FileFieldTestBase { * Tests the required property on file fields. */ function testRequired() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -45,7 +46,7 @@ function testRequired() { $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.'); @@ -63,7 +64,7 @@ function testRequired() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.'); } @@ -72,6 +73,7 @@ function testRequired() { * Tests the max file size validator. */ function testFileMaxSize() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -95,7 +97,7 @@ function testFileMaxSize() { $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); @@ -112,7 +114,7 @@ function testFileMaxSize() { $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); } @@ -121,6 +123,7 @@ function testFileMaxSize() { * Tests file extension checking. */ function testFileExtension() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -136,7 +139,7 @@ function testFileExtension() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.'); @@ -155,7 +158,7 @@ function testFileExtension() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.'); } diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index fb3165b..468c6a9 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -29,6 +29,7 @@ class FileFieldWidgetTest extends FileFieldTestBase { * Tests upload and remove buttons for a single-valued File field. */ function testSingleValuedWidget() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -44,7 +45,7 @@ function testSingleValuedWidget() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the file can be downloaded. @@ -205,6 +206,7 @@ function testMultiValuedWidget() { * Tests a file field with a "Private files" upload destination setting. */ function testPrivateFileSetting() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Grant the admin user required permissions. user_role_grant_permissions($this->admin_user->roles[0]->target_id, array('administer node fields')); @@ -222,7 +224,7 @@ function testPrivateFileSetting() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the private file is available to the user who uploaded it. diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index 25b170e..d345bc3 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -56,6 +56,7 @@ protected function sumUsages($usage) { * Tests file overview with different user permissions. */ function testFileListingPages() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $file_usage = $this->container->get('file.usage'); // Users without sufficient permissions should not see file listing. $this->drupalLogin($this->base_user); @@ -96,7 +97,7 @@ function testFileListingPages() { $this->drupalGet('admin/content/files'); foreach ($nodes as $node) { - $file = entity_load('file', $node->file->target_id); + $file = $file_storage->load($node->file->target_id); $this->assertText($file->getFilename()); $this->assertLinkByHref(file_create_url($file->getFileUri())); $this->assertLinkByHref('admin/content/files/usage/' . $file->id()); @@ -110,11 +111,11 @@ function testFileListingPages() { $nodes[1]->save(); $this->drupalGet('admin/content/files'); - $file = entity_load('file', $orphaned_file); + $file = $file_storage->load($orphaned_file); $usage = $this->sumUsages($file_usage->listUsage($file)); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); - $file = entity_load('file', $used_file); + $file = $file_storage->load($used_file); $usage = $this->sumUsages($file_usage->listUsage($file)); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); @@ -123,7 +124,7 @@ function testFileListingPages() { // Test file usage page. foreach ($nodes as $node) { - $file = entity_load('file', $node->file->target_id); + $file = $file_storage->load($node->file->target_id); $usage = $file_usage->listUsage($file); $this->drupalGet('admin/content/files/usage/' . $file->id()); $this->assertResponse(200); diff --git a/core/modules/file/src/Tests/FilePrivateTest.php b/core/modules/file/src/Tests/FilePrivateTest.php index a9f08a5..e3dc44a 100644 --- a/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -36,6 +36,7 @@ protected function setUp() { * Tests file access for file uploaded to a private node. */ function testPrivateFile() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -45,7 +46,7 @@ function testPrivateFile() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); \Drupal::entityManager()->getStorage('node')->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = File::load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); // Ensure the file can be viewed. $this->drupalGet('node/' . $node->id()); $this->assertRaw($node_file->getFilename(), 'File reference is displayed after attaching it'); @@ -65,7 +66,7 @@ function testPrivateFile() { $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); \Drupal::entityManager()->getStorage('node')->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = File::load($node->{$no_access_field_name}->target_id); + $node_file = $file_storage->load($node->{$no_access_field_name}->target_id); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 84d599f..4aea78f 100644 --- a/core/modules/file/src/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php @@ -20,6 +20,7 @@ class FileTokenReplaceTest extends FileFieldTestBase { * Creates a file, then tests the tokens generated from it. */ function testFileTokenReplacement() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $token_service = \Drupal::token(); $language_interface = \Drupal::languageManager()->getCurrentLanguage(); @@ -40,7 +41,7 @@ function testFileTokenReplacement() { // Load the node and the file. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $file = file_load($node->{$field_name}->target_id); + $file = $file_storage->load($node->{$field_name}->target_id); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/file/src/Tests/LoadTest.php b/core/modules/file/src/Tests/LoadTest.php index 7c593cb..c6410c6 100644 --- a/core/modules/file/src/Tests/LoadTest.php +++ b/core/modules/file/src/Tests/LoadTest.php @@ -17,7 +17,8 @@ class LoadTest extends FileManagedUnitTestBase { * Try to load a non-existent file by fid. */ function testLoadMissingFid() { - $this->assertFalse(file_load(-1), 'Try to load an invalid fid fails.'); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->assertFalse($file_storage->load(-1), 'Try to load an invalid fid fails.'); $this->assertFileHooksCalled(array()); } @@ -45,10 +46,10 @@ function testLoadInvalidStatus() { function testSingleValues() { // Create a new file entity from scratch so we know the values. $file = $this->createFile('druplicon.txt', NULL, 'public'); - - $by_fid_file = file_load($file->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $by_fid_file = $file_storage->load($file->id()); $this->assertFileHookCalled('load'); - $this->assertTrue(is_object($by_fid_file), 'file_load() returned an object.'); + $this->assertTrue(is_object($by_fid_file), 'file_storage->load() returned an object.'); $this->assertEqual($by_fid_file->id(), $file->id(), 'Loading by fid got the same fid.', 'File'); $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File'); $this->assertEqual($by_fid_file->getFilename(), $file->getFilename(), 'Loading by fid got the correct filename.', 'File'); @@ -61,6 +62,7 @@ function testSingleValues() { * This will test loading file data from the database. */ function testMultiple() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Create a new file entity. $file = $this->createFile('druplicon.txt', NULL, 'public'); @@ -75,9 +77,9 @@ function testMultiple() { // Load by fid. file_test_reset(); - $by_fid_files = file_load_multiple(array($file->id())); + $by_fid_files = $file_storage->loadMultiple(array($file->id())); $this->assertFileHooksCalled(array()); - $this->assertEqual(1, count($by_fid_files), 'file_load_multiple() returned an array of the correct size.'); + $this->assertEqual(1, count($by_fid_files), 'file_storage->loadMultiple() returned an array of the correct size.'); $by_fid_file = reset($by_fid_files); $this->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.'); $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File'); diff --git a/core/modules/file/src/Tests/MoveTest.php b/core/modules/file/src/Tests/MoveTest.php index 9b1bfc2..89e2459 100644 --- a/core/modules/file/src/Tests/MoveTest.php +++ b/core/modules/file/src/Tests/MoveTest.php @@ -38,7 +38,9 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_file = file_load($result->id(), TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $loaded_file = $file_storage->load($result->id()); $this->assertTrue($loaded_file, 'File can be loaded from the database.'); $this->assertFileUnchanged($result, $loaded_file); } @@ -66,14 +68,18 @@ function testExistingRename() { $this->assertFileHooksCalled(array('move', 'load', 'update')); // Compare the returned value to what made it into the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); // The target file should not have been altered. - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $file_storage->resetCache(array($target->id())); + $this->assertFileUnchanged($target, $file_storage->load($target->id())); // Make sure we end up with two distinct files afterwards. $this->assertDifferentFile($target, $result); // Compare the source and results. - $loaded_source = file_load($source->id(), TRUE); + $file_storage->resetCache(array($source->id())); + $loaded_source = $file_storage->load($source->id()); $this->assertEqual($loaded_source->id(), $result->id(), "Returned file's id matches the source."); $this->assertNotEqual($loaded_source->getFileUri(), $source->getFileUri(), 'Returned file path has changed from the original.'); } @@ -102,7 +108,9 @@ function testExistingReplace() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_result = file_load($result->id(), TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $loaded_result = $file_storage->load($result->id()); $this->assertFileUnchanged($result, $loaded_result); // Check that target was re-used. $this->assertSameFile($target, $loaded_result); @@ -129,7 +137,9 @@ function testExistingReplaceSelf() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($source->id())); + $this->assertFileUnchanged($source, $file_storage->load($source->id())); } /** @@ -156,7 +166,10 @@ function testExistingError() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($source->id())); + $this->assertFileUnchanged($source, $file_storage->load($source->id())); + $file_storage->resetCache(array($target->id())); + $this->assertFileUnchanged($target, $file_storage->load($target->id())); } } diff --git a/core/modules/file/src/Tests/SaveDataTest.php b/core/modules/file/src/Tests/SaveDataTest.php index 8368e0b..43caa4b 100644 --- a/core/modules/file/src/Tests/SaveDataTest.php +++ b/core/modules/file/src/Tests/SaveDataTest.php @@ -32,7 +32,9 @@ function testWithoutFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -57,7 +59,9 @@ function testWithFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -81,11 +85,14 @@ function testExistingRename() { $this->assertFileHooksCalled(array('insert')); // Ensure that the existing file wasn't overwritten. + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($existing->id())); $this->assertDifferentFile($existing, $result); - $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE)); + $this->assertFileUnchanged($existing, $file_storage->load($existing->id())); // Verify that was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -112,7 +119,9 @@ function testExistingReplace() { $this->assertSameFile($existing, $result); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -131,6 +140,8 @@ function testExistingError() { $this->assertFileHooksCalled(array()); // Ensure that the existing file wasn't overwritten. - $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($existing->id())); + $this->assertFileUnchanged($existing, $file_storage->load($existing->id())); } } diff --git a/core/modules/file/src/Tests/SaveTest.php b/core/modules/file/src/Tests/SaveTest.php index ee6c1a3..1afb418 100644 --- a/core/modules/file/src/Tests/SaveTest.php +++ b/core/modules/file/src/Tests/SaveTest.php @@ -16,6 +16,7 @@ */ class SaveTest extends FileManagedUnitTestBase { function testFileSave() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Create a new file entity. $file = entity_create('file', array( 'uid' => 1, @@ -35,7 +36,7 @@ function testFileSave() { $this->assertFileHooksCalled(array('insert')); $this->assertTrue($file->id() > 0, 'A new file ID is set when saving a new file to the database.', 'File'); - $loaded_file = file_load($file->id()); + $loaded_file = $file_storage->load($file->id()); $this->assertNotNull($loaded_file, 'Record exists in the database.'); $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($file->getSize(), filesize($file->getFileUri()), 'File size was set correctly.', 'File'); @@ -52,7 +53,7 @@ function testFileSave() { $this->assertEqual($file->id(), $file->id(), 'The file ID of an existing file is not changed when updating the database.', 'File'); $this->assertTrue($file->getChangedTime() >= $file->getChangedTime(), "Timestamp didn't go backwards.", 'File'); - $loaded_file = file_load($file->id()); + $loaded_file = $file_storage->load($file->id()); $this->assertNotNull($loaded_file, 'Record still exists in the database.', 'File'); $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was saved correctly.'); diff --git a/core/modules/file/src/Tests/SaveUploadTest.php b/core/modules/file/src/Tests/SaveUploadTest.php index 30e681d..d981d79 100644 --- a/core/modules/file/src/Tests/SaveUploadTest.php +++ b/core/modules/file/src/Tests/SaveUploadTest.php @@ -63,9 +63,10 @@ protected function setUp() { * Test the file_save_upload() function. */ function testNormal() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); $this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.'); - $file1 = file_load($max_fid_after); + $file1 = $file_storage->load($max_fid_after); $this->assertTrue($file1, 'Loaded the file.'); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file1->getMimeType(), 0, 5), 'image', 'A MIME type was set.'); @@ -84,13 +85,13 @@ function testNormal() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('validate', 'insert')); - $file2 = file_load($max_fid_after); + $file2 = $file_storage->load($max_fid_after); $this->assertTrue($file2, 'Loaded the file'); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file2->getMimeType(), 0, 5), 'image', 'A MIME type was set.'); - // Load both files using file_load_multiple(). - $files = file_load_multiple(array($file1->id(), $file2->id())); + // Load both files using $file_storage->loadMultiple(). + $files = $file_storage->loadMultiple(array($file1->id(), $file2->id())); $this->assertTrue(isset($files[$file1->id()]), 'File was loaded successfully'); $this->assertTrue(isset($files[$file2->id()]), 'File was loaded successfully'); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index f1faacb..788b0d9 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -344,7 +344,8 @@ function image_entity_presave(EntityInterface $entity) { if ($fid) { $original_fid = isset($entity->original) ? $entity->original->settings['default_image']['fid'] : NULL; if ($fid != $original_fid) { - $file = file_load($fid); + $file_storage = \Drupal::entityManager()->getStorage('file'); + $file = $file_storage->load($fid); if ($file) { $image = \Drupal::service('image.factory')->get($file->getFileUri()); $entity->settings['default_image']['width'] = $image->getWidth(); @@ -373,8 +374,8 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st // The value of a managed_file element can be an array if #extended == TRUE. $fid_new = $field_storage->settings['default_image']['fid']; $fid_old = $prior_field_storage->settings['default_image']['fid']; - - $file_new = $fid_new ? file_load($fid_new) : FALSE; + $file_storage = \Drupal::entityManager()->getStorage('file'); + $file_new = $fid_new ? $file_storage->load($fid_new) : FALSE; if ($fid_new != $fid_old) { @@ -386,7 +387,7 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st } // Is there an old file? - if ($fid_old && ($file_old = file_load($fid_old))) { + if ($fid_old && ($file_old = $file_storage->load($fid_old))) { \Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field_storage->uuid()); } } @@ -414,8 +415,9 @@ function image_field_config_update(FieldConfigInterface $field) { $fid_new = $field->settings['default_image']['fid']; $fid_old = $prior_instance->settings['default_image']['fid']; + $file_storage = \Drupal::entityManager()->getStorage('file'); // If the old and new files do not match, update the default accordingly. - $file_new = $fid_new ? file_load($fid_new) : FALSE; + $file_new = $fid_new ? $file_storage->load($fid_new) : FALSE; if ($fid_new != $fid_old) { // Save the new file, if present. if ($file_new) { @@ -424,7 +426,7 @@ function image_field_config_update(FieldConfigInterface $field) { \Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field->uuid()); } // Delete the old file, if present. - if ($fid_old && ($file_old = file_load($fid_old))) { + if ($fid_old && ($file_old = $file_storage->load($fid_old))) { \Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field->uuid()); } } @@ -448,7 +450,8 @@ function image_field_storage_config_delete(FieldStorageConfigInterface $field) { // The value of a managed_file element can be an array if #extended == TRUE. $fid = $field->settings['default_image']['fid']; - if ($fid && ($file = file_load($fid))) { + $file_storage = \Drupal::entityManager()->getStorage('file'); + if ($fid && ($file = $file_storage->load($fid))) { \Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid()); } } @@ -465,9 +468,9 @@ function image_field_config_delete(FieldConfigInterface $field) { // The value of a managed_file element can be an array if #extended == TRUE. $fid = $field->settings['default_image']['fid']; - + $file_storage = \Drupal::entityManager()->getStorage('file'); // Remove the default image when the instance is deleted. - if ($fid && ($file = file_load($fid))) { + if ($fid && ($file = $file_storage->load($fid))) { \Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid()); } } diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php index e9ab03e..d4dc0a8 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php @@ -14,6 +14,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\Core\Utility\LinkGeneratorInterface; +use Drupal\file\FileStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Form\FormStateInterface; @@ -74,9 +75,11 @@ class ImageFormatter extends ImageFormatterBase implements ContainerFactoryPlugi * The link generator service. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The url generator service. + * @param FileStorageInterface $file_storage + * The file storage. */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, LinkGeneratorInterface $link_generator, UrlGeneratorInterface $url_generator) { - parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, LinkGeneratorInterface $link_generator, UrlGeneratorInterface $url_generator, FileStorageInterface $file_storage) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $file_storage); $this->currentUser = $current_user; $this->linkGenerator = $link_generator; $this->urlGenerator = $url_generator; @@ -96,7 +99,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration['third_party_settings'], $container->get('current_user'), $container->get('link_generator'), - $container->get('url_generator') + $container->get('url_generator'), + $container->get('entity.manager')->getStorage('file') ); } diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php index 62bef76..ffa05c4 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php @@ -32,7 +32,7 @@ public function prepareView(array $entities_items) { $default_image = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('default_image'); } - if (!empty($default_image['fid']) && ($file = file_load($default_image['fid']))) { + if (!empty($default_image['fid']) && ($file = $this->fileStorage->load($default_image['fid']))) { $items->setValue(array(array( 'is_default' => TRUE, 'alt' => $default_image['alt'], diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index 3ecf7c7..5da33f9 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -301,7 +301,8 @@ function testStyleReplacement() { // Get node field original image URI. $fid = $node->get($field_name)->target_id; - $original_uri = file_load($fid)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $original_uri = $file_storage->load($fid)->getFileUri(); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); @@ -435,7 +436,8 @@ function testConfigImport() { // Get node field original image URI. $fid = $node->get($field_name)->target_id; - $original_uri = file_load($fid)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $original_uri = $file_storage->load($fid)->getFileUri(); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index c5dd44d..54da93b 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -251,7 +251,8 @@ public function testDefaultImages() { ); // Confirm the default image is shown on the node form. - $file = File::load($default_images['field_new']->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file = $file_storage->load($default_images['field_new']->id()); $this->drupalGet('node/add/article'); $this->assertRaw($file->getFilename()); @@ -295,7 +296,7 @@ public function testDefaultImages() { $this->assertText(t('The specified file text-0.txt could not be uploaded. Only files with the following extensions are allowed: png gif jpg jpeg.'), 'Non-image file cannot be used as default image.'); // Confirm the default image is shown on the node form. - $file = File::load($default_images['field_new']->id()); + $file = $file_storage->load($default_images['field_new']->id()); $this->drupalGet('node/add/article'); $this->assertRaw($file->getFilename()); } diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index ca9cf28..48f8ebc 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -83,7 +83,8 @@ function _testImageFieldFormatters($scheme) { $node = $node_storage->load($nid); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $image_uri = $file_storage->load($node->{$field_name}->target_id)->getFileUri(); $image = array( '#theme' => 'image', '#uri' => $image_uri, @@ -188,6 +189,7 @@ function _testImageFieldFormatters($scheme) { * Tests for image field settings. */ function testImageFieldSettings() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $test_image = current($this->drupalGetTestFiles('image')); list(, $test_image_extension) = explode('.', $test_image->filename); @@ -222,7 +224,7 @@ function testImageFieldSettings() { $node = $node_storage->load($nid); $image_style = array( '#theme' => 'image_style', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => $file_storage->load($node->{$field_name}->target_id)->getFileUri(), '#width' => 40, '#height' => 20, '#style_name' => 'medium', @@ -233,7 +235,7 @@ function testImageFieldSettings() { // Add alt/title fields to the image and verify that they are displayed. $image = array( '#theme' => 'image', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => $file_storage->load($node->{$field_name}->target_id)->getFileUri(), '#alt' => $this->randomMachineName(), '#title' => $this->randomMachineName(), '#width' => 40, @@ -318,8 +320,9 @@ function testImageFieldDefaultImage() { // Clear field definition cache so the new default image is detected. \Drupal::entityManager()->clearCachedFieldDefinitions(); $field_storage = FieldStorageConfig::loadByName('node', $field_name); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $default_image = $field_storage->getSetting('default_image'); - $file = file_load($default_image['fid']); + $file = $file_storage->load($default_image['fid']); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.'); $image = array( '#theme' => 'image', @@ -342,7 +345,7 @@ function testImageFieldDefaultImage() { $node = $node_storage->load($nid); $image = array( '#theme' => 'image', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => $file_storage->load($node->{$field_name}->target_id)->getFileUri(), '#width' => 40, '#height' => 20, ); @@ -379,7 +382,7 @@ function testImageFieldDefaultImage() { $private_field_storage = FieldStorageConfig::loadByName('node', $private_field_name); $default_image = $private_field_storage->getSetting('default_image'); - $file = file_load($default_image['fid']); + $file = $file_storage->load($default_image['fid']); $this->assertEqual('private', file_uri_scheme($file->getFileUri()), 'Default image uses private:// scheme.'); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.'); // Create a new node with no image attached and ensure that default private diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php index 48645c1..f235888 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php @@ -45,8 +45,9 @@ protected function setUp() { * Tests the Drupal 6 files to Drupal 8 migration. */ public function testFiles() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); /** @var \Drupal\file\FileInterface $file */ - $file = entity_load('file', 1); + $file = $file_storage->load(1); $this->assertEqual($file->getFilename(), 'Image1.png'); $this->assertEqual($file->getSize(), 39325); $this->assertEqual($file->getFileUri(), 'public://image-1.png'); @@ -66,7 +67,7 @@ public function testFiles() { $executable = new MigrateExecutable($migration, $this); $executable->import(); - $file = entity_load('file', 2); + $file = $file_storage->load(2); $this->assertEqual($file->getFileUri(), 'public://core/modules/simpletest/files/image-2.jpg'); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php index ff204f7..d787d21 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php @@ -48,8 +48,8 @@ public function testUserPictures() { foreach (entity_load('migration', 'd6_user_picture_file')->getIdMap() as $destination_ids) { $file_ids[] = reset($destination_ids); } - $files = entity_load_multiple('file', $file_ids); - /** @var \Drupal\file\FileInterface $file */ + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $files = $file_storage->loadMultiple($file_ids); $file = array_shift($files); $this->assertEqual($file->getFilename(), 'image-test.jpg'); $this->assertEqual($file->getFileUri(), 'public://image-test.jpg'); diff --git a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php index e6aea38..ec13e4d 100644 --- a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php @@ -68,7 +68,9 @@ protected function setUp() { $node_storage->resetCache(array($nid)); $this->node = $node_storage->load($nid); - $this->file = file_load($this->node->{$this->fieldName}->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->file = $file_storage->load($this->node->{$this->fieldName}->target_id); + } diff --git a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php index ec41a77..2f9b3e0 100644 --- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php @@ -68,7 +68,8 @@ protected function setUp() { // Save a node with the image. $nid = $this->uploadNodeImage($image, $this->fieldName, 'article'); $this->node = Node::load($nid); - $this->file = file_load($this->node->{$this->fieldName}->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->file = $file_storage->load($this->node->{$this->fieldName}->target_id); } /** diff --git a/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php index a1308e9..133d217 100644 --- a/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php +++ b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php @@ -15,6 +15,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\file\FileStorageInterface; /** * Plugin for responsive image formatter. @@ -51,11 +52,13 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa * The view mode. * @param array $third_party_settings * Any third party settings. + * @param \Drupal\file\FileStorageInterface $file_storage + * The file storage. * @param \Drupal\Core\Entity\EntityStorageInterface $responsive_image_mapping_storage * The responsive image mapping storage. */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityStorageInterface $responsive_image_mapping_storage) { - parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, FileStorageInterface $file_storage, EntityStorageInterface $responsive_image_mapping_storage) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $file_storage); $this->responsiveImageMappingStorage = $responsive_image_mapping_storage; } @@ -72,6 +75,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], + $container->get('entity.manager')->getStorage('file'), $container->get('entity.manager')->getStorage('responsive_image_mapping') ); } diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index 41e4f1c..5fef3e6 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -133,7 +133,8 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles = $node = $node_storage->load($nid); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $image_uri = $file_storage->load($node->{$field_name}->target_id)->getFileUri(); $image = array( '#theme' => 'image', '#uri' => $image_uri, diff --git a/core/modules/system/css/system.admin.css b/core/modules/system/css/system.admin.css index add899d..ac89af6 100644 --- a/core/modules/system/css/system.admin.css +++ b/core/modules/system/css/system.admin.css @@ -222,6 +222,21 @@ small .admin-link:after { } /** + * Theme settings. + */ +.theme-settings-left { + float: left; + width: 49%; +} +.theme-settings-right { + float: right; + width: 49%; +} +.theme-settings-bottom { + clear: both; +} + +/** * Appearance page. */ .theme-info__header { diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 44649d2..25568b0 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -147,6 +147,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme = '#type' => 'details', '#title' => t('Logo image settings'), '#open' => TRUE, + '#attributes' => array('class' => array('theme-settings-bottom')), '#states' => array( // Hide the logo image settings fieldset when logo display is disabled. 'invisible' => array( diff --git a/core/modules/system/src/Tests/Common/RenderTest.php b/core/modules/system/src/Tests/Common/RenderTest.php index 8f801d8..523ab62 100644 --- a/core/modules/system/src/Tests/Common/RenderTest.php +++ b/core/modules/system/src/Tests/Common/RenderTest.php @@ -796,10 +796,6 @@ function testDrupalRenderChildrenPostRenderCache() { function testDrupalRenderRenderCachePlaceholder() { $context = array( 'bar' => $this->randomContextValue(), - // Provide a token instead of letting one be generated by - // drupal_render_cache_generate_placeholder(), otherwise we cannot know - // what the token is. - 'token' => \Drupal\Component\Utility\Crypt::randomBytesBase64(55), ); $callback = 'common_test_post_render_cache_placeholder'; $placeholder = drupal_render_cache_generate_placeholder($callback, $context); @@ -841,7 +837,7 @@ function testDrupalRenderRenderCachePlaceholder() { $this->assertIdentical($element['#attached']['js'], $expected_js, '#attached is modified; JavaScript setting is added to page.'); // GET request: validate cached data. - $expected_token = $context['token']; + $expected_token = $element['#post_render_cache']['common_test_post_render_cache_placeholder'][0]['token']; $element = array('#cache' => array('cid' => 'render_cache_placeholder_test_GET')); $cached_element = \Drupal::cache('render')->get(drupal_render_cid_create($element))->data; // Parse unique token out of the cached markup. @@ -887,10 +883,6 @@ function testDrupalRenderRenderCachePlaceholder() { function testDrupalRenderChildElementRenderCachePlaceholder() { $context = array( 'bar' => $this->randomContextValue(), - // Provide a token instead of letting one be generated by - // drupal_render_cache_generate_placeholder(), otherwise we cannot know - // what the token is. - 'token' => \Drupal\Component\Utility\Crypt::randomBytesBase64(55), ); $callback = 'common_test_post_render_cache_placeholder'; $placeholder = drupal_render_cache_generate_placeholder($callback, $context); @@ -928,13 +920,15 @@ function testDrupalRenderChildElementRenderCachePlaceholder() { $element['foo']['#cache'] = array('cid' => 'render_cache_placeholder_test_child_GET'); // Render, which will use the common-test-render-element.html.twig template. $output = drupal_render_root($element); - $this->assertIdentical($output, $expected_output, 'Placeholder was replaced in output'); + $this->assertIdentical($output, $expected_output); //, 'Placeholder was replaced in output'); $this->assertTrue(isset($element['#printed']), 'No cache hit'); $this->assertIdentical($element['#markup'], $expected_output, 'Placeholder was replaced in #markup.'); $this->assertIdentical($element['#attached']['js'], $expected_js, '#attached is modified; JavaScript setting is added to page.'); // GET request: validate cached data for child element. - $expected_token = $context['token']; + $child_tokens = $element['foo']['#post_render_cache']['common_test_post_render_cache_placeholder'][0]['token']; + $parent_tokens = $element['#post_render_cache']['common_test_post_render_cache_placeholder'][0]['token']; + $expected_token = $child_tokens; $element = array('#cache' => array('cid' => 'render_cache_placeholder_test_child_GET')); $cached_element = \Drupal::cache('render')->get(drupal_render_cid_create($element))->data; // Parse unique token out of the cached markup. @@ -984,7 +978,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() { ), '#cache' => array('tags' => array('rendered')), ); - $this->assertIdentical($cached_element, $expected_element, 'The correct data is cached for the parent element: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.'); + $this->assertIdentical($cached_element, $expected_element); //, 'The correct data is cached for the parent element: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.'); // GET request: validate cached data. // Check the cache of the child element again after the parent has been @@ -993,6 +987,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() { $cached_element = \Drupal::cache('render')->get(drupal_render_cid_create($element))->data; // Verify that the child element contains the correct // render_cache_placeholder markup. + $expected_token = $child_tokens; $dom = Html::load($cached_element['#markup']); $xpath = new \DOMXPath($dom); $nodes = $xpath->query('//*[@token]'); @@ -1030,31 +1025,6 @@ function testDrupalRenderChildElementRenderCachePlaceholder() { } /** - * Tests a #post_render_cache callback that adds another #post_render_cache - * callback. - * - * E.g. when rendering a node in a #post_render_cache callback, the rendering - * of that node needs a #post_render_cache callback of its own to be executed - * (to render the node links). - */ - function testRecursivePostRenderCache() { - $context = array('foo' => $this->randomContextValue()); - $element = []; - $element['#markup'] = ''; - $element['#post_render_cache']['common_test_post_render_cache_recursion'] = array( - $context - ); - - $output = drupal_render_root($element); - $this->assertEqual('

overridden

', $output, 'The output has been modified by the indirect, recursive #post_render_cache callback.'); - $this->assertIdentical($element['#markup'], '

overridden

', '#markup is overridden by the indirect, recursive #post_render_cache callback.'); - $expected_js = [ - ['type' => 'setting', 'data' => ['common_test' => $context]], - ]; - $this->assertIdentical($element['#attached']['js'], $expected_js, '#attached is modified by the indirect, recursive #post_render_cache callback.'); - } - - /** * #pre_render callback for testDrupalRenderBubbling(). */ public static function bubblingPreRender($elements) { @@ -1153,7 +1123,18 @@ function testDrupalRenderBubbling() { ), ); $this->assertEqual($expected_attached, $test_element['#attached'], 'Expected assets found.'); - $this->assertEqual([], $test_element['#post_render_cache'], '#post_render_cache property is empty after rendering'); + $expected_post_render_cache = array( + 'Drupal\\system\\Tests\\Common\\RenderTest::bubblingPostRenderCache' => array( + 0 => array ( + 'foo' => 'bar', + 'baz' => 'qux', + ), + ), + ); + $post_render_cache = $test_element['#post_render_cache']; + // We don't care about the exact token. + unset($post_render_cache['Drupal\\system\\Tests\\Common\\RenderTest::bubblingPostRenderCache'][0]['token']); + $this->assertEqual($expected_post_render_cache, $post_render_cache, 'Expected post-render cache data found.'); // Ensure that #pre_render callbacks are only executed if they don't have // a render cache hit. diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 3e040a4..2f510cd 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -251,7 +251,8 @@ public function testFileHooks() { )); $GLOBALS['entity_crud_hook_test'] = array(); - $file = file_load($file->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file = $file_storage->load($file->id()); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type file', diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module index 24aa3da..a1100b4 100644 --- a/core/modules/system/tests/modules/common_test/common_test.module +++ b/core/modules/system/tests/modules/common_test/common_test.module @@ -255,34 +255,6 @@ function common_test_post_render_cache_placeholder(array $element, array $contex } /** - * #post_render_cache callback; bubbles another #post_render_cache callback. - * - * @param array $element - * A render array with the following keys: - * - #markup - * - #attached - * @param array $context - * An array with the following keys: - * - foo: contains a random string. - * - * @return array $element - * The updated $element. - */ -function common_test_post_render_cache_recursion(array $element, array $context) { - // Render a child which itself also has a #post_render_cache callback that - // must be bubbled. - $child = []; - $child['#markup'] = 'foo'; - $child['#post_render_cache']['common_test_post_render_cache'][] = $context; - - // Render the child. - $element['#markup'] = drupal_render($child); - - return $element; -} - - -/** * Implements hook_page_attachments(). * * @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions() diff --git a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module index 0325dbd..4cf118f 100644 --- a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module +++ b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\file\Entity\File; /** * Implements hook_entity_create(). diff --git a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php index 9cb3372..91c59de 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php @@ -83,7 +83,8 @@ public function testTaxonomyImageAccess() { // Create a user that should have access to the file and one that doesn't. $access_user = $this->drupalCreateUser(array('access content')); $no_access_user = $this->drupalCreateUser(); - $image = file_load($term->field_test->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $image = $file_storage->load($term->field_test->target_id); $this->drupalLogin($access_user); $this->drupalGet(file_create_url($image->getFileUri())); $this->assertResponse(200, 'Private image on term is accessible with right permission'); diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php index 639c382..16fa963 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -72,7 +72,9 @@ function testCreateDeletePicture() { \Drupal::service('cron')->run(); // Verify that the image has been deleted. - $this->assertFalse(file_load($file->id(), TRUE), 'File was removed from the database.'); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($file->id())); + $this->assertFalse($file_storage->load($file->id()), 'File was removed from the database.'); // Clear out PHP's file stat cache so we see the current value. clearstatcache(TRUE, $file->getFileUri()); $this->assertFalse(is_file($file->getFileUri()), 'File was removed from the file system.'); @@ -134,6 +136,8 @@ function saveUserPicture($image) { // Load actual user data from database. $account = user_load($this->web_user->id(), TRUE); - return file_load($account->user_picture->target_id, TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($account->user_picture->target_id)); + return $file_storage->load($account->user_picture->target_id); } } diff --git a/core/tests/Drupal/Tests/Component/Utility/BytesTest.php b/core/tests/Drupal/Tests/Component/Utility/BytesTest.php index 8e72b6c..bfacd6c 100644 --- a/core/tests/Drupal/Tests/Component/Utility/BytesTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/BytesTest.php @@ -11,11 +11,8 @@ use Drupal\Tests\UnitTestCase; /** - * Tests bytes size parsing helper methods. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\Bytes + * @group Utility */ class BytesTest extends UnitTestCase { @@ -46,7 +43,6 @@ public function testToInt($size, $expected_int) { */ public function providerTestToInt() { return array( - array('1', 1), array('1 byte', 1), array('1 KB' , Bytes::KILOBYTE), array('1 MB' , pow(Bytes::KILOBYTE, 2)), diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php index bf6ca27..94929ee 100644 --- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php @@ -11,18 +11,13 @@ use Drupal\Component\Utility\Crypt; /** - * Tests random byte generation. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\Crypt + * @group Utility */ class CryptTest extends UnitTestCase { /** - * Tests random byte generation. - * - * @covers ::randomBytes + * Tests \Drupal\Component\Utility\Crypt::randomBytes(). */ public function testRandomBytes() { for ($i = 1; $i < 10; $i++) { @@ -35,15 +30,14 @@ public function testRandomBytes() { } /** - * Tests hash generation. - * - * @dataProvider providerTestHashBase64 - * @covers ::hashBase64 + * Tests \Drupal\Component\Utility\Crypt::hashBase64(). * * @param string $data * Data to hash. * @param string $expected_hash * Expected result from hashing $data. + * + * @dataProvider providerTestHashBase64 */ public function testHashBase64($data, $expected_hash) { $hash = Crypt::hashBase64($data); @@ -51,10 +45,7 @@ public function testHashBase64($data, $expected_hash) { } /** - * Tests HMAC generation. - * - * @dataProvider providerTestHmacBase64 - * @covers ::hmacBase64 + * Tests \Drupal\Component\Utility\Crypt::hmacBase64(). * * @param string $data * Data to hash. @@ -62,6 +53,8 @@ public function testHashBase64($data, $expected_hash) { * Key to use in hashing process. * @param string $expected_hmac * Expected result from hashing $data using $key. + * + * @dataProvider providerTestHmacBase64 */ public function testHmacBase64($data, $key, $expected_hmac) { $hmac = Crypt::hmacBase64($data, $key); @@ -71,14 +64,13 @@ public function testHmacBase64($data, $key, $expected_hmac) { /** * Tests the hmacBase64 method with invalid parameters. * - * @dataProvider providerTestHmacBase64Invalid - * @expectedException InvalidArgumentException - * @covers ::hmacBase64 - * * @param string $data * Data to hash. * @param string $key * Key to use in hashing process. + * + * @dataProvider providerTestHmacBase64Invalid + * @expectedException InvalidArgumentException */ public function testHmacBase64Invalid($data, $key) { Crypt::hmacBase64($data, $key); diff --git a/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php b/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php index 72f04f7..d7713e0 100644 --- a/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php @@ -11,20 +11,14 @@ use Drupal\Tests\UnitTestCase; /** - * Test PHP Environment helper methods. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\Environment + * @group Utility */ class EnvironmentTest extends UnitTestCase { /** * Tests \Drupal\Component\Utility\Environment::checkMemoryLimit(). * - * @dataProvider providerTestCheckMemoryLimit - * @covers ::checkMemoryLimit - * * @param string $required * The required memory argument for * \Drupal\Component\Utility\Environment::checkMemoryLimit(). @@ -34,6 +28,9 @@ class EnvironmentTest extends UnitTestCase { * @param bool $expected * The expected return value from * \Drupal\Component\Utility\Environment::checkMemoryLimit(). + * + * @dataProvider providerTestCheckMemoryLimit + * @covers ::checkMemoryLimit */ public function testCheckMemoryLimit($required, $custom_memory_limit, $expected) { $actual = Environment::checkMemoryLimit($required, $custom_memory_limit); diff --git a/core/tests/Drupal/Tests/Component/Utility/NumberAlphadecimalTest.php b/core/tests/Drupal/Tests/Component/Utility/NumberAlphadecimalTest.php new file mode 100644 index 0000000..01d2c2b --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Utility/NumberAlphadecimalTest.php @@ -0,0 +1,56 @@ +assertSame(Number::intToAlphadecimal($value), $expected); + $this->assertSame($value, Number::alphadecimalToInt($expected)); + } + + /** + * Data provider for testConversions(). + * + * @see testConversions() + * + * @return array + * An array containing: + * - The integer value. + * - The alphadecimal value. + */ + public function providerTestConversions() { + return array( + array(0, '00'), + array(1, '01'), + array(10, '0a'), + array(20, '0k'), + array(35, '0z'), + array(36, '110'), + array(100, '12s'), + ); + } + +} diff --git a/core/tests/Drupal/Tests/Component/Utility/NumberTest.php b/core/tests/Drupal/Tests/Component/Utility/NumberTest.php index 4e6b967..088a0f3 100644 --- a/core/tests/Drupal/Tests/Component/Utility/NumberTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/NumberTest.php @@ -13,26 +13,23 @@ use Drupal\Tests\UnitTestCase; /** - * Tests number manipulation utilities. + * Tests number step validation by Number::validStep(). * * @group Utility - * - * @coversDefaultClass \Drupal\Component\Utility\Number */ class NumberTest extends UnitTestCase { /** * Tests Number::validStep() without offset. * - * @dataProvider providerTestValidStep - * @covers ::validStep - * * @param numeric $value * The value argument for Number::validStep(). * @param numeric $step * The step argument for Number::validStep(). * @param boolean $expected * Expected return value from Number::validStep(). + * + * @dataProvider providerTestValidStep */ public function testValidStep($value, $step, $expected) { $return = Number::validStep($value, $step); @@ -42,9 +39,6 @@ public function testValidStep($value, $step, $expected) { /** * Tests Number::validStep() with offset. * - * @dataProvider providerTestValidStepOffset - * @covers ::validStep - * * @param numeric $value * The value argument for Number::validStep(). * @param numeric $step @@ -53,6 +47,8 @@ public function testValidStep($value, $step, $expected) { * The offset argument for Number::validStep(). * @param boolean $expected * Expected return value from Number::validStep(). + * + * @dataProvider providerTestValidStepOffset */ public function testValidStepOffset($value, $step, $offset, $expected) { $return = Number::validStep($value, $step, $offset); @@ -121,43 +117,4 @@ public static function providerTestValidStepOffset() { ); } - /** - * Tests the alphadecimal conversion functions. - * - * @dataProvider providerTestConversions - * @covers ::intToAlphadecimal - * @covers ::alphadecimalToInt - * - * @param int $value - * The integer value. - * @param string $expected - * The expected alphadecimal value. - */ - public function testConversions($value, $expected) { - $this->assertSame(Number::intToAlphadecimal($value), $expected); - $this->assertSame($value, Number::alphadecimalToInt($expected)); - } - - /** - * Data provider for testConversions(). - * - * @see testConversions() - * - * @return array - * An array containing: - * - The integer value. - * - The alphadecimal value. - */ - public function providerTestConversions() { - return array( - array(0, '00'), - array(1, '01'), - array(10, '0a'), - array(20, '0k'), - array(35, '0z'), - array(36, '110'), - array(100, '12s'), - ); - } - } diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php index 716059f..cda119e 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -12,11 +12,8 @@ use Drupal\Tests\UnitTestCase; /** - * Tests random data generation. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\Random + * @group Utility */ class RandomTest extends UnitTestCase { @@ -32,7 +29,7 @@ class RandomTest extends UnitTestCase { /** * Tests unique random string generation. * - * @covers ::string + * @see \Drupal\Component\Utility\Random::string() */ public function testRandomStringUniqueness() { $strings = array(); @@ -47,7 +44,7 @@ public function testRandomStringUniqueness() { /** * Tests unique random name generation. * - * @covers ::name + * @see \Drupal\Component\Utility\Random::name() */ public function testRandomNamesUniqueness() { $names = array(); @@ -62,8 +59,9 @@ public function testRandomNamesUniqueness() { /** * Tests infinite loop prevention whilst generating random names. * - * @covers ::name - * @expectedException \RuntimeException + * @see \Drupal\Component\Utility\Random::name() + * + * @expectedException RuntimeException */ public function testRandomNameException() { // There are fewer than 100 possibilities so an exception should occur to @@ -78,8 +76,9 @@ public function testRandomNameException() { /** * Tests infinite loop prevention whilst generating random strings. * - * @covers ::string - * @expectedException \RuntimeException + * @see \Drupal\Component\Utility\Random::string() + * + * @expectedException RuntimeException */ public function testRandomStringException() { // There are fewer than 100 possibilities so an exception should occur to @@ -94,7 +93,7 @@ public function testRandomStringException() { /** * Tests random name generation if uniqueness is not enforced. * - * @covers ::name + * @see \Drupal\Component\Utility\Random::name() */ public function testRandomNameNonUnique() { // There are fewer than 100 possibilities if we were forcing uniqueness so @@ -109,7 +108,7 @@ public function testRandomNameNonUnique() { /** * Tests random string if uniqueness is not enforced. * - * @covers ::string + * @see \Drupal\Component\Utility\Random::string() */ public function testRandomStringNonUnique() { // There are fewer than 100 possibilities if we were forcing uniqueness so @@ -124,7 +123,7 @@ public function testRandomStringNonUnique() { /** * Tests random object generation to ensure the expected number of properties. * - * @covers ::object + * @see \Drupal\Component\Utility\Random::object() */ public function testRandomObject() { // For values of 0 and 1 \Drupal\Component\Utility\Random::object() will @@ -139,7 +138,7 @@ public function testRandomObject() { /** * Tests random string validation callbacks. * - * @covers ::string + * @see \Drupal\Component\Utility\Random::name() */ public function testRandomStringValidator() { $random = new Random(); diff --git a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php index cd8eff7..c2804e4 100644 --- a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php @@ -11,11 +11,8 @@ use Drupal\Component\Utility\SortArray; /** - * Tests the SortArray component. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\SortArray + * @group Utility */ class SortArrayTest extends UnitTestCase { @@ -23,8 +20,6 @@ class SortArrayTest extends UnitTestCase { * Tests SortArray::sortByWeightElement() input against expected output. * * @dataProvider providerSortByWeightElement - * @covers ::sortByWeightElement - * @covers ::sortByKeyInt * * @param array $a * The first input array for the SortArray::sortByWeightElement() method. @@ -32,6 +27,9 @@ class SortArrayTest extends UnitTestCase { * The second input array for the SortArray::sortByWeightElement(). * @param integer $expected * The expected output from calling the method. + * + * @see \Drupal\Component\Utility\SortArray::sortByWeightElement() + * @see \Drupal\Tests\Component\Utility\SortArrayTest::providersortByWeightElement() */ public function testSortByWeightElement($a, $b, $expected) { $result = SortArray::sortByWeightElement($a, $b); @@ -45,6 +43,7 @@ public function testSortByWeightElement($a, $b, $expected) { * An array of tests, matching the parameter inputs for * testSortByWeightElement. * + * @see \Drupal\Component\Utility\SortArray::sortByWeightElement() * @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByWeightElement() */ public function providerSortByWeightElement() { @@ -99,8 +98,6 @@ public function providerSortByWeightElement() { * Tests SortArray::sortByWeightProperty() input against expected output. * * @dataProvider providerSortByWeightProperty - * @covers ::sortByWeightProperty - * @covers ::sortByKeyInt * * @param array $a * The first input array for the SortArray::sortByWeightProperty() method. @@ -108,6 +105,9 @@ public function providerSortByWeightElement() { * The second input array for the SortArray::sortByWeightProperty(). * @param integer $expected * The expected output from calling the method. + * + * @see \Drupal\Component\Utility\SortArray::sortByWeightProperty() + * @see \Drupal\Tests\Component\Utility\SortArrayTest::SortByWeightProperty() */ public function testSortByWeightProperty($a, $b, $expected) { $result = SortArray::sortByWeightProperty($a, $b); @@ -121,6 +121,7 @@ public function testSortByWeightProperty($a, $b, $expected) { * An array of tests, matching the parameter inputs for * testSortByWeightProperty. * + * @see \Drupal\Component\Utility\SortArray::sortByWeightProperty() * @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByWeightProperty() */ public function providerSortByWeightProperty() { @@ -175,8 +176,6 @@ public function providerSortByWeightProperty() { * Tests SortArray::sortByTitleElement() input against expected output. * * @dataProvider providerSortByTitleElement - * @covers ::sortByTitleElement - * @covers ::sortByKeyString * * @param array $a * The first input item for comparison. @@ -184,6 +183,9 @@ public function providerSortByWeightProperty() { * The second item for comparison. * @param integer $expected * The expected output from calling the method. + * + * @see \Drupal\Component\Utility\SortArray::sortByTitleElement() + * @see \Drupal\Tests\Component\Utility\SortArrayTest::providerSortByTitleElement() */ public function testSortByTitleElement($a, $b, $expected) { $result = SortArray::sortByTitleElement($a, $b); @@ -197,6 +199,7 @@ public function testSortByTitleElement($a, $b, $expected) { * An array of tests, matching the parameter inputs for * testSortByTitleElement. * + * @see \Drupal\Component\Utility\SortArray::sortByTitleElement() * @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByTitleElement() */ public function providerSortByTitleElement() { @@ -244,8 +247,6 @@ public function providerSortByTitleElement() { * Tests SortArray::sortByTitleProperty() input against expected output. * * @dataProvider providerSortByTitleProperty - * @covers ::sortByTitleProperty - * @covers ::sortByKeyString * * @param array $a * The first input item for comparison. @@ -253,6 +254,9 @@ public function providerSortByTitleElement() { * The second item for comparison. * @param integer $expected * The expected output from calling the method. + * + * @see \Drupal\Component\Utility\SortArray::sortByTitleProperty() + * @see \Drupal\Tests\Component\Utility\SortArrayTest::SortByTitleProperty() */ public function testSortByTitleProperty($a, $b, $expected) { $result = SortArray::sortByTitleProperty($a, $b); @@ -266,6 +270,7 @@ public function testSortByTitleProperty($a, $b, $expected) { * An array of tests, matching the parameter inputs for * testSortByTitleProperty. * + * @see \Drupal\Component\Utility\SortArray::sortByTitleProperty() * @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByTitleProperty() */ public function providerSortByTitleProperty() { diff --git a/core/tests/Drupal/Tests/Component/Utility/StringTest.php b/core/tests/Drupal/Tests/Component/Utility/StringTest.php index 358ee2d..21127b5 100644 --- a/core/tests/Drupal/Tests/Component/Utility/StringTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/StringTest.php @@ -11,11 +11,8 @@ use Drupal\Component\Utility\String; /** - * Tests string filtering. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\String + * @group Utility */ class StringTest extends UnitTestCase { @@ -23,7 +20,6 @@ class StringTest extends UnitTestCase { * Tests String::checkPlain(). * * @dataProvider providerCheckPlain - * @covers ::checkPlain * * @param string $text * The text to provide to String::checkPlain(). @@ -61,7 +57,6 @@ function providerCheckPlain() { * Tests string formatting with String::format(). * * @dataProvider providerFormat - * @covers ::format * * @param string $string * The string to run through String::format(). @@ -71,6 +66,8 @@ function providerCheckPlain() { * The expected result from calling the function. * @param string $message * The message to display as output to the test. + * + * @see String::format() */ function testFormat($string, $args, $expected, $message) { $result = String::format($string, $args); @@ -94,7 +91,7 @@ function providerFormat() { /** * Tests String::placeholder(). * - * @covers ::placeholder + * @see String::placeholder() */ function testPlaceholder() { $this->assertEquals('Some text', String::placeholder('Some text')); @@ -104,7 +101,6 @@ function testPlaceholder() { * Tests String::decodeEntities(). * * @dataProvider providerDecodeEntities - * @covers ::decodeEntities */ public function testDecodeEntities($text, $expected) { $this->assertEquals($expected, String::decodeEntities($text)); diff --git a/core/tests/Drupal/Tests/Component/Utility/TimerTest.php b/core/tests/Drupal/Tests/Component/Utility/TimerTest.php index cfb05dd..f306896 100644 --- a/core/tests/Drupal/Tests/Component/Utility/TimerTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/TimerTest.php @@ -11,20 +11,15 @@ use Drupal\Component\Utility\Timer; /** - * Tests the Timer system. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\Timer + * @group Utility */ class TimerTest extends UnitTestCase { /** * Tests Timer::read() time accumulation accuracy across multiple restarts. * - * @covers ::start - * @covers ::stop - * @covers ::read + * @see \Drupal\Component\Utility\Timer::read() */ public function testTimer() { Timer::start('test'); diff --git a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php index b9861c2..11d3a83 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php @@ -11,30 +11,20 @@ use Drupal\Component\Utility\Unicode; /** - * Test unicode handling features implemented in Unicode component. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\Unicode + * @group Utility */ class UnicodeTest extends UnitTestCase { - /** - * {@inheritdoc} - * - * @covers ::check - */ - public function setUp() { + protected function setUp() { // Initialize unicode component. Unicode::check(); } /** - * Getting and settings the multibyte environment status. + * Tests Unicode::getStatus() and Unicode::setStatus(). * * @dataProvider providerTestStatus - * @covers ::getStatus - * @covers ::setStatus */ public function testStatus($value, $expected, $invalid = FALSE) { if ($invalid) { @@ -68,11 +58,9 @@ public function providerTestStatus() { } /** - * Tests multibyte encoding and decoding. + * Tests Unicode::mimeHeaderEncode() and Unicode::mimeHeaderDecode(). * * @dataProvider providerTestMimeHeader - * @covers ::mimeHeaderEncode - * @covers ::mimeHeaderDecode */ public function testMimeHeader($value, $encoded) { $this->assertEquals($encoded, Unicode::mimeHeaderEncode($value)); @@ -96,11 +84,9 @@ public function providerTestMimeHeader() { } /** - * Tests multibyte strtolower. + * Tests Unicode::strtolower(). * * @dataProvider providerStrtolower - * @covers ::strtolower - * @covers ::caseFlip */ public function testStrtolower($text, $expected, $multibyte = FALSE) { $status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE; @@ -133,11 +119,9 @@ public function providerStrtolower() { } /** - * Tests multibyte strtoupper. + * Tests Unicode::strtoupper(). * * @dataProvider providerStrtoupper - * @covers ::strtoupper - * @covers ::caseFlip */ public function testStrtoupper($text, $expected, $multibyte = FALSE) { $status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE; @@ -170,10 +154,9 @@ public function providerStrtoupper() { } /** - * Tests multibyte ucfirst. + * Tests Unicode::ucfirst(). * * @dataProvider providerUcfirst - * @covers ::ucfirst */ public function testUcfirst($text, $expected) { $this->assertEquals($expected, Unicode::ucfirst($text)); @@ -199,10 +182,9 @@ public function providerUcfirst() { } /** - * Tests multibyte lcfirst. + * Tests Unicode::lcfirst(). * * @dataProvider providerLcfirst - * @covers ::lcfirst */ public function testLcfirst($text, $expected, $multibyte = FALSE) { $status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE; @@ -231,10 +213,9 @@ public function providerLcfirst() { } /** - * Tests multibyte ucwords. + * Tests Unicode::ucwords(). * * @dataProvider providerUcwords - * @covers ::ucwords */ public function testUcwords($text, $expected, $multibyte = FALSE) { $status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE; @@ -265,10 +246,9 @@ public function providerUcwords() { } /** - * Tests multibyte strlen. + * Tests Unicode::strlen(). * * @dataProvider providerStrlen - * @covers ::strlen */ public function testStrlen($text, $expected) { // Run through multibyte code path. @@ -295,10 +275,9 @@ public function providerStrlen() { } /** - * Tests multibyte substr. + * Tests Unicode::substr(). * * @dataProvider providerSubstr - * @covers ::substr */ public function testSubstr($text, $start, $length, $expected) { // Run through multibyte code path. @@ -323,7 +302,6 @@ public function testSubstr($text, $start, $length, $expected) { */ public function providerSubstr() { return array( - array('frànçAIS is über-åwesome', 0, NULL, 'frànçAIS is über-åwesome'), array('frànçAIS is über-åwesome', 0, 0, ''), array('frànçAIS is über-åwesome', 0, 1, 'f'), array('frànçAIS is über-åwesome', 0, 8, 'frànçAIS'), @@ -352,12 +330,12 @@ public function providerSubstr() { } /** - * Tests multibyte truncate. + * Tests Unicode::truncate(). * * @dataProvider providerTruncate - * @covers ::truncate */ public function testTruncate($text, $max_length, $expected, $wordsafe = FALSE, $add_ellipsis = FALSE) { + Unicode::check(); $this->assertEquals($expected, Unicode::truncate($text, $max_length, $wordsafe, $add_ellipsis)); } @@ -424,10 +402,7 @@ public function providerTruncate() { } /** - * Tests multibyte truncate bytes. - * - * @dataProvider providerTestTruncateBytes - * @covers ::truncateBytes + * Tests Unicode::truncateBytes(). * * @param string $text * The string to truncate. @@ -435,6 +410,8 @@ public function providerTruncate() { * The upper limit on the returned string length. * @param string $expected * The expected return from Unicode::truncateBytes(). + * + * @dataProvider providerTestTruncateBytes */ public function testTruncateBytes($text, $max_length, $expected) { $this->assertEquals($expected, Unicode::truncateBytes($text, $max_length), 'The string was not correctly truncated.'); @@ -459,10 +436,7 @@ public function providerTestTruncateBytes() { } /** - * Tests UTF-8 validation. - * - * @dataProvider providerTestValidateUtf8 - * @covers ::validateUtf8 + * Tests Unicode::validateUtf8(). * * @param string $text * The text to validate. @@ -470,6 +444,8 @@ public function providerTestTruncateBytes() { * The expected return value from Unicode::validateUtf8(). * @param string $message * The message to display on failure. + * + * @dataProvider providerTestValidateUtf8 */ public function testValidateUtf8($text, $expected, $message) { $this->assertEquals($expected, Unicode::validateUtf8($text), $message); @@ -498,10 +474,7 @@ public function providerTestValidateUtf8() { } /** - * Tests UTF-8 conversion. - * - * @dataProvider providerTestConvertToUtf8 - * @covers ::convertToUtf8 + * Tests Unicode::convertToUtf8(). * * @param string $data * The data to be converted. @@ -509,6 +482,8 @@ public function providerTestValidateUtf8() { * The encoding the data is in. * @param string|bool $expected * The expected result. + * + * @dataProvider providerTestConvertToUtf8 */ public function testConvertToUtf8($data, $encoding, $expected) { $this->assertEquals($expected, Unicode::convertToUtf8($data, $encoding)); diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php index 0477b7a..12cbad5 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -7,14 +7,14 @@ namespace Drupal\Tests\Component\Utility; + use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\String; use Drupal\Tests\UnitTestCase; /** - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\UrlHelper + * @group Utility */ class UrlHelperTest extends UnitTestCase { @@ -34,10 +34,7 @@ public function providerTestBuildQuery() { } /** - * Tests query building. - * - * @dataProvider providerTestBuildQuery - * @covers ::buildQuery + * Tests UrlHelper::buildQuery(). * * @param array $query * The array of query parameters. @@ -45,6 +42,8 @@ public function providerTestBuildQuery() { * The expected query string. * @param string $message * The assertion message. + * + * @dataProvider providerTestBuildQuery */ public function testBuildQuery($query, $expected, $message) { $this->assertEquals(UrlHelper::buildQuery($query), $expected, $message); @@ -83,13 +82,12 @@ public function providerTestValidAbsoluteData() { /** * Tests valid absolute URLs. * - * @dataProvider providerTestValidAbsoluteData - * @covers ::isValid - * * @param string $url * The url to test. * @param string $scheme * The scheme to test. + * + * @dataProvider providerTestValidAbsoluteData */ public function testValidAbsolute($url, $scheme) { $test_url = $scheme . '://' . $url; @@ -114,13 +112,12 @@ public function providerTestInvalidAbsolute() { /** * Tests invalid absolute URLs. * - * @dataProvider providerTestInvalidAbsolute - * @covers ::isValid - * * @param string $url * The url to test. * @param string $scheme * The scheme to test. + * + * @dataProvider providerTestInvalidAbsolute */ public function testInvalidAbsolute($url, $scheme) { $test_url = $scheme . '://' . $url; @@ -148,13 +145,12 @@ public function providerTestValidRelativeData() { /** * Tests valid relative URLs. * - * @dataProvider providerTestValidRelativeData - * @covers ::isValid - * * @param string $url * The url to test. * @param string $prefix * The prefix to test. + * + * @dataProvider providerTestValidRelativeData */ public function testValidRelative($url, $prefix) { $test_url = $prefix . $url; @@ -179,13 +175,12 @@ public function providerTestInvalidRelativeData() { /** * Tests invalid relative URLs. * - * @dataProvider providerTestInvalidRelativeData - * @covers ::isValid - * * @param string $url * The url to test. * @param string $prefix * The prefix to test. + * + * @dataProvider providerTestInvalidRelativeData */ public function testInvalidRelative($url, $prefix) { $test_url = $prefix . $url; @@ -196,9 +191,6 @@ public function testInvalidRelative($url, $prefix) { /** * Tests query filtering. * - * @dataProvider providerTestFilterQueryParameters - * @covers ::filterQueryParameters - * * @param array $query * The array of query parameters. * @param array $exclude @@ -206,6 +198,10 @@ public function testInvalidRelative($url, $prefix) { * nested items. * @param array $expected * An array containing query parameters. + * + * @dataProvider providerTestFilterQueryParameters + * + * @see \Drupal\Component\Utility\Url::filterQueryParameters(). */ public function testFilterQueryParameters($query, $exclude, $expected) { $filtered = UrlHelper::filterQueryParameters($query, $exclude); @@ -237,13 +233,14 @@ public static function providerTestFilterQueryParameters() { /** * Tests url parsing. * - * @dataProvider providerTestParse - * @covers ::parse - * * @param string $url * URL to test. * @param array $expected * Associative array with expected parameters. + * + * @dataProvider providerTestParse + * + * @see \Drupal\Component\Utility\Url::parse() */ public function testParse($url, $expected) { $parsed = UrlHelper::parse($url); @@ -307,13 +304,14 @@ public static function providerTestParse() { /** * Tests path encoding. * - * @dataProvider providerTestEncodePath - * @covers ::encodePath - * * @param string $path * A path to encode. * @param string $expected * The expected encoded path. + * + * @see \Drupal\Component\Utility\Url::encodePath(). + * + * @dataProvider providerTestEncodePath */ public function testEncodePath($path, $expected) { $encoded = UrlHelper::encodePath($path); @@ -335,13 +333,14 @@ public static function providerTestEncodePath() { /** * Tests external versus internal paths. * - * @dataProvider providerTestIsExternal - * @covers ::isExternal - * * @param string $path * URL or path to test. * @param bool $expected * Expected result. + * + * @see \Drupal\Component\Utility\Url::isExternal() + * + * @dataProvider providerTestIsExternal */ public function testIsExternal($path, $expected) { $isExternal = UrlHelper::isExternal($path); @@ -364,16 +363,14 @@ public static function providerTestIsExternal() { /** * Tests bad protocol filtering and escaping. * - * @dataProvider providerTestFilterBadProtocol - * @covers ::setAllowedProtocols - * @covers ::filterBadProtocol - * * @param string $uri * Protocol URI. * @param string $expected * Expected escaped value. * @param array $protocols * Protocols to allow. + * + * @dataProvider providerTestFilterBadProtocol */ public function testFilterBadProtocol($uri, $expected, $protocols) { UrlHelper::setAllowedProtocols($protocols); @@ -401,16 +398,16 @@ public static function providerTestFilterBadProtocol() { /** * Tests dangerous url protocol filtering. * - * @dataProvider providerTestStripDangerousProtocols - * @covers ::setAllowedProtocols - * @covers ::stripDangerousProtocols - * * @param string $uri * Protocol URI. * @param string $expected * Expected escaped value. * @param array $protocols * Protocols to allow. + * + * @see \Drupal\Component\Utility\Url::stripDangerousProtocols() + * + * @dataProvider providerTestStripDangerousProtocols */ public function testStripDangerousProtocols($uri, $expected, $protocols) { UrlHelper::setAllowedProtocols($protocols); diff --git a/core/tests/Drupal/Tests/Component/Utility/XssTest.php b/core/tests/Drupal/Tests/Component/Utility/XssTest.php index a14827f..3a090b8 100644 --- a/core/tests/Drupal/Tests/Component/Utility/XssTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/XssTest.php @@ -13,11 +13,8 @@ use Drupal\Tests\UnitTestCase; /** - * XSS Filtering tests. - * - * @group Utility - * * @coversDefaultClass \Drupal\Component\Utility\Xss + * @group Utility * * Script injection vectors mostly adopted from http://ha.ckers.org/xss.html. * diff --git a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php index a346cbb..76bb6bc 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php @@ -24,7 +24,11 @@ class EntityRouteEnhancerTest extends UnitTestCase { * @see \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer::enhancer() */ public function testEnhancer() { - $route_enhancer = new EntityRouteEnhancer(); + $controller_resolver = $this->getMock('Drupal\Core\Controller\ControllerResolverInterface'); + $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); + $form_builder = $this->getMock('Drupal\Core\Form\FormBuilderInterface'); + + $route_enhancer = new EntityRouteEnhancer($controller_resolver, $entity_manager, $form_builder); // Set a controller to ensure it is not overridden. $request = new Request(); @@ -39,7 +43,9 @@ public function testEnhancer() { $defaults = array(); $defaults['_entity_form'] = 'entity_test.default'; $new_defaults = $route_enhancer->enhance($defaults, $request); - $this->assertEquals('controller.entity_form:getContentResult', $new_defaults['_controller']); + $this->assertTrue(is_callable($new_defaults['_controller'])); + $this->assertInstanceOf('\Drupal\Core\Entity\HtmlEntityFormController', $new_defaults['_controller'][0]); + $this->assertEquals($new_defaults['_controller'][1], 'getContentResult'); // Set _entity_list and ensure that the entity list controller is set. $defaults = array();