Same name and namespace in other branches
- 8.9.x core/modules/config/tests/src/Functional/ConfigImportUploadTest.php \Drupal\Tests\config\Functional\ConfigImportUploadTest
- 9 core/modules/config/tests/src/Functional/ConfigImportUploadTest.php \Drupal\Tests\config\Functional\ConfigImportUploadTest
Tests importing configuration from an uploaded file.
@group config
Hierarchy
- class \Drupal\Tests\config\Functional\ConfigImportUploadTest extends \Drupal\Tests\BrowserTestBase uses TestFileCreationTrait
Expanded class hierarchy of ConfigImportUploadTest
File
- core/
modules/ config/ tests/ src/ Functional/ ConfigImportUploadTest.php, line 16
Namespace
Drupal\Tests\config\FunctionalView source
class ConfigImportUploadTest extends BrowserTestBase {
use TestFileCreationTrait;
/**
* A user with the 'import configuration' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'config',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'import configuration',
]);
$this
->drupalLogin($this->webUser);
}
/**
* Tests importing configuration.
*/
public function testImport() {
// Verify access to the config upload form.
$this
->drupalGet('admin/config/development/configuration/full/import');
$this
->assertSession()
->statusCodeEquals(200);
// Attempt to upload a non-tar file.
$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');
// Make the sync directory read-only.
$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.");
// Ensure submit button for \Drupal\config\Form\ConfigImportForm is
// disabled.
$submit_is_disabled = $this
->cssSelect('form.config-import-form input[type="submit"]:disabled');
$this
->assertCount(1, $submit_is_disabled, 'The submit button is disabled.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigImportUploadTest:: |
protected | property | ||
ConfigImportUploadTest:: |
protected static | property | Modules to install. | |
ConfigImportUploadTest:: |
protected | property | A user with the 'import configuration' permission. | |
ConfigImportUploadTest:: |
protected | function | ||
ConfigImportUploadTest:: |
public | function | Tests importing configuration. | |
TestFileCreationTrait:: |
protected | property | Whether the files were copied to the test files directory. | |
TestFileCreationTrait:: |
protected | function | Compares two files based on size and file name. | |
TestFileCreationTrait:: |
public static | function | Generates a test file. | |
TestFileCreationTrait:: |
protected | function | Gets a list of files that can be used in tests. |