You are here

content.test in Patterns 7.2

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

SimpleTests for the Node component of Patterns (Content Types).

File

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

/**
 * @file
 * SimpleTests for the Node component of Patterns (Content Types).
 */
class PatternsContentTypeTestCase extends PatternsTestCase {
  var $node_tests_dir;
  static function getInfo() {
    return array(
      'name' => 'Node component (Content Types)',
      'description' => 'Creates, modifies, and deletes Content Types.',
      '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 content type should not exist at this point.
    $node_type_count = db_select('node_type', 'n')
      ->fields('n', array(
      'type',
    ))
      ->condition('type', 'test_content_type')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertIdentical($node_type_count, '0', t('The content type should not exist at this point.'));

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

    // Expected messages.
    $this
      ->assertUniqueText(t('The content type Test Content Type has been added.'));

    // The content type should exist with the right values.
    $node_type = db_select('node_type', 'n')
      ->fields('n')
      ->condition('type', 'test_content_type')
      ->execute()
      ->fetchAll();
    $this
      ->assertIdentical(count($node_type), 1);
    $this
      ->assertIdentical($node_type[0]->name, 'Test Content Type');
    $this
      ->assertIdentical($node_type[0]->base, 'node_content');
    $this
      ->assertIdentical($node_type[0]->module, 'node');
    $this
      ->assertIdentical($node_type[0]->description, 'Test Content Type Long Description');
    $this
      ->assertIdentical($node_type[0]->help, 'help text');

    // TODO
    $this
      ->assertIdentical($node_type[0]->has_title, '1');

    // TODO
    // TODO: more fields
  }
  private function testDelete() {

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

    // Expected messages.
    $this
      ->assertUniqueText(t('The content type Test Content Type2 has been deleted.'));

    // The content type should exist at this point.
    $node_type_count = db_select('node_type', 'n')
      ->fields('n', array(
      'type',
    ))
      ->condition('type', 'test_content_type')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertIdentical($node_type_count, '0', t('The content type should not exist at this point.'));
  }
  private function testModify() {

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

    // Expected messages.
    $this
      ->assertUniqueText(t('The content type Test Content Type2 has been updated.'));

    // The content type should exist with the right values.
    $node_type = db_select('node_type', 'n')
      ->fields('n')
      ->condition('type', 'test_content_type')
      ->execute()
      ->fetchAll();
    $this
      ->assertIdentical(count($node_type), 1);
    $this
      ->assertIdentical($node_type[0]->name, 'Test Content Type2');
    $this
      ->assertIdentical($node_type[0]->base, 'node_content');
    $this
      ->assertIdentical($node_type[0]->module, 'node');
    $this
      ->assertIdentical($node_type[0]->description, 'Test Content Type Long Description2');
    $this
      ->assertIdentical($node_type[0]->help, 'help text2');

    // TODO
    $this
      ->assertIdentical($node_type[0]->has_title, '1');

    // TODO
    // TODO: more fields
  }

}

Classes

Namesort descending Description
PatternsContentTypeTestCase @file SimpleTests for the Node component of Patterns (Content Types).