ConfigImportUploadTest.php in Drupal 9
File
core/modules/config/tests/src/Functional/ConfigImportUploadTest.php
View source
<?php
namespace Drupal\Tests\config\Functional;
use Drupal\Core\Site\Settings;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait;
class ConfigImportUploadTest extends BrowserTestBase {
use TestFileCreationTrait;
protected $webUser;
protected static $modules = [
'config',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'import configuration',
]);
$this
->drupalLogin($this->webUser);
}
public function testImport() {
$this
->drupalGet('admin/config/development/configuration/full/import');
$this
->assertSession()
->statusCodeEquals(200);
$text_file = $this
->getTestFiles('text')[0];
$edit = [
'files[import_tarball]' => \Drupal::service('file_system')
->realpath($text_file->uri),
];
$this
->drupalGet('admin/config/development/configuration/full/import');
$this
->submitForm($edit, 'Upload');
$this
->assertSession()
->pageTextContains('Could not extract the contents of the tar file');
$directory = Settings::get('config_sync_directory');
\Drupal::service('file_system')
->chmod($directory, 0555);
$this
->drupalGet('admin/config/development/configuration/full/import');
$this
->assertSession()
->pageTextContains("The directory {$directory} is not writable.");
$submit_is_disabled = $this
->cssSelect('form.config-import-form input[type="submit"]:disabled');
$this
->assertCount(1, $submit_is_disabled, 'The submit button is disabled.');
}
}