. */ /** * Doctrine_Tokenizer_TestCase * This class tests the functinality of Doctrine_Tokenizer component * * @package Doctrine * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.com * @since 1.0 * @version $Revision: 1181 $ * @author Konsta Vesterinen */ class Doctrine_Tokenizer_TestCase extends Doctrine_UnitTestCase { public function prepareData() { } public function prepareTables() { } public function testSqlExplode() { $tokenizer = new Doctrine_Query_Tokenizer(); $str = "word1 word2 word3"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "word2", "word3")); $str = "word1 (word2 word3)"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "(word2 word3)")); $str = "word1 'word2 word3'"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "'word2 word3'")); $str = "word1 'word2 word3'"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "'word2 word3'")); $str = "word1 \"word2 word3\""; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "\"word2 word3\"")); $str = "word1 ((word2) word3)"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "((word2) word3)")); $str = "word1 ( (word2) 'word3')"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "( (word2) 'word3')")); $str = "word1 ( \"(word2) 'word3')"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "( \"(word2) 'word3')")); $str = "word1 ( ''(word2) 'word3')"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "( ''(word2) 'word3')")); $str = "word1 ( '()()'(word2) 'word3')"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "( '()()'(word2) 'word3')")); $str = "word1 'word2)() word3'"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "'word2)() word3'")); $str = "word1 (word2() word3)"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "(word2() word3)")); $str = "word1 \"word2)() word3\""; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("word1", "\"word2)() word3\"")); $str = "something (subquery '')"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("something", "(subquery '')")); $str = "something (( ))"; $a = $tokenizer->sqlExplode($str); $this->assertEqual($a, array("something", "(( ))")); } public function testSqlExplode2() { $tokenizer = new Doctrine_Query_Tokenizer(); $str = 'rdbms (dbal OR database)'; $a = $tokenizer->sqlExplode($str, ' OR '); $this->assertEqual($a, array('rdbms (dbal OR database)')); } public function testBracketExplode() { $tokenizer = new Doctrine_Query_Tokenizer(); $str = 'foo.field AND bar.field'; $a = $tokenizer->bracketExplode($str, array(' \&\& ', ' AND '), '(', ')'); $this->assertEqual($a, array('foo.field', 'bar.field')); // delimiters should be case insensitive $str = 'foo.field and bar.field'; $a = $tokenizer->bracketExplode($str, array(' \&\& ', ' AND '), '(', ')'); $this->assertEqual($a, array('foo.field', 'bar.field')); } public function testQuoteExplodedShouldQuoteArray() { $tokenizer = new Doctrine_Query_Tokenizer(); $term = $tokenizer->quoteExplode("test", array("'test'", "test2")); $this->assertEqual($term[0], "test"); } }