reverted: --- b/core/modules/editor/tests/src/Kernel/QuickEditIntegrationTest.php +++ a/core/modules/editor/tests/src/Kernel/QuickEditIntegrationTest.php @@ -9,7 +9,7 @@ use Drupal\entity_test\Entity\EntityTest; use Drupal\quickedit\MetadataGenerator; use Drupal\Tests\quickedit\Kernel\QuickEditTestBase; +use Drupal\quickedit_test\MockEditEntityFieldAccessCheck; -use Drupal\quickedit_test\MockQuickEditEntityFieldAccessCheck; use Drupal\editor\EditorController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -52,7 +52,7 @@ /** * The access checker object to be used by the metadata generator object. * + * @var \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface - * @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface */ protected $accessChecker; @@ -165,7 +165,7 @@ */ public function testMetadata() { $this->editorManager = $this->container->get('plugin.manager.quickedit.editor'); + $this->accessChecker = new MockEditEntityFieldAccessCheck(); - $this->accessChecker = new MockQuickEditEntityFieldAccessCheck(); $this->editorSelector = $this->container->get('quickedit.editor.selector'); $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager); reverted: --- b/core/modules/quickedit/quickedit.services.yml +++ a/core/modules/quickedit/quickedit.services.yml @@ -3,7 +3,7 @@ class: Drupal\quickedit\Plugin\InPlaceEditorManager parent: default_plugin_manager access_check.quickedit.entity_field: + class: Drupal\quickedit\Access\EditEntityFieldAccessCheck - class: Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck tags: - { name: access_check, applies_to: _access_quickedit_entity_field } quickedit.editor.selector: reverted: --- b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheck.php +++ a/core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php @@ -8,9 +8,9 @@ use Drupal\Core\Entity\EntityInterface; /** + * Access check for editing entity fields. - * Access check for in-place editing entity fields. */ +class EditEntityFieldAccessCheck implements AccessInterface, EditEntityFieldAccessCheckInterface { -class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntityFieldAccessCheckInterface { /** * Checks Quick Edit access to the field. reverted: --- b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheckInterface.php +++ a/core/modules/quickedit/src/Access/EditEntityFieldAccessCheckInterface.php @@ -5,9 +5,9 @@ use Drupal\Core\Entity\EntityInterface; /** + * Access check for editing entity fields. - * Access check for in-place editing entity fields. */ +interface EditEntityFieldAccessCheckInterface { -interface QuickEditEntityFieldAccessCheckInterface { /** * Checks access to edit the requested field of the requested entity. reverted: --- b/core/modules/quickedit/src/MetadataGenerator.php +++ a/core/modules/quickedit/src/MetadataGenerator.php @@ -5,7 +5,7 @@ use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface; -use Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface; use Drupal\Core\Entity\Entity\EntityViewDisplay; /** @@ -16,7 +16,7 @@ /** * An object that checks if a user has access to edit a given entity field. * + * @var \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface - * @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface */ protected $accessChecker; @@ -37,14 +37,14 @@ /** * Constructs a new MetadataGenerator. * + * @param \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface $access_checker - * @param \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface $access_checker * An object that checks if a user has access to edit a given field. * @param \Drupal\quickedit\EditorSelectorInterface $editor_selector * An object that determines which editor to attach to a given field. * @param \Drupal\Component\Plugin\PluginManagerInterface $editor_manager * The manager for editor plugins. */ + public function __construct(EditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) { - public function __construct(QuickEditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) { $this->accessChecker = $access_checker; $this->editorSelector = $editor_selector; $this->editorManager = $editor_manager; reverted: --- b/core/modules/quickedit/tests/modules/src/MockQuickEditEntityFieldAccessCheck.php +++ a/core/modules/quickedit/tests/modules/src/MockEditEntityFieldAccessCheck.php @@ -3,12 +3,12 @@ namespace Drupal\quickedit_test; use Drupal\Core\Entity\EntityInterface; +use Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface; -use Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface; /** * Access check for editing entity fields. */ +class MockEditEntityFieldAccessCheck implements EditEntityFieldAccessCheckInterface { -class MockQuickEditEntityFieldAccessCheck implements QuickEditEntityFieldAccessCheckInterface { /** * {@inheritdoc} reverted: --- b/core/modules/quickedit/tests/src/Kernel/MetadataGeneratorTest.php +++ a/core/modules/quickedit/tests/src/Kernel/MetadataGeneratorTest.php @@ -5,7 +5,7 @@ use Drupal\entity_test\Entity\EntityTest; use Drupal\quickedit\EditorSelector; use Drupal\quickedit\MetadataGenerator; +use Drupal\quickedit_test\MockEditEntityFieldAccessCheck; -use Drupal\quickedit_test\MockQuickEditEntityFieldAccessCheck; use Drupal\filter\Entity\FilterFormat; /** @@ -44,7 +44,7 @@ /** * The access checker object to be used by the metadata generator object. * + * @var \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface - * @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface */ protected $accessChecker; @@ -52,7 +52,7 @@ parent::setUp(); $this->editorManager = $this->container->get('plugin.manager.quickedit.editor'); + $this->accessChecker = new MockEditEntityFieldAccessCheck(); - $this->accessChecker = new MockQuickEditEntityFieldAccessCheck(); $this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter')); $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager); } diff -u b/core/modules/quickedit/tests/src/Unit/Access/QuickEditEntityFieldAccessCheckTest.php b/core/modules/quickedit/tests/src/Unit/Access/EditEntityFieldAccessCheckTest.php --- b/core/modules/quickedit/tests/src/Unit/Access/QuickEditEntityFieldAccessCheckTest.php +++ b/core/modules/quickedit/tests/src/Unit/Access/EditEntityFieldAccessCheckTest.php @@ -1,149 +1,8 @@ -editAccessCheck = new QuickEditEntityFieldAccessCheck(); - - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); - $cache_contexts_manager->reveal(); - $container = new Container(); - $container->set('cache_contexts_manager', $cache_contexts_manager); - \Drupal::setContainer($container); - } - - /** - * Provides test data for testAccess(). - * - * @see \Drupal\Tests\edit\Unit\quickedit\Access\QuickEditEntityFieldAccessCheckTest::testAccess() - */ - public function providerTestAccess() { - $data = array(); - $data[] = array(TRUE, TRUE, AccessResult::allowed()); - $data[] = array(FALSE, TRUE, AccessResult::neutral()); - $data[] = array(TRUE, FALSE, AccessResult::neutral()); - $data[] = array(FALSE, FALSE, AccessResult::neutral()); - - return $data; - } - - /** - * Tests the method for checking access to routes. - * - * @param bool $entity_is_editable - * Whether the subject entity is editable. - * @param bool $field_storage_is_accessible - * Whether the user has access to the field storage entity. - * @param \Drupal\Core\Access\AccessResult $expected_result - * The expected result of the access call. - * - * @dataProvider providerTestAccess - */ - public function testAccess($entity_is_editable, $field_storage_is_accessible, AccessResult $expected_result) { - $entity = $this->createMockEntity(); - $entity->expects($this->any()) - ->method('access') - ->willReturn(AccessResult::allowedIf($entity_is_editable)->cachePerPermissions()); - - $field_storage = $this->getMock('Drupal\field\FieldStorageConfigInterface'); - $field_storage->expects($this->any()) - ->method('access') - ->willReturn(AccessResult::allowedIf($field_storage_is_accessible)); - - $expected_result->cachePerPermissions(); - - $field_name = 'valid'; - $entity_with_field = clone $entity; - $entity_with_field->expects($this->any()) - ->method('get') - ->with($field_name) - ->will($this->returnValue($field_storage)); - $entity_with_field->expects($this->once()) - ->method('hasTranslation') - ->with(LanguageInterface::LANGCODE_NOT_SPECIFIED) - ->will($this->returnValue(TRUE)); - - $account = $this->getMock('Drupal\Core\Session\AccountInterface'); - $access = $this->editAccessCheck->access($entity_with_field, $field_name, LanguageInterface::LANGCODE_NOT_SPECIFIED, $account); - $this->assertEquals($expected_result, $access); - } - - /** - * Tests checking access to routes that result in AccessResult::isForbidden(). - * - * @dataProvider providerTestAccessForbidden - */ - public function testAccessForbidden($field_name, $langcode) { - $account = $this->getMock('Drupal\Core\Session\AccountInterface'); - $entity = $this->createMockEntity(); - $this->assertEquals(AccessResult::forbidden(), $this->editAccessCheck->access($entity, $field_name, $langcode, $account)); - } - - /** - * Provides test data for testAccessForbidden. - */ - public function providerTestAccessForbidden() { - $data = array(); - // Tests the access method without a field_name. - $data[] = array(NULL, LanguageInterface::LANGCODE_NOT_SPECIFIED); - // Tests the access method with a non-existent field. - $data[] = array('not_valid', LanguageInterface::LANGCODE_NOT_SPECIFIED); - // Tests the access method without a langcode. - $data[] = array('valid', NULL); - // Tests the access method with an invalid langcode. - $data[] = array('valid', 'xx-lolspeak'); - return $data; - } - - /** - * Returns a mock entity. - * - * @return \Drupal\Core\Entity\EntityInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected function createMockEntity() { - $entity = $this->getMockBuilder('Drupal\entity_test\Entity\EntityTest') - ->disableOriginalConstructor() - ->getMock(); - - $entity->expects($this->any()) - ->method('hasTranslation') - ->will($this->returnValueMap(array( - array(LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE), - array('xx-lolspeak', FALSE), - ))); - $entity->expects($this->any()) - ->method('hasField') - ->will($this->returnValueMap(array( - array('valid', TRUE), - array('not_valid', FALSE), - ))); - - return $entity; - } - +class EditEntityFieldAccessCheckTest extends QuickEditEntityFieldAccessCheck { } +