public function FileEntityCreationTest::testFileEntityCreationMultipleSteps in File Entity (fieldable files) 8.2
Upload a file with both private and public folder set.
Should have one extra step selecting a scheme. Selects private scheme and checks if the file is succesfully uploaded to the private folder.
File
- tests/
src/ Functional/ FileEntityCreationTest.php, line 69
Class
- FileEntityCreationTest
- Tests creating and saving a file.
Namespace
Drupal\Tests\file_entity\FunctionalCode
public function testFileEntityCreationMultipleSteps() {
$test_file = $this
->getTestFile('text');
// Create a file.
$edit = array();
$edit['files[upload]'] = \Drupal::service('file_system')
->realpath($test_file->uri);
$this
->drupalGet('file/add');
$this
->assertEmpty($this
->xpath('//input[@id="edit-upload-remove-button"]'), 'Remove');
$this
->drupalPostForm(NULL, $edit, t('Next'));
// Check if your on form step 2, scheme selecting.
// At this point it should not skip this form.
$this
->assertNotEmpty($this
->xpath('//input[@name="scheme"]'), "Loaded select destination scheme page.");
// Test if the public radio button is selected by default.
$this
->assertFieldChecked('edit-scheme-public', 'Public Scheme is checked');
// Submit form and set scheme to private.
$edit = array();
$edit['scheme'] = 'private';
$this
->drupalPostForm(NULL, $edit, t('Next'));
// Check that the document file has been uploaded.
$this
->assertRaw(t('@type %name was uploaded.', array(
'@type' => 'Document',
'%name' => 'text-0_0.txt',
)), t('Document file uploaded.'));
// Check that the file exists in the database.
$file = $this
->getFileByFilename('text-0_0.txt');
$this
->assertInstanceOf(FileInterface::class, $file, t('File found in database.'));
// Check if the file is stored in the private folder.
$this
->assertTrue(substr($file
->getFileUri(), 0, 10) === 'private://', 'File uploaded in private folder.');
}