diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index 1281862..8d87de1 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -268,14 +268,17 @@ public function buildForm(array $form, array &$form_state) { * {@inheritdoc} */ public function getOperations(EntityInterface $entity) { + $uri = $entity->uri(); $operations = array(); $operations['configure'] = array( 'title' => t('configure'), - 'href' => 'admin/structure/block/manage/' . $entity->id() . '/configure', + 'href' => $uri['path'] . '/configure', + 'options' => $uri['options'], ); $operations['delete'] = array( 'title' => t('delete'), - 'href' => 'admin/structure/block/manage/' . $entity->id() . '/delete', + 'href' => $uri['path'] . '/delete', + 'options' => $uri['options'], ); return $operations; } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php deleted file mode 100644 index 395e620..0000000 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php +++ /dev/null @@ -1,62 +0,0 @@ - 'Block hook operations', - 'description' => 'Implement hook entity operations alter.', - 'group' => 'Block', - ); - } - - public function setUp() { - parent::setUp(); - - $permissions = array( - 'administer blocks', - ); - - // Create and log in user. - $admin_user = $this->drupalCreateUser($permissions); - $this->drupalLogin($admin_user); - } - - /* - * Tests block lists to see if translate link is added to operations. - */ - public function testTranslateOperationInBlockListUI() { - // Add a test block, any block will do. - // Set the machine name so later the translate link can be built. - $block_machine_name = Unicode::strtolower($this->randomName(16)); - $this->drupalPlaceBlock('system_powered_by_block', array('machine_name' => $block_machine_name)); - - // Get the Block listing. - $this->drupalGet('admin/structure/block'); - - $translate_link = 'admin/structure/block/manage/stark.' . $block_machine_name . '/translate'; - // Test if the link to translate the block is on the page. - $this->assertLinkByHref($translate_link); - } - -} diff --git a/core/modules/block/tests/block_test_hook_operation/block_test_hook_operation.info.yml b/core/modules/block/tests/block_test_hook_operation/block_test_hook_operation.info.yml deleted file mode 100644 index 5bf37bd..0000000 --- a/core/modules/block/tests/block_test_hook_operation/block_test_hook_operation.info.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: 'Block test hook operation' -type: module -description: 'Implements a hook to test entity_hook_operations_alter() in blocks.' -package: Core -version: VERSION -hidden: TRUE -core: 8.x -dependencies: - - block diff --git a/core/modules/block/tests/block_test_hook_operation/block_test_hook_operation.module b/core/modules/block/tests/block_test_hook_operation/block_test_hook_operation.module deleted file mode 100644 index 0c570b4..0000000 --- a/core/modules/block/tests/block_test_hook_operation/block_test_hook_operation.module +++ /dev/null @@ -1,19 +0,0 @@ -uri(); - $operations['translate'] = array( - 'title' => t('Translate'), - 'href' => $uri['path'] . '/translate', - 'options' => $uri['options'], - 'weight' => 50, - ); -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityOperationsTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityOperationsTest.php index 776021d..d1929a4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityOperationsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityOperationsTest.php @@ -7,19 +7,35 @@ namespace Drupal\system\Tests\Entity; -use Drupal\simpletest\WebTestBase; +use Drupal\Component\Utility\Unicode; +use Drupal\views_ui\Tests\UITestBase; /** * Tests for entity operations, that they can be altered. */ -class EntityOperationsTest extends WebTestBase { +class EntityOperationsTest extends UITestBase { /** + * Views used by this test. + * + * @var array + */ + public static $testViews = array('test_view'); + /** * Modules to enable. * * @var array */ - public static $modules = array('entity_test'); + public static $modules = array( + 'block', + 'contact', + 'custom_block', + 'entity_test', + 'menu', + 'shortcut', + 'taxonomy', + 'views_ui', + ); public static function getInfo() { return array( @@ -32,11 +48,23 @@ public static function getInfo() { public function setUp() { parent::setUp(); - // Create and login user. - $this->web_user = $this->drupalCreateUser(array( + $permissions = array( + 'access site-wide contact form', + 'administer blocks', + 'administer contact forms', + 'administer filters', + 'administer menu', 'administer permissions', - )); - $this->drupalLogin($this->web_user); + 'administer shortcuts', + 'administer site configuration', + 'administer taxonomy', + 'administer users', + 'administer views', + ); + + // Create and log in user. + $admin_user = $this->drupalCreateUser($permissions); + $this->drupalLogin($admin_user); } /** @@ -45,14 +73,191 @@ public function setUp() { * @see entity_test_entity_operation_alter() */ public function testEntityOperationAlter() { - // Check that role listing contain our test_operation operation. + + $this->doBlockListTest(); + $this->doCustomBlockTypeListTest(); + $this->doContactFormsListTest(); + $this->doFormatsListTest(); + $this->doMenuListTest(); + $this->doShortcutListTest(); + $this->doUserRoleListTest(); + $this->doVocabularyListTest(); + $this->doViewListUITest(); + + } + + /** + * Tests block lists to see if test_operation link is added to operations. + */ + protected function doBlockListTest() { + // Add a test block, any block will do. + // Set the machine name so the test_operation link can be built later. + $block_machine_name = Unicode::strtolower($this->randomName(16)); + $this->drupalPlaceBlock('system_powered_by_block', array('machine_name' => $block_machine_name)); + + // Get the Block listing. + $this->drupalGet('admin/structure/block'); + + $test_operation_link = 'admin/structure/block/manage/stark.' . $block_machine_name . '/test_operation'; + // Test if the link to test_operation the block is on the page. + $this->assertLinkByHref($test_operation_link); + } + + /** + * Tests custom block lists to see if test_operation link is added to operations. + */ + function doCustomBlockTypeListTest() { + // Create a test custom block type to decouple looking for test_operation + // operations link so this does not test more than necessary. + $custom_block_type = entity_create('custom_block_type', array( + 'id' => Unicode::strtolower($this->randomName(16)), + 'label' => $this->randomName(), + 'revision' => FALSE + )); + $custom_block_type->save(); + + // Get the custom block listing. + $this->drupalGet('admin/structure/custom-blocks'); + + $test_operation_link = 'admin/structure/custom-blocks/manage/' . $custom_block_type->id() . '/test_operation'; + // Test if the link to test_operation the custom block is on the page. + $this->assertLinkByHref($test_operation_link); + } + + /** + * Tests contact forms lists to see if test_operation link is added to operations. + */ + function doContactFormsListTest() { + // Create a test contact form to decouple looking for test_operation operations + // link so this does not test more than necessary. + $contact_form = entity_create('contact_category', array( + 'id' => Unicode::strtolower($this->randomName(16)), + 'label' => $this->randomName(), + )); + $contact_form->save(); + + // Get the contact form listing. + $this->drupalGet('admin/structure/contact'); + + $test_operation_link = 'admin/structure/contact/manage/' . $contact_form->id() . '/test_operation'; + // Test if the link to test_operation the contact form is on the page. + $this->assertLinkByHref($test_operation_link); + } + + /** + * Tests formats lists to see if test_operation link is added to operations. + */ + function doFormatsListTest() { + // Create a test format to decouple looking for test_operation operations + // link so this does not test more than necessary. + $filter_format = entity_create('filter_format', array( + 'format' => Unicode::strtolower($this->randomName(16)), + 'name' => $this->randomName(), + )); + $filter_format->save(); + + // Get the format listing. + $this->drupalGet('admin/config/content/formats'); + + $test_operation_link = 'admin/config/content/formats/manage/' . $filter_format->id() . '/test_operation'; + // Test if the link to test_operation the format is on the page. + $this->assertLinkByHref($test_operation_link); + } + + /** + * Tests menu lists to see if test_operation link is added to operations. + */ + protected function doMenuListTest() { + // Create a test menu to decouple looking for test_operation operations link so + // this does not test more than necessary. + $this->drupalGet('admin/structure/menu/add'); + // Lowercase the machine name. + $menu_name = Unicode::strtolower($this->randomName(16)); + $label = $this->randomName(16); + $edit = array( + 'id' => $menu_name, + 'description' => '', + 'label' => $label, + ); + // Create the menu by posting the form. + $this->drupalPost('admin/structure/menu/add', $edit, t('Save')); + + // Get the Menu listing. + $this->drupalGet('admin/structure/menu'); + + // Custom Menus are automatically prefixed by 'menu-'. + $menu_name = 'menu-' . $menu_name; + $test_operation_link = 'admin/structure/menu/manage/' . $menu_name . '/test_operation'; + // Test if the link to test_operation the menu is on the page. + $this->assertLinkByHref($test_operation_link); + } + + /** + * Tests shortcut lists to see if test_operation link is added to operations. + */ + function doShortcutListTest() { + // Create a test shortcut to decouple looking for test_operation operations + // link so this does not test more than necessary. + $shortcut = entity_create('shortcut', array( + 'id' => Unicode::strtolower($this->randomName(16)), + 'label' => $this->randomString(), + )); + $shortcut->save(); + + // Get the shortcut listing. + $this->drupalGet('admin/config/user-interface/shortcut'); + + $test_operation_link = 'admin/config/user-interface/shortcut/manage/' . $shortcut->id() . '/test_operation'; + // Test if the link to test_operation the shortcut is on the page. + $this->assertLinkByHref($test_operation_link); + } + + /** + * Tests role lists to see if test_operation link is added to operations. + */ + function doUserRoleListTest() { + // Create a test role to decouple looking for test_operation operations + // link so this does not test more than necessary. + $role_id = Unicode::strtolower($this->randomName(16)); + $this->drupalCreateRole(array(), $role_id); + + // Get the role listing. $this->drupalGet('admin/people/roles'); - $roles = user_roles(); - foreach ($roles as $role) { - $uri = $role->uri(); - $this->assertLinkByHref($uri['path'] . '/test_operation'); - $this->assertLink(format_string('Test Operation: @label', array('@label' => $role->label()))); - } + + $test_operation_link = 'admin/people/roles/manage/' . $role_id . '/test_operation'; + // Test if the link to test_operation the role is on the page. + $this->assertLinkByHref($test_operation_link); + } + + /** + * Tests vocabulary lists to see if test_operation link is added to operations. + */ + protected function doVocabularyListTest() { + // Create a test vocabulary to decouple looking for test_operation operations + // link so this does not test more than necessary. + $vocabulary = entity_create('taxonomy_vocabulary', array( + 'name' => $this->randomName(), + 'description' => $this->randomName(), + 'vid' => Unicode::strtolower($this->randomName()), + )); + $vocabulary->save(); + + // Get the Taxonomy listing. + $this->drupalGet('admin/structure/taxonomy'); + + $test_operation_link = 'admin/structure/taxonomy/manage/' . $vocabulary->id() . '/test_operation'; + // Test if the link to test_operation the vocabulary is on the page. + $this->assertLinkByHref($test_operation_link); } + /** + * Tests views_ui list to see if test_operation link is added to operations. + */ + function doViewListUITest() { + // Views UI List 'admin/structure/views'. + $this->drupalGet('admin/structure/views'); + $test_operation_link = 'admin/structure/views/view/test_view/test_operation'; + // Test if the link to test_operation the test_view is on the page. + $this->assertLinkByHref($test_operation_link); + } }