You are here

public function NatSecondaryTest::testNatAssociation in Node Auto Term [NAT] 6.2

Same name and namespace in other branches
  1. 6 tests/nat.test \NatSecondaryTest::testNatAssociation()
  2. 7.2 tests/nat.test \NatSecondaryTest::testNatAssociation()
  3. 7 tests/nat.test \NatSecondaryTest::testNatAssociation()

Test different settings.

File

tests/nat.test, line 253
NAT module functionality tests.

Class

NatSecondaryTest
Test different settings. Due to static settings caching we have to use a second test case for this.

Code

public function testNatAssociation() {
  $this
    ->drupalLogin($this->nat_user);

  // Create NAT node
  $settings = array(
    'type' => $this->nat_type,
    'title' => $this->nat_node_title,
    'body' => $this->nat_node_body,
  );
  $node = $this
    ->drupalCreateNode($settings);
  $terms = taxonomy_get_term_by_name($node->title);
  $this
    ->assertTRUE(count($terms) === 2, 'Found 2 terms');

  // Check for empty description.
  $this
    ->assertTRUE($terms[0]->description === '', 'Term 1 description is correct');
  $this
    ->assertTRUE($terms[1]->description === '', 'Term 2 description is correct');

  // Delete node.
  node_delete($node->nid);

  // Check that terms are not deleted.
  $this
    ->assertTRUE(count(taxonomy_get_term_by_name($this->nat_node_title)) === 2, 'Found 2 terms');

  // Get tid in regards of the vid.
  $vocab1_tid = $terms[0]->vid === $this->nat_vocab1->vid ? $terms[0]->tid : $terms[1]->tid;
  $vocab2_tid = $terms[0]->vid === $this->nat_vocab2->vid ? $terms[0]->tid : $terms[1]->tid;

  // Create node with synonyms.
  $title = $this
    ->randomName();
  $edit = array(
    'title' => $title,
    'nat[related][' . $this->nat_vocab1->vid . '][]' => $vocab1_tid,
    'nat[related][' . $this->nat_vocab2->vid . '][]' => $vocab2_tid,
    'nat[synonyms]' => 'Foo',
  );
  $this
    ->drupalPost('node/add/' . $this->nat_type, $edit, t('Save'));

  // Load the node and its edit page to check the data.
  $node = node_load(array(
    'title' => $title,
  ));
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertFieldByName('nat[related][' . $this->nat_vocab1->vid . '][]', $vocab1_tid, 'Found relation for vocab1');
  $this
    ->assertFieldByName('nat[related][' . $this->nat_vocab2->vid . '][]', $vocab2_tid, 'Found relation for vocab2');
  $this
    ->assertFieldByName('nat[synonyms]', 'Foo', 'Found synonym');
  $this
    ->drupalLogout($this->nat_user);
}