You are here

node.test in Patterns 7.2

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

SimpleTests for the Node component of Patterns (Node).

File

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

/**
 * @file
 * SimpleTests for the Node component of Patterns (Node).
 */
class PatternsNodeTestCase extends PatternsTestCase {
  var $node_tests_dir;
  static function getInfo() {
    return array(
      'name' => 'Node component (Nodes)',
      'description' => 'Creates, modifies, and deletes Nodes.',
      'group' => 'Patterns',
    );
  }
  public function setUp($modules = array(), $first = FALSE) {
    $this->node_tests_dir = $this
      ->getPatternsTestDir() . 'node/';

    // Enable any modules required for the tests.
    $modules = array(
      'patterns_components',
      'patterns_yamlparser',
    );
    parent::setUp($modules);
  }
  public function testCreateModifyDelete() {
    $this
      ->testCreate();
    $this
      ->testModify();
    $this
      ->testDelete();
  }
  private function testCreate() {

    // The node should not exist at this point.
    $node_count = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('type', 'article')
      ->condition('title', 'Test Article')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertIdentical($node_count, '0', t('The node should not exist at this point.'));

    // Run the pattern.
    parent::runFile('node.yaml', 'Nodes (create)', $this->node_tests_dir);

    // Expected messages.
    $this
      ->assertUniqueText(t('Article Test Article has been created.'));

    // The node should exist with the right values.
    $node_count = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('type', 'article')
      ->condition('title', 'Test Article')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertIdentical($node_count, '1', t('The node should exist at this point.'));
  }
  private function testDelete() {

    // Run the pattern.
    parent::runFile('node_delete.yaml', 'Node (delete)', $this->node_tests_dir);

    // Expected messages.
    $this
      ->assertUniqueText(t('Article Test Article2 has been deleted.'));

    // The node should not exist at this point.
    $node_count = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('type', 'article')
      ->condition('title', 'Test Article2')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertIdentical($node_count, '0', t('The node should not exist at this point.'));
  }
  private function testModify() {

    // Run the pattern.
    parent::runFile('node_modify.yaml', 'Node (modify)', $this->node_tests_dir);

    // Expected messages.
    $this
      ->assertText(t('Article Test Article2 has been updated.'));

    // The node should exist with the right values.
    $node_count = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('type', 'article')
      ->condition('title', 'Test Article2')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertIdentical($node_count, '1', t('The node should exist at this point.'));
  }

}

Classes

Namesort descending Description
PatternsNodeTestCase @file SimpleTests for the Node component of Patterns (Node).