importing.test in Patterns 7
Same filename and directory in other branches
Tests importing files.
File
tests/importing/importing.testView source
<?php
/**
* @file
* Tests importing files.
*/
class PatternsImportTestCase extends PatternsTestCase {
const REMOTE_URL_IMPORT = 'http://www.shakty.org/patterns/importing.yaml';
var $importing_tests_dir;
public static function getInfo() {
return array(
'name' => 'Importing files',
'description' => 'Tests importing patterns files.',
'group' => 'Patterns',
);
}
public function setUp($modules = array(), $first = FALSE) {
$this->importing_tests_dir = $this
->getPatternsTestDir() . 'importing/';
// Enable any modules required for the tests.
$modules = array(
'patterns_components',
'patterns_yamlparser',
);
parent::setUp($modules);
}
public function testImportFileFromSource() {
$name = 'Test_Import_From_Source';
$destination = patterns_path_get_files_dir();
// Fill the form.
$edit = array();
$edit['name'] = $name;
$edit['content'] = $this
->loadPattern('importing.yaml', $this->importing_tests_dir);
$edit['destination'] = $destination;
$edit['format'] = PATTERNS_FORMAT_YAML;
// Post the form.
$this
->drupalPost('admin/patterns/import/source', $edit, t('Import'));
$this
->checkImportedFile($name, PATTERNS_FORMAT_YAML, $destination);
}
public function testImportFileFromFile() {
$name = 'Test_Import_From_File';
$destination = $destination = patterns_path_get_files_dir();
// Fill the form.
$edit = array();
$edit['name'] = $name;
$edit['files[pattern_uri]'] = $this->importing_tests_dir . 'importing.yaml';
$edit['destination'] = $destination;
// Post the form.
$this
->drupalPost('admin/patterns/import/file', $edit, t('Import'));
$this
->checkImportedFile($name, PATTERNS_FORMAT_YAML, $destination);
}
public function testImportFileFromURL() {
$name = 'Test_Import_From_URL';
$destination = patterns_path_get_files_dir();
if (!$this
->isFopenurlEnabled()) {
$this
->pass(t('Import from URL test skipped because \'allow_url_fopen\' is disabled.'));
return;
}
// Fill the form.
$edit = array();
$edit['name'] = $name;
$edit['pattern_uri'] = self::REMOTE_URL_IMPORT;
$edit['destination'] = $destination;
// Post the form.
$this
->drupalPost('admin/patterns/import/url', $edit, t('Import'));
$this
->checkImportedFile($name, PATTERNS_FORMAT_YAML, $destination);
}
private function checkImportedFile($name, $format, $destination) {
$this
->assertNoText(t('Errors in the name of the pattern'), t('Errors in the name of the patterns found.'));
$this
->assertNoText(t('Destination folder does not exist or is not writable'), t('Destination folder exists and is writable: ') . $destination);
// TODO: proper t()
$fullname = $name . '.' . $format;
$ps = db_select('patterns', 'p')
->fields('p')
->condition('p.name', $fullname)
->execute()
->fetchAll();
// return array of Std objs
$this
->assertEqual(count($ps), 1, t('One imported pattern found'));
$p = $ps[0];
$this
->assertNotNull($p, t('Imported pattern found in the DB.'));
$this
->assertEqual($p->name, $fullname, t('Imported pattern has the correct name.'));
// Cleanup
$deleted = file_unmanaged_delete($destination . $fullname);
$this
->assertTrue($deleted, t('Test files deleted.'));
}
}
// Class
Classes
Name | Description |
---|---|
PatternsImportTestCase | @file Tests importing files. |