diff --git a/core/modules/media_library/tests/src/Functional/InstallUninstallTest.php b/core/modules/media_library/tests/src/Functional/InstallUninstallTest.php new file mode 100644 index 0000000000..5dcb9d9dcf --- /dev/null +++ b/core/modules/media_library/tests/src/Functional/InstallUninstallTest.php @@ -0,0 +1,105 @@ +drupalPlaceBlock('local_tasks_block'); + } + + /** + * Tests that a custom path to the media view's page display is not modified. + */ + public function testCustomizedAdministationPagePath() { + $assert_session = $this->assertSession(); + + // If the media view's page display's path has been changed before Media + // Library is installed, it should not be changed by hook_install(). + $view = View::load('media'); + + $display = &$view->getDisplay('media_page_list'); + $display['display_options']['path'] = '/admin/content/all-media'; + $view->save(); + + $this->container->get('module_installer')->install(['media_library']); + + $account = $this->drupalCreateUser(['access media overview']); + $this->drupalLogin($account); + + $this->drupalGet('/admin/content/media'); + $assert_session->statusCodeEquals(200); + $this->drupalGet('/admin/content/media-table'); + $assert_session->statusCodeEquals(404); + $this->drupalGet('/admin/content/all-media'); + $assert_session->statusCodeEquals(200); + $this->drupalGet('/admin/content/all-media-table'); + $assert_session->statusCodeEquals(404); + + $this->container->get('module_installer')->uninstall(['media_library']); + + // This will be a 403 because uninstalling media_library removed the + // /admin/content/media path -- the 'media' view lives at + // /admin/content/all-media, remember -- and therefore, /admin/content/media + // is going to go to the Media entity's list builder, which requires the + // 'administer media' permission...which the current user doesn't have. + $this->drupalGet('/admin/content/media'); + $assert_session->statusCodeEquals(403); + $this->drupalGet('/admin/content/media-table'); + $assert_session->statusCodeEquals(404); + $this->drupalGet('/admin/content/all-media'); + $assert_session->statusCodeEquals(200); + $this->drupalGet('/admin/content/all-media-table'); + $assert_session->statusCodeEquals(404); + } + + /** + * Tests that a custom link to the media view's page display is not modified. + */ + public function testCustomizedMenuSettings() { + $assert_session = $this->assertSession(); + + // If the media view's page display's menu settings have been changed before + // Media Library is installed, they should not be changed by hook_install(). + $view = View::load('media'); + + $display = &$view->getDisplay('media_page_list'); + $display['display_options']['menu']['title'] = 'A treasure trove of interesting pictures!'; + $display['display_options']['menu']['type'] = 'normal'; + $display['display_options']['menu']['parent'] = 'system.admin_structure'; + $view->save(); + + $this->container->get('module_installer')->install(['media_library']); + + $account = $this->drupalCreateUser([ + 'access administration pages', + 'access media overview', + ]); + $this->drupalLogin($account); + + $this->drupalGet('/admin/structure'); + $assert_session->linkExists('A treasure trove of interesting pictures!'); + + $this->container->get('module_installer')->uninstall(['media_library']); + $this->getSession()->reload(); + $assert_session->linkExists('A treasure trove of interesting pictures!'); + } + +}