You are here

parser.test in Patterns 7.2

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

SimpleTests for the Taxonomy component of Patterns.

File

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

/**
 * @file
 * SimpleTests for the Taxonomy component of Patterns.
 */
class PatternsParserTestCase extends PatternsTestCase {
  var $parser_tests_dir;
  public static function getInfo() {
    return array(
      'name' => 'Parser',
      'description' => 'Tests the validation algorithm against valid and invalid patterns.',
      'group' => 'Patterns',
    );
  }
  public function setUp($modules = array(), $first = FALSE) {
    $this->parser_tests_dir = $this
      ->getPatternsTestDir() . 'parser/';

    // Enable any modules required for the tests.
    $modules = array(
      'patterns_components',
      'patterns_yamlparser',
    );
    parent::setUp($modules);
  }
  public function testValidSyntaxP() {
    $dir = $this->parser_tests_dir . 'valid_syntax/';
    $this
      ->callbackOnDir($dir, array(
      &$this,
      'check_valid_syntax_only',
    ));
  }
  public function testInvalidP() {
    $dir = $this->parser_tests_dir . 'invalid/';
    $this
      ->callbackOnDir($dir, array(
      &$this,
      'check_invalid',
    ));
  }
  public function testvalidP() {
    $dir = $this->parser_tests_dir . 'valid_semantics/';
    $this
      ->callbackOnDir($dir, array(
      &$this,
      'check_valid_semantics',
    ));
  }
  private function scan_pattern($pattern) {
    $scan = patterns_scan_pattern($pattern);
    $this
      ->assertNotNull($scan, t('Pattern file loaded and scanned.'));
    return $scan;
  }
  private function analyze_scan($scan, $level, $include = FALSE) {
    $analysis = _patterns_scan_analyze_patternscan($scan, $include, $level);
    $this
      ->assertNotNull($analysis, t('Pattern-scan was analyzed successfully.'));
    return $analysis;
  }
  public function check_valid_syntax_only($pattern) {
    $scan = $this
      ->scan_pattern($pattern);
    $analysis = $this
      ->analyze_scan($scan, PATTERNS_VALIDATE_SYNTAX);
    $this
      ->assertEqual(count($analysis), 0, t('No error message generated while parsing syntactically valid pattern.'));
    $analysis = $this
      ->analyze_scan($scan, PATTERNS_VALIDATE_ALL);
    $this
      ->assertNotEqual(count($analysis), 0, t('Error messages generated while parsing semantically invalid pattern.'));
  }
  public function check_valid_semantics($pattern) {
    $scan = $this
      ->scan_pattern($pattern);
    $analysis = $this
      ->analyze_scan($scan, PATTERNS_VALIDATE_SYNTAX);
    $this
      ->assertEqual(count($analysis), 0, t('No error message generated while parsing syntactically valid pattern.'));
    $analysis = $this
      ->analyze_scan($scan, PATTERNS_VALIDATE_ALL);
    $this
      ->assertEqual(count($analysis), 0, t('Error messages generated while parsing semantically invalid pattern.'));
  }
  public function check_invalid($pattern) {
    $scan = $this
      ->scan_pattern($pattern);
    $analysis = $this
      ->analyze_scan($scan, PATTERNS_VALIDATE_SYNTAX);
    $this
      ->assertNotEqual(count($analysis), 0, t('No error message generated while parsing syntactically valid pattern.'));
    $analysis = $this
      ->analyze_scan($scan, PATTERNS_VALIDATE_ALL);
    $this
      ->assertNotEqual(count($analysis), 0, t('Error messages generated while parsing semantically invalid pattern.'));
  }

}

Classes

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