Source of file HeuristicParserTest.php
Size: 4,390 Bytes - Last Modified: 2021-12-23T10:02:17+00:00
/var/www/docs.ssmods.com/process/src/tests/HeuristicParserTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 | <?php namespace Seeder\Tests; use Seeder\Helpers\HeuristicParser; use Seeder\Util\Field; /** * Class HeuristicParserTest * @package Seeder\Tests */ class HeuristicParserTest extends \SapphireTest { /** * @var bool */ protected $usesDatabase = true; /** * @var array */ protected $extraDataObjects = array( 'Seeder\Tests\Dog', 'Seeder\Tests\House', 'Seeder\Tests\Human', 'Seeder\Tests\Pet', 'Seeder\Tests\Treat', ); /** * */ public function __construct() { parent::__construct(); $this->setUpOnce(); } /** * */ public function testParse_HeuristicWithOneCondition_HeuristicParsedCorrectly() { $parser = new HeuristicParser(); $heuristics = $parser->parse(array( 'Dog' => array( 'conditions' => array( 'name' => 'Age' ), ), )); $heuristic = $heuristics[0]; $this->assertEquals(1, $heuristic->getSpecificity()); $field = new Field(); $field->name = 'Age'; $this->assertTrue($heuristic->match($field)); $field->name = 'Bob'; $this->assertFalse($heuristic->match($field)); } /** * */ public function testParse_HeuristicWithMultipleConditionsMultipleMatchers_HeuristicParsedCorrectly() { $parser = new HeuristicParser(); $heuristics = $parser->parse(array( 'Dog' => array( 'conditions' => array( 'name' => array('Name', 'Age'), 'fieldType' => Field::FT_HAS_ONE, ), ), )); $heuristic = $heuristics[0]; $field = new Field(); $field->name = 'Name'; $field->fieldType = Field::FT_HAS_ONE; $this->assertTrue($heuristic->match($field)); $field->name = 'Age'; $this->assertTrue($heuristic->match($field)); $field->fieldType = Field::FT_HAS_MANY; $this->assertFalse($heuristic->match($field)); } /** * */ public function testParse_HeuristicsWithLikeMatcher_HeuristicParsedCorrectly() { $parser = new HeuristicParser(); $heuristics = $parser->parse(array( 'Dog' => array( 'conditions' => array( 'name' => array( 'like(bob)', 'like(%label)', 'like(%content%)', 'like(home%)', ), ), ), )); $heuristic = $heuristics[0]; $field = new Field(); $field->name = 'Bob'; $this->assertTrue($heuristic->match($field)); $field->name = 'jjbobhh'; $this->assertFalse($heuristic->match($field)); $field->name = 'GraphLabel'; $this->assertTrue($heuristic->match($field)); $field->name = 'LabelGraph'; $this->assertFalse($heuristic->match($field)); $field->name = 'Content'; $this->assertTrue($heuristic->match($field)); $field->name = 'HomePage'; $this->assertTrue($heuristic->match($field)); $field->name = 'PageHome'; $this->assertFalse($heuristic->match($field)); } /** * */ public function testParse_ParentHeuristics_HeuristicParsedCorrectly() { $parser = new HeuristicParser(); $heuristics = $parser->parse(array( 'Test' => array( 'conditions' => array( 'parent.fieldType' => array( 'has_many', 'many_many' ), ), ), )); $heuristic = $heuristics[0]; $field = new Field(); $field->fieldType = 'has_many'; $childField = new Field(); $childField->parent = $field; $childField->fieldType = 'has_many'; $this->assertTrue($heuristic->match($childField)); $field->fieldType = 'has_one'; $this->assertFalse($heuristic->match($childField)); } // // /** // * // */ // public static function tearDownAfterClass() // { // parent::tearDownAfterClass(); // \SapphireTest::delete_all_temp_dbs(); // } } |