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;
}
protected static $modules = [
'update',
'update_test',
'file',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
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
->drupalGet('admin/modules/install');
$this
->submitForm($edit, 'Continue');
$extensions = \Drupal::service('plugin.manager.archiver')
->getExtensions();
$this
->assertSession()
->pageTextContains("Only files with the following extensions are allowed: {$extensions}.");
$this
->assertSession()
->addressEquals('admin/modules/install');
$validArchiveFile = __DIR__ . '/../../aaa_update_test.tar.gz';
$edit = [
'files[project_upload]' => $validArchiveFile,
];
$this
->drupalGet('admin/modules/install');
$this
->submitForm($edit, 'Continue');
$this
->assertSession()
->pageTextContains('AAA Update test is already present.');
$this
->assertSession()
->addressEquals('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
->assertFileDoesNotExist($installedInfoFilePath);
$validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
$edit = [
'files[project_upload]' => $validArchiveFile,
];
$this
->drupalGet('admin/modules/install');
$this
->submitForm($edit, 'Continue');
$this
->assertSession()
->addressEquals('core/authorize.php');
$this
->assertSession()
->titleEquals('Update manager | Drupal');
$this
->assertSession()
->pageTextContains("Added / updated update_test_new_module successfully");
$this
->assertFileExists($installedInfoFilePath);
$this
->assertSession()
->linkExists('Add another module');
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('update.module_install')
->toString());
$this
->assertSession()
->linkExists('Enable newly added modules');
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('system.modules_list')
->toString());
$this
->assertSession()
->linkExists('Administration pages');
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('system.admin')
->toString());
$this
->clickLink('Add another module');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->addressEquals('admin/modules/install');
$info_parser = new InfoParserDynamic(DRUPAL_ROOT);
$info = $info_parser
->parse($installedInfoFilePath);
$this
->assertEquals('8.x-1.0', $info['version']);
$this
->drupalGet('admin/modules');
$this
->submitForm([
'modules[update_test_new_module][enable]' => TRUE,
], '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
->drupalGet('admin/reports/updates/update');
$this
->submitForm([
'projects[update_test_new_module]' => TRUE,
], 'Download these updates');
$this
->submitForm([
'maintenance_mode' => FALSE,
], 'Continue');
$this
->assertSession()
->pageTextContains('Update was completed successfully.');
$this
->assertSession()
->pageTextContains("Added / updated update_test_new_module successfully");
$info = $info_parser
->parse($installedInfoFilePath);
$this
->assertEquals('8.x-1.1', $info['version']);
}
public function testFileNameExtensionMerging() {
$this
->drupalGet('admin/modules/install');
$this
->assertSession()
->responseMatches('/file extensions are supported:.*update-test-extension/');
$this
->assertSession()
->responseMatches('/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
->assertSession()
->pageTextNotContains('There is a security update available for your version of Drupal.');
$this
->drupalGet('admin/modules/update');
$this
->assertSession()
->pageTextNotContains('There is a security update available for your version of Drupal.');
$this
->drupalGet('admin/appearance/install');
$this
->assertSession()
->pageTextNotContains('There is a security update available for your version of Drupal.');
$this
->drupalGet('admin/appearance/update');
$this
->assertSession()
->pageTextNotContains('There is a security update available for your version of Drupal.');
$this
->drupalGet('admin/reports/updates/install');
$this
->assertSession()
->pageTextNotContains('There is a security update available for your version of Drupal.');
$this
->drupalGet('admin/reports/updates/update');
$this
->assertSession()
->pageTextNotContains('There is a security update available for your version of Drupal.');
$this
->drupalGet('admin/update/ready');
$this
->assertSession()
->pageTextNotContains('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
->assertEquals('Drupal\\Core\\Updater\\Module', $type, 'Detected a Module');
$type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/themes/update_test_basetheme');
$this
->assertEquals('Drupal\\Core\\Updater\\Theme', $type, 'Detected a Theme.');
}
}