You are here

public function PatternsExportTestCase::testExportTaxonomy in Patterns 7.2

Same name and namespace in other branches
  1. 7 tests/exporting/exporting.test \PatternsExportTestCase::testExportTaxonomy()

File

tests/exporting/exporting.test, line 34
Tests importing files.

Class

PatternsExportTestCase
@file Tests importing files.

Code

public function testExportTaxonomy() {
  $destination = patterns_path_get_files_dir();

  // Fill the form.
  $edit = array();
  $pattern_str = $this
    ->loadPattern('exporting.yaml', $this->exporting_tests_dir);
  $pattern_array = patterns_parser_parse($pattern_str, PATTERNS_FORMAT_YAML);
  $pattern_name = 'exp_test';

  // Importing
  $edit['name'] = 'imported';
  $edit['content'] = $pattern_str;
  $edit['destination'] = $destination;
  $edit['format'] = PATTERNS_FORMAT_YAML;

  // Post the form.
  $this
    ->drupalPost('admin/patterns/import/source', $edit, t('Import'));
  $imp_pattern = patterns_get_pattern('imported.yaml');
  $result = $this
    ->assertTrue($imp_pattern !== FALSE, t('Importing a pattern (before exporting it) worked.'));
  if (!$result) {
    $this
      ->fail('Import failed');
    return FALSE;
  }

  // Exporting
  $export_form = array();
  $export_form['all'] = 1;
  $export_form['ext[taxonomy][options][vocabulary]'] = 1;
  $export_form['export[to]'] = PATTERNS_EXPORT_TO_DB;
  $export_form['format'] = PATTERNS_FORMAT_YAML;
  $export_form['pattern_name'] = 'exported';

  // Post the form.
  $this
    ->drupalPost('admin/patterns/export', $export_form, t('Export'));
  $result = $this
    ->assertNoText(t('No valid format selected.'), t('No errors in the export format'));
  $result = $result && $this
    ->assertNoText(t('Please specify a valid file name.'), t('No errors in the name of the export file'));
  $result = $result && $this
    ->assertNoText(t('Please specify a valid export mode.'), t('No errors in the export mode'));
  $result = $result && $this
    ->assertNoText(t('No info section found.'), t('Info section found'));
  $result = $result && $this
    ->assertNoText(t('Export did not return any data.'), t('Export returned data.'));
  if (!$result) {
    $this
      ->fail(t('Export failed'));
    return FALSE;
  }
  $patterns = patterns_db_get_patterns();
  $this
    ->assertTrue(count($patterns) == 2, t('Exported pattern was inserted into the database.'));
  $exported = patterns_get_pattern('exported.yaml');
  $this
    ->assertTrue($exported !== FALSE, t('Exported pattern correctly found in the database'));
  $exp_pattern_array = $exported->pattern;
  $this
    ->assertNotNull($exp_pattern_array, t('Exported pattern is not empty'));

  // TODO: Cannot test this
  // Simpletests fails, and returns a wrong database from which exporting data
  // Anyway, I should test only the content of the action, not the whole pattern

  //$this->assertIdentical($exp_pattern_array, $pattern_array, t('Exported pattern is identical to imported one.'));
}