You are here

public function DynamicDepthCalculationTest::testCalculateDepth in Taxonomy Term Depth 7

Creates and ensures that a feed is unique, checks source, and deletes feed.

File

./taxonomy_term_depth.test, line 34

Class

DynamicDepthCalculationTest
Tests the taxonomy vocabulary interface.

Code

public function testCalculateDepth() {
  $voc = entity_create('taxonomy_vocabulary', array(
    'machine_name' => 'testvoc',
    'name' => 'testvoc',
    'description' => 'testvoc',
    'help' => 'test',
  ));
  entity_save('taxonomy_vocabulary', $voc);
  $term1 = entity_create('taxonomy_term', array(
    'vid' => $voc->vid,
    'name' => 'Depth 1 term',
  ));
  entity_save('taxonomy_term', $term1);
  $term2 = entity_create('taxonomy_term', array(
    'vid' => $voc->vid,
    'name' => 'Depth 2 term',
    'parent' => array(
      $term1->tid,
    ),
  ));
  entity_save('taxonomy_term', $term2);
  $term3 = entity_create('taxonomy_term', array(
    'vid' => $voc->vid,
    'name' => 'Depth 3 term',
    'parent' => array(
      $term2->tid,
    ),
  ));
  entity_save('taxonomy_term', $term3);
  $this->terms[] = $term1;
  $this->terms[] = $term2;
  $this->terms[] = $term3;
  $this
    ->assertEqual(taxonomy_term_depth_get_by_tid($term1->tid), 1, 'Depth of first term');
  $this
    ->assertEqual(taxonomy_term_depth_get_by_tid($term2->tid), 2, 'Depth of second term');
  $this
    ->assertEqual(taxonomy_term_depth_get_by_tid($term3->tid), 3, 'Depth of third term');
  $chain = taxonomy_term_depth_get_full_chain($term2->tid);
  $compare = [
    $term1->tid,
    $term2->tid,
    $term3->tid,
  ];
  $this
    ->assertTrue($chain === $compare, 'Testing fullchain for term2');
  $chain = taxonomy_term_depth_get_full_chain($term2->tid, TRUE);
  $this
    ->assertTrue($chain === array_reverse($compare), 'Testing reversed fullchain for term2');
  $this
    ->assertEqual(db_query('SELECT depth FROM {taxonomy_term_data} WHERE tid=:tid', [
    ':tid' => $term1->tid,
  ])
    ->fetchField(), 1, 'DB depth_level field of first term');
  $this
    ->assertEqual(db_query('SELECT depth FROM {taxonomy_term_data} WHERE tid=:tid', [
    ':tid' => $term2->tid,
  ])
    ->fetchField(), 2, 'DB depth_level field of second term');
  $this
    ->assertEqual(db_query('SELECT depth FROM {taxonomy_term_data} WHERE tid=:tid', [
    ':tid' => $term3->tid,
  ])
    ->fetchField(), 3, 'DB depth_level field of third term');
  $this
    ->_testDepthCache();
  $this
    ->_testDepthProperty();
}