- <?php
- * @file
- * Tests for File Example.
- */
-
- * Functional tests for the File Example module.
- *
- * @ingroup file_example
- */
- class FileExampleTest extends BackdropWebTestCase {
-
- protected $priviledgedUser;
-
-
- * {@inheritdoc}
- */
- public function setUp() {
- parent::setUp(array('file_example'));
- $this->priviledgedUser = $this->backdropCreateUser(array('use file example'));
- $this->backdropLogin($this->priviledgedUser);
- }
-
-
- * Test the basic File Example UI.
- *
- * - Create a directory to work with
- * - Foreach scheme create and read files using each of the three methods.
- */
- public function testFileExampleBasic() {
-
- $expected_text = array(
- t('Write managed file') => t('Saved managed file'),
- t('Write unmanaged file') => t('Saved file as'),
- t('Unmanaged using PHP') => t('Saved file as'),
- );
-
- $buttons = array(
- t('Write managed file'),
- t('Write unmanaged file'),
- t('Unmanaged using PHP'),
- );
- foreach ($buttons as $button) {
-
- $schemes = array('public', 'private', 'temporary', 'session');
- foreach ($schemes as $scheme) {
-
- $dirname = $scheme . '://' . $this->randomName(10);
-
-
- $edit = array(
- 'directory_name' => $dirname,
- );
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Check to see if directory exists'));
- $this->assertRaw(t('Directory %dirname does not exist', array('%dirname' => $dirname)), 'Verify that directory does not exist.');
-
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Create directory'));
- $this->assertRaw(t('Directory %dirname is ready for use', array('%dirname' => $dirname)));
-
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Check to see if directory exists'));
- $this->assertRaw(t('Directory %dirname exists', array('%dirname' => $dirname)), 'Verify that directory now does exist.');
-
-
- $content = $this->randomName(30);
- $filename = $dirname . '/' . $this->randomName(30) . '.txt';
-
-
- $edit = array(
- 'fileops_file' => $filename,
- );
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Check to see if file exists'));
- $this->assertRaw(t('The file %filename does not exist', array('%filename' => $filename)), 'Verify that file does not yet exist.');
-
- debug(
- t('Processing button=%button, scheme=%scheme, dir=%dirname, file=%filename',
- array(
- '%button' => $button,
- '%scheme' => $scheme,
- '%filename' => $filename,
- '%dirname' => $dirname,
- )
- )
- );
- $edit = array(
- 'write_contents' => $content,
- 'destination' => $filename,
- );
- $this->backdropPost('examples/file_example/fileapi', $edit, $button);
- $this->assertText($expected_text[$button]);
-
-
-
- $element = $this->xpath('//span[@id="uri"]');
- $output_filename = (string) $element[0];
- debug($output_filename, 'Name of output file');
-
-
-
- if (!in_array($scheme, array('private', 'temporary'))) {
- $this->clickLink(t('this URL'));
- $this->assertText($content);
- }
-
-
- $edit = array(
- 'fileops_file' => $filename,
- );
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Check to see if file exists'));
- $this->assertRaw(t('The file %filename exists', array('%filename' => $filename)), 'Verify that file now exists.');
-
-
-
- $edit = array(
- 'fileops_file' => $output_filename,
- );
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Read the file and store it locally'));
-
- $this->assertText(t('The file was read and copied'));
-
- $edit = array(
- 'fileops_file' => $filename,
- );
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Delete file'));
- $this->assertText(t('Successfully deleted'));
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Check to see if file exists'));
- $this->assertRaw(t('The file %filename does not exist', array('%filename' => $filename)), 'Verify file has been deleted.');
-
- $edit = array(
- 'directory_name' => $dirname,
- );
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Delete directory'));
- $this->backdropPost('examples/file_example/fileapi', $edit, t('Check to see if directory exists'));
- $this->assertRaw(t('Directory %dirname does not exist', array('%dirname' => $dirname)), 'Verify that directory does not exist after deletion.');
- }
- }
- }
- }