955842d01b289a8a784e356d411a43615e907df4
[yaffs-website] / web / core / modules / config / tests / src / Functional / ConfigImportUploadTest.php
1 <?php
2
3 namespace Drupal\Tests\config\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\TestFileCreationTrait;
7
8 /**
9  * Tests importing configuration from an uploaded file.
10  *
11  * @group config
12  */
13 class ConfigImportUploadTest extends BrowserTestBase {
14
15   use TestFileCreationTrait;
16
17   /**
18    * A user with the 'import configuration' permission.
19    *
20    * @var \Drupal\user\UserInterface
21    */
22   protected $webUser;
23
24   /**
25    * Modules to install.
26    *
27    * @var array
28    */
29   public static $modules = ['config'];
30
31   protected function setUp() {
32     parent::setUp();
33
34     $this->webUser = $this->drupalCreateUser(['import configuration']);
35     $this->drupalLogin($this->webUser);
36   }
37
38   /**
39    * Tests importing configuration.
40    */
41   public function testImport() {
42     // Verify access to the config upload form.
43     $this->drupalGet('admin/config/development/configuration/full/import');
44     $this->assertResponse(200);
45
46     // Attempt to upload a non-tar file.
47     $text_file = $this->getTestFiles('text')[0];
48     $edit = ['files[import_tarball]' => drupal_realpath($text_file->uri)];
49     $this->drupalPostForm('admin/config/development/configuration/full/import', $edit, t('Upload'));
50     $this->assertText(t('Could not extract the contents of the tar file'));
51
52     // Make the sync directory read-only.
53     $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
54     \Drupal::service('file_system')->chmod($directory, 0555);
55     $this->drupalGet('admin/config/development/configuration/full/import');
56     $this->assertRaw(t('The directory %directory is not writable.', ['%directory' => $directory]));
57     // Ensure submit button for \Drupal\config\Form\ConfigImportForm is
58     // disabled.
59     $submit_is_disabled = $this->cssSelect('form.config-import-form input[type="submit"]:disabled');
60     $this->assertTrue(count($submit_is_disabled) === 1, 'The submit button is disabled.');
61   }
62
63 }