You are here

public function PatternsTaxonomyTestCase::testCMDVocabulary in Patterns 7.2

Same name and namespace in other branches
  1. 7 tests/taxonomy/taxonomy.test \PatternsTaxonomyTestCase::testCMDVocabulary()

Test the:

  • Creation
  • Modification of name and description
  • Deletion

of a vocabulary with machine_name 'anothervoc'.

File

tests/taxonomy/taxonomy.test, line 41
SimpleTests for the Taxonomy component of Patterns.

Class

PatternsTaxonomyTestCase
@file SimpleTests for the Taxonomy component of Patterns.

Code

public function testCMDVocabulary() {

  // Make sure that 'anothervoc' matches the name in the pattern file
  $voc = 'anothervoc';

  //$taxo = taxonomy_vocabulary_machine_name_load($voc);

  //$this->assertFALSE($taxo, t('Make sure that vocabulary \'anothervoc\' is not already existing.'));

  // CREATE VOCABULARY pattern.
  parent::runFile('taxonomy_vocabulary_add.yaml', 'Taxonomy_Vocabulary_ADD', $this->taxo_tests_dir);
  $taxo = taxonomy_vocabulary_machine_name_load($voc);
  $this
    ->assertNotNull($taxo, t('Vocabulary \'anothervoc\' created.'));
  $this
    ->assertEqual($taxo->machine_name, $voc, t('Vocabulary \'anothervoc\' created with machine_name \'anothervoc\'.'));

  // Run test on terms with the newly created vocabulary
  $this
    ->testCMDTerm();

  // MODIFY VOCABULARY pattern
  $vid = $taxo->vid;
  $name = $taxo->name;
  $descr = $taxo->description;
  $taxo = NULL;
  parent::runFile('taxonomy_vocabulary_modify.yaml', 'Taxonomy_Vocabulary_MODIFY', $this->taxo_tests_dir);

  // Seems to fail
  // $taxo = taxonomy_vocabulary_machine_name_load($voc);
  $taxos = db_select('taxonomy_vocabulary', 'tv')
    ->fields('tv', array(
    'vid',
    'name',
    'description',
  ))
    ->condition('tv.machine_name', $voc)
    ->execute()
    ->fetchAll();

  // return array of Std objs
  $this
    ->assertEqual(count($taxos), 1, t('One vocabulary found'));
  $taxo = $taxos[0];
  $this
    ->assertEqual($taxo->vid, $vid, t('Modify Vocabulary pattern did no alter vid.'));
  $this
    ->assertNotEqual($taxo->name, $name, t('Modify Vocabulary pattern changed name correctly.'));
  $this
    ->assertNotEqual($taxo->description, $descr, t('Modify Vocabulary pattern changed description correctly.'));

  // Delete VOCABULARY pattern
  parent::runFile('taxonomy_vocabulary_delete.yaml', 'Taxonomy_Vocabulary_DELETE', $this->taxo_tests_dir);
  $taxos = db_select('taxonomy_vocabulary', 'tv')
    ->fields('tv', array(
    'vid',
    'name',
    'description',
  ))
    ->condition('tv.machine_name', $voc)
    ->execute()
    ->fetchAll();

  // return array of Std objs
  $this
    ->assertEqual(count($taxos), 0, t('Vocabulary \'anothervoc\' deleted.'));

  //$this->verbose('Vocabulary modified: ' . var_export($taxo, TRUE));
}