You are here

taxonomy.test in Patterns 7.2

Same filename and directory in other branches
  1. 7 tests/taxonomy/taxonomy.test

SimpleTests for the Taxonomy component of Patterns.

File

tests/taxonomy/taxonomy.test
View source
<?php

/**
 * @file
 * SimpleTests for the Taxonomy component of Patterns.
 */
class PatternsTaxonomyTestCase extends PatternsTestCase {
  var $taxo_tests_dir;
  public static function getInfo() {
    return array(
      'name' => 'Taxonomy component',
      'description' => 'Tests creating, modifying, deleting Vocabularies and Terms.',
      'group' => 'Patterns',
    );
  }
  public function setUp($modules = array(), $first = FALSE) {
    $this->taxo_tests_dir = $this
      ->getPatternsTestDir() . 'taxonomy/';

    // Enable any modules required for the tests.
    $modules = array(
      'patterns_components',
      'patterns_yamlparser',
    );
    parent::setUp($modules);
  }

  /**
   * Test the:
   *
   *    * Creation
   *    * Modification of name and description
   *    * Deletion
   *
   * of a vocabulary with machine_name 'anothervoc'.
   *
   */
  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));
  }

  /**
   * Test the:
   *
   *    * Creation
   *    * Modification of name and description
   *    * Deletion
   *
   * of a term with name 'Patatina'.
   *
   */
  private function testCMDTerm() {

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

    // CREATE Term pattern.
    parent::runFile('taxonomy_term_add.yaml', 'Taxonomy_Term_ADD', $this->taxo_tests_dir);
    $terms = taxonomy_get_term_by_name($term);

    //$this->assertNotNull($terms, t('Terms found.'));
    $this
      ->assertEqual(count($terms), 1, 'Term found');
    $t = $terms[1];
    $this
      ->assertEqual($t->name, $term, t('Term created with name \'Patatina\'.'));

    // MODIFY Term pattern
    $vid = $t->vid;
    $tid = $t->tid;
    $name = $t->name;
    $descr = $t->description;
    $t = NULL;
    parent::runFile('taxonomy_term_modify.yaml', 'Taxonomy_Term_MODIFY', $this->taxo_tests_dir);
    $terms = db_select('taxonomy_term_data', 'ttd')
      ->fields('ttd', array(
      'vid',
      'tid',
      'name',
      'description',
    ))
      ->condition('ttd.tid', $tid)
      ->execute()
      ->fetchAll();

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

    // DELETE Term pattern
    parent::runFile('taxonomy_term_delete.yaml', 'Taxonomy_Term_DELETE', $this->taxo_tests_dir);
    $terms = db_select('taxonomy_term_data', 'ttd')
      ->fields('ttd', array(
      'vid',
      'tid',
      'name',
      'description',
    ))
      ->condition('ttd.name', $term)
      ->execute()
      ->fetchAll();

    // return array of Std objs
    $this
      ->assertEqual(count($terms), 0, t('Term \'Patatina\' deleted.'));

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

}

Classes

Namesort descending Description
PatternsTaxonomyTestCase @file SimpleTests for the Taxonomy component of Patterns.