diff --git a/tests/RawSqlTestCase.php b/tests/RawSqlTestCase.php index 5d5b10ecf..40a0f00ff 100644 --- a/tests/RawSqlTestCase.php +++ b/tests/RawSqlTestCase.php @@ -1,7 +1,40 @@ . + */ - public function testQueryParser() { +/** + * Doctrine_RawSql_TestCase + * This class tests the functinality of Doctrine_RawSql 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_RawSql_TestCase extends Doctrine_UnitTestCase +{ + public function testQueryParser() + { $sql = "SELECT {p.*} FROM photos p"; $query = new Doctrine_RawSql($this->connection); $query->parseQuery($sql); @@ -16,8 +49,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($query->where, array('p.can_see = -1 AND t.tag_id = 62')); $this->assertEqual($query->limit, array(200)); } - - public function testAsteriskOperator() { + public function testAsteriskOperator() + { // Selecting with * $query = new Doctrine_RawSql($this->connection); @@ -32,8 +65,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($coll->count(), 11); } - - public function testLazyPropertyLoading() { + public function testLazyPropertyLoading() + { $query = new Doctrine_RawSql($this->connection); $this->connection->clear(); @@ -52,8 +85,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($coll[0]->state(), Doctrine_Record::STATE_PROXY); $this->assertEqual($coll[3]->state(), Doctrine_Record::STATE_PROXY); } - - public function testSmartMapping() { + public function testSmartMapping() + { $query = new Doctrine_RawSql($this->connection); // smart component mapping (no need for additional addComponent call @@ -70,7 +103,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($coll[3]->state(), Doctrine_Record::STATE_PROXY); } - public function testMultipleComponents() { + public function testMultipleComponents() + { $query = new Doctrine_RawSql($this->connection); // multi component fetching @@ -90,7 +124,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $coll[5]->Phonenumber[0]->phonenumber; $this->assertEqual($count, $this->dbh->count()); } - public function testPrimaryKeySelectForcing() { + public function testPrimaryKeySelectForcing() + { // forcing the select of primary key fields $query = new Doctrine_RawSql($this->connection); @@ -104,7 +139,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertTrue(is_numeric($coll[3]->id)); $this->assertTrue(is_numeric($coll[7]->id)); } - public function testMethodOverloading() { + public function testMethodOverloading() + { $query = new Doctrine_RawSql($this->connection); $query->select('{entity.name}')->from('entity'); $query->addComponent("entity", "User"); @@ -116,7 +152,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertTrue(is_numeric($coll[7]->id)); } - public function testColumnAggregationInheritance() { + public function testColumnAggregationInheritance() + { // forcing the select of primary key fields $query = new Doctrine_RawSql($this->connection); @@ -131,7 +168,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertTrue(is_numeric($coll[7]->id)); } - public function testColumnAggregationInheritanceWithOrderBy() { + public function testColumnAggregationInheritanceWithOrderBy() + { // forcing the select of primary key fields $query = new Doctrine_RawSql($this->connection); @@ -150,68 +188,9 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase { $this->assertTrue(is_numeric($coll[7]->id)); } - public function testsqlExplode() { - $str = "word1 word2 word3"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "word2", "word3")); - - $str = "word1 (word2 word3)"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "(word2 word3)")); - - $str = "word1 'word2 word3'"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "'word2 word3'")); - $str = "word1 ´word2 word3´"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "´word2 word3´")); - - $str = "word1 \"word2 word3\""; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "\"word2 word3\"")); - - $str = "word1 ((word2) word3)"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "((word2) word3)")); - - $str = "word1 ( (word2) 'word3')"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "( (word2) 'word3')")); - - $str = "word1 ( \"(word2) 'word3')"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "( \"(word2) 'word3')")); - - $str = "word1 ( ´´(word2) 'word3')"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "( ´´(word2) 'word3')")); - - $str = "word1 ( ´()()´(word2) 'word3')"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "( ´()()´(word2) 'word3')")); - - $str = "word1 'word2)() word3'"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "'word2)() word3'")); - - $str = "word1 ´word2)() word3´"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "´word2)() word3´")); - - $str = "word1 \"word2)() word3\""; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("word1", "\"word2)() word3\"")); - - $str = "something (subquery '')"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("something", "(subquery '')")); - - $str = "something (( ))"; - $a = Doctrine_Query::sqlExplode($str); - $this->assertEqual($a, array("something", "(( ))")); - } - public function testQueryParser2() { + public function testQueryParser2() + { $query = new Doctrine_RawSql(); $query->parseQuery("SELECT {entity.name} FROM (SELECT entity.name FROM entity WHERE entity.name = 'something') WHERE entity.id = 2 ORDER BY entity.name"); diff --git a/tests/Sequence.php b/tests/Sequence.php deleted file mode 100644 index 9253a8d43..000000000 --- a/tests/Sequence.php +++ /dev/null @@ -1,36 +0,0 @@ -. - */ - -/** - * Doctrine_Connection_TestCase - * - * @package Doctrine - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Sequence_TestCase extends Doctrine_UnitTestCase -{ - -} diff --git a/tests/TokenizerTestCase.php b/tests/TokenizerTestCase.php new file mode 100644 index 000000000..1bc925f0e --- /dev/null +++ b/tests/TokenizerTestCase.php @@ -0,0 +1,98 @@ +. + */ + +/** + * 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 testSqlExplode() + { + $str = "word1 word2 word3"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "word2", "word3")); + + $str = "word1 (word2 word3)"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "(word2 word3)")); + + $str = "word1 'word2 word3'"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "'word2 word3'")); + + $str = "word1 'word2 word3'"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "'word2 word3'")); + + $str = "word1 \"word2 word3\""; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "\"word2 word3\"")); + + $str = "word1 ((word2) word3)"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "((word2) word3)")); + + $str = "word1 ( (word2) 'word3')"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "( (word2) 'word3')")); + + $str = "word1 ( \"(word2) 'word3')"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "( \"(word2) 'word3')")); + + $str = "word1 ( ''(word2) 'word3')"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "( ''(word2) 'word3')")); + + $str = "word1 ( '()()'(word2) 'word3')"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "( '()()'(word2) 'word3')")); + + $str = "word1 'word2)() word3'"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "'word2)() word3'")); + + $str = "word1 (word2() word3)"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "(word2() word3)")); + + $str = "word1 \"word2)() word3\""; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("word1", "\"word2)() word3\"")); + + $str = "something (subquery '')"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("something", "(subquery '')")); + + $str = "something (( ))"; + $a = Doctrine_Tokenizer::sqlExplode($str); + $this->assertEqual($a, array("something", "(( ))")); + } +}