View source
<?php
namespace Drupal\Tests\update\Functional;
use Drupal\Core\Extension\InfoParserDynamic;
use Drupal\Core\Updater\Updater;
use Drupal\Core\Url;
use Drupal\Tests\TestFileCreationTrait;
class UpdateUploadTest extends UpdateTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
public static $modules = [
'update',
'update_test',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer modules',
'administer software updates',
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
}
public function testUploadModule() {
update_get_available(TRUE);
$imageTestFiles = $this
->drupalGetTestFiles('image');
$invalidArchiveFile = reset($imageTestFiles);
$edit = [
'files[project_upload]' => $invalidArchiveFile->uri,
];
$this
->drupalPostForm('admin/modules/install', $edit, t('Install'));
$extensions = \Drupal::service('plugin.manager.archiver')
->getExtensions();
$this
->assertSession()
->pageTextContains(t('Only files with the following extensions are allowed: @archive_extensions.', [
'@archive_extensions' => $extensions,
]));
$this
->assertUrl('admin/modules/install');
$validArchiveFile = __DIR__ . '/../../aaa_update_test.tar.gz';
$edit = [
'files[project_upload]' => $validArchiveFile,
];
$this
->drupalPostForm('admin/modules/install', $edit, t('Install'));
$this
->assertText(t('@module_name is already installed.', [
'@module_name' => 'AAA Update test',
]), 'Existing module was extracted and not reinstalled.');
$this
->assertUrl('admin/modules/install');
$updaters = drupal_get_updaters();
$moduleUpdater = $updaters['module']['class'];
$installedInfoFilePath = $this->container
->get('update.root') . '/' . $moduleUpdater::getRootDirectoryRelativePath() . '/update_test_new_module/update_test_new_module.info.yml';
$this
->assertFileNotExists($installedInfoFilePath);
$validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
$edit = [
'files[project_upload]' => $validArchiveFile,
];
$this
->drupalPostForm('admin/modules/install', $edit, t('Install'));
$this
->assertUrl('core/authorize.php');
$this
->assertTitle('Update manager | Drupal');
$this
->assertRaw(t('Installed %project_name successfully', [
'%project_name' => 'update_test_new_module',
]));
$this
->assertFileExists($installedInfoFilePath);
$this
->assertSession()
->linkExists(t('Install another module'));
$this
->assertLinkByHref(Url::fromRoute('update.module_install')
->toString());
$this
->assertSession()
->linkExists(t('Enable newly added modules'));
$this
->assertLinkByHref(Url::fromRoute('system.modules_list')
->toString());
$this
->assertSession()
->linkExists(t('Administration pages'));
$this
->assertLinkByHref(Url::fromRoute('system.admin')
->toString());
$this
->clickLink(t('Install another module'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertUrl('admin/modules/install');
$info_parser = new InfoParserDynamic(DRUPAL_ROOT);
$info = $info_parser
->parse($installedInfoFilePath);
$this
->assertEqual($info['version'], '8.x-1.0');
$this
->drupalPostForm('admin/modules', [
'modules[update_test_new_module][enable]' => TRUE,
], t('Install'));
$update_test_config = $this
->config('update_test.settings');
$system_info = [
'update_test_new_module' => [
'project' => 'update_test_new_module',
],
];
$update_test_config
->set('system_info', $system_info)
->save();
$xml_mapping = [
'update_test_new_module' => '1_1',
];
$this
->refreshUpdateStatus($xml_mapping);
$this
->drupalPostForm('admin/reports/updates/update', [
'projects[update_test_new_module]' => TRUE,
], t('Download these updates'));
$this
->drupalPostForm(NULL, [
'maintenance_mode' => FALSE,
], t('Continue'));
$this
->assertText(t('Update was completed successfully.'));
$this
->assertRaw(t('Installed %project_name successfully', [
'%project_name' => 'update_test_new_module',
]));
$info = $info_parser
->parse($installedInfoFilePath);
$this
->assertEqual($info['version'], '8.x-1.1');
}
public function testFileNameExtensionMerging() {
$this
->drupalGet('admin/modules/install');
$this
->assertPattern('/file extensions are supported:.*update-test-extension/');
$this
->assertPattern('/file extensions are supported:.*tar/');
}
public function testUpdateManagerCoreSecurityUpdateMessages() {
$setting = [
'#all' => [
'version' => '8.0.0',
],
];
$this
->config('update_test.settings')
->set('system_info', $setting)
->set('xml_map', [
'drupal' => '0.2-sec',
])
->save();
$this
->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')
->setAbsolute()
->toString())
->save();
$this
->drupalGet('admin/reports/updates');
$this
->drupalGet('admin/modules/install');
$this
->assertNoText(t('There is a security update available for your version of Drupal.'));
$this
->drupalGet('admin/modules/update');
$this
->assertNoText(t('There is a security update available for your version of Drupal.'));
$this
->drupalGet('admin/appearance/install');
$this
->assertNoText(t('There is a security update available for your version of Drupal.'));
$this
->drupalGet('admin/appearance/update');
$this
->assertNoText(t('There is a security update available for your version of Drupal.'));
$this
->drupalGet('admin/reports/updates/install');
$this
->assertNoText(t('There is a security update available for your version of Drupal.'));
$this
->drupalGet('admin/reports/updates/update');
$this
->assertNoText(t('There is a security update available for your version of Drupal.'));
$this
->drupalGet('admin/update/ready');
$this
->assertNoText(t('There is a security update available for your version of Drupal.'));
}
public function testUpdateDirectory() {
$type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/modules/aaa_update_test');
$this
->assertEqual($type, 'Drupal\\Core\\Updater\\Module', 'Detected a Module');
$type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/themes/update_test_basetheme');
$this
->assertEqual($type, 'Drupal\\Core\\Updater\\Theme', 'Detected a Theme.');
}
}