Chris@0: drupalCreateUser(['administer modules', 'administer software updates', 'administer site configuration']); Chris@0: $this->drupalLogin($admin_user); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests upload, extraction, and update of a module. Chris@0: */ Chris@0: public function testUploadModule() { Chris@0: // Ensure that the update information is correct before testing. Chris@0: update_get_available(TRUE); Chris@0: Chris@0: // Images are not valid archives, so get one and try to install it. We Chris@0: // need an extra variable to store the result of drupalGetTestFiles() Chris@0: // since reset() takes an argument by reference and passing in a constant Chris@0: // emits a notice in strict mode. Chris@0: $imageTestFiles = $this->drupalGetTestFiles('image'); Chris@0: $invalidArchiveFile = reset($imageTestFiles); Chris@0: $edit = [ Chris@0: 'files[project_upload]' => $invalidArchiveFile->uri, Chris@0: ]; Chris@0: // This also checks that the correct archive extensions are allowed. Chris@0: $this->drupalPostForm('admin/modules/install', $edit, t('Install')); Chris@0: $this->assertText(t('Only files with the following extensions are allowed: @archive_extensions.', ['@archive_extensions' => archiver_get_extensions()]), 'Only valid archives can be uploaded.'); Chris@0: $this->assertUrl('admin/modules/install'); Chris@0: Chris@0: // Check to ensure an existing module can't be reinstalled. Also checks that Chris@0: // the archive was extracted since we can't know if the module is already Chris@0: // installed until after extraction. Chris@0: $validArchiveFile = __DIR__ . '/../../aaa_update_test.tar.gz'; Chris@0: $edit = [ Chris@0: 'files[project_upload]' => $validArchiveFile, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/modules/install', $edit, t('Install')); Chris@0: $this->assertText(t('@module_name is already installed.', ['@module_name' => 'AAA Update test']), 'Existing module was extracted and not reinstalled.'); Chris@0: $this->assertUrl('admin/modules/install'); Chris@0: Chris@0: // Ensure that a new module can be extracted and installed. Chris@0: $updaters = drupal_get_updaters(); Chris@0: $moduleUpdater = $updaters['module']['class']; Chris@0: $installedInfoFilePath = $this->container->get('update.root') . '/' . $moduleUpdater::getRootDirectoryRelativePath() . '/update_test_new_module/update_test_new_module.info.yml'; Chris@0: $this->assertFalse(file_exists($installedInfoFilePath), 'The new module does not exist in the filesystem before it is installed with the Update Manager.'); Chris@0: $validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz'; Chris@0: $edit = [ Chris@0: 'files[project_upload]' => $validArchiveFile, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/modules/install', $edit, t('Install')); Chris@0: // Check that submitting the form takes the user to authorize.php. Chris@0: $this->assertUrl('core/authorize.php'); Chris@0: $this->assertTitle('Update manager | Drupal'); Chris@0: // Check for a success message on the page, and check that the installed Chris@0: // module now exists in the expected place in the filesystem. Chris@0: $this->assertRaw(t('Installed %project_name successfully', ['%project_name' => 'update_test_new_module'])); Chris@0: $this->assertTrue(file_exists($installedInfoFilePath), 'The new module exists in the filesystem after it is installed with the Update Manager.'); Chris@0: // Ensure the links are relative to the site root and not Chris@0: // core/authorize.php. Chris@0: $this->assertLink(t('Install another module')); Chris@0: $this->assertLinkByHref(Url::fromRoute('update.module_install')->toString()); Chris@0: $this->assertLink(t('Enable newly added modules')); Chris@0: $this->assertLinkByHref(Url::fromRoute('system.modules_list')->toString()); Chris@0: $this->assertLink(t('Administration pages')); Chris@0: $this->assertLinkByHref(Url::fromRoute('system.admin')->toString()); Chris@0: // Ensure we can reach the "Install another module" link. Chris@0: $this->clickLink(t('Install another module')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertUrl('admin/modules/install'); Chris@0: Chris@0: // Check that the module has the correct version before trying to update Chris@0: // it. Since the module is installed in sites/simpletest, which only the Chris@0: // child site has access to, standard module API functions won't find it Chris@0: // when called here. To get the version, the info file must be parsed Chris@0: // directly instead. Chris@0: $info_parser = new InfoParserDynamic(); Chris@0: $info = $info_parser->parse($installedInfoFilePath); Chris@0: $this->assertEqual($info['version'], '8.x-1.0'); Chris@0: Chris@0: // Enable the module. Chris@0: $this->drupalPostForm('admin/modules', ['modules[update_test_new_module][enable]' => TRUE], t('Install')); Chris@0: Chris@0: // Define the update XML such that the new module downloaded above needs an Chris@0: // update from 8.x-1.0 to 8.x-1.1. Chris@0: $update_test_config = $this->config('update_test.settings'); Chris@0: $system_info = [ Chris@0: 'update_test_new_module' => [ Chris@0: 'project' => 'update_test_new_module', Chris@0: ], Chris@0: ]; Chris@0: $update_test_config->set('system_info', $system_info)->save(); Chris@0: $xml_mapping = [ Chris@0: 'update_test_new_module' => '1_1', Chris@0: ]; Chris@0: $this->refreshUpdateStatus($xml_mapping); Chris@0: Chris@0: // Run the updates for the new module. Chris@0: $this->drupalPostForm('admin/reports/updates/update', ['projects[update_test_new_module]' => TRUE], t('Download these updates')); Chris@0: $this->drupalPostForm(NULL, ['maintenance_mode' => FALSE], t('Continue')); Chris@0: $this->assertText(t('Update was completed successfully.')); Chris@0: $this->assertRaw(t('Installed %project_name successfully', ['%project_name' => 'update_test_new_module'])); Chris@0: Chris@0: // Parse the info file again to check that the module has been updated to Chris@0: // 8.x-1.1. Chris@0: $info = $info_parser->parse($installedInfoFilePath); Chris@0: $this->assertEqual($info['version'], '8.x-1.1'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Ensures that archiver extensions are properly merged in the UI. Chris@0: */ Chris@0: public function testFileNameExtensionMerging() { Chris@0: $this->drupalGet('admin/modules/install'); Chris@0: // Make sure the bogus extension supported by update_test.module is there. Chris@0: $this->assertPattern('/file extensions are supported:.*update-test-extension/', "Found 'update-test-extension' extension."); Chris@0: // Make sure it didn't clobber the first option from core. Chris@0: $this->assertPattern('/file extensions are supported:.*tar/', "Found 'tar' extension."); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks the messages on update manager pages when missing a security update. Chris@0: */ Chris@0: public function testUpdateManagerCoreSecurityUpdateMessages() { Chris@0: $setting = [ Chris@0: '#all' => [ Chris@0: 'version' => '8.0.0', Chris@0: ], Chris@0: ]; Chris@0: $this->config('update_test.settings') Chris@0: ->set('system_info', $setting) Chris@0: ->set('xml_map', ['drupal' => '0.2-sec']) Chris@0: ->save(); Chris@0: $this->config('update.settings') Chris@0: ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString()) Chris@0: ->save(); Chris@0: // Initialize the update status. Chris@0: $this->drupalGet('admin/reports/updates'); Chris@0: Chris@0: // Now, make sure none of the Update manager pages have duplicate messages Chris@0: // about core missing a security update. Chris@0: Chris@0: $this->drupalGet('admin/modules/install'); Chris@0: $this->assertNoText(t('There is a security update available for your version of Drupal.')); Chris@0: Chris@0: $this->drupalGet('admin/modules/update'); Chris@0: $this->assertNoText(t('There is a security update available for your version of Drupal.')); Chris@0: Chris@0: $this->drupalGet('admin/appearance/install'); Chris@0: $this->assertNoText(t('There is a security update available for your version of Drupal.')); Chris@0: Chris@0: $this->drupalGet('admin/appearance/update'); Chris@0: $this->assertNoText(t('There is a security update available for your version of Drupal.')); Chris@0: Chris@0: $this->drupalGet('admin/reports/updates/install'); Chris@0: $this->assertNoText(t('There is a security update available for your version of Drupal.')); Chris@0: Chris@0: $this->drupalGet('admin/reports/updates/update'); Chris@0: $this->assertNoText(t('There is a security update available for your version of Drupal.')); Chris@0: Chris@0: $this->drupalGet('admin/update/ready'); Chris@0: $this->assertNoText(t('There is a security update available for your version of Drupal.')); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests only an *.info.yml file are detected without supporting files. Chris@0: */ Chris@0: public function testUpdateDirectory() { Chris@17: $type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/modules/aaa_update_test'); Chris@0: $this->assertEqual($type, 'Drupal\\Core\\Updater\\Module', 'Detected a Module'); Chris@0: Chris@17: $type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/themes/update_test_basetheme'); Chris@0: $this->assertEqual($type, 'Drupal\\Core\\Updater\\Theme', 'Detected a Theme.'); Chris@0: } Chris@0: Chris@0: }