1
0
mirror of synced 2025-01-18 06:21:40 +03:00
This commit is contained in:
zYne 2007-06-19 10:09:48 +00:00
parent 3736c71a2c
commit 7aa35b7b8e
2 changed files with 53 additions and 1189 deletions

View File

@ -30,8 +30,11 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase { class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase
public function testWordLikeParserSupportsHyphens() { {
public function testWordLikeParserSupportsHyphens()
{
$parser = new Doctrine_Hook_WordLike(); $parser = new Doctrine_Hook_WordLike();
$parser->parse('u', 'name', "'some guy' OR zYne"); $parser->parse('u', 'name', "'some guy' OR zYne");
@ -40,7 +43,8 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($parser->getParams(), array('some guy%', 'zYne%')); $this->assertEqual($parser->getParams(), array('some guy%', 'zYne%'));
} }
public function testHookOrderbyAcceptsArray() { public function testHookOrderbyAcceptsArray()
{
$hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$a['orderby'] = array('u.name ASC'); $a['orderby'] = array('u.name ASC');
@ -48,7 +52,9 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$hook->hookOrderBy($a['orderby']); $hook->hookOrderBy($a['orderby']);
$this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) ORDER BY e.name ASC'); $this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) ORDER BY e.name ASC');
} }
public function testHookOrderbyAcceptsDescendingOrder() {
public function testHookOrderbyAcceptsDescendingOrder()
{
$hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$a['orderby'] = array('u.name DESC'); $a['orderby'] = array('u.name DESC');
@ -56,7 +62,9 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$hook->hookOrderBy($a['orderby']); $hook->hookOrderBy($a['orderby']);
$this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) ORDER BY e.name DESC'); $this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) ORDER BY e.name DESC');
} }
public function testHookOrderbyDoesntAcceptUnknownColumn() {
public function testHookOrderbyDoesntAcceptUnknownColumn()
{
$hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$a['orderby'] = array('u.unknown DESC'); $a['orderby'] = array('u.unknown DESC');
@ -64,7 +72,9 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$hook->hookOrderBy($a['orderby']); $hook->hookOrderBy($a['orderby']);
$this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)'); $this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)');
} }
public function testHookOrderbyAcceptsMultipleParameters() {
public function testHookOrderbyAcceptsMultipleParameters()
{
$hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$a['orderby'] = array('u.name ASC', 'u.id DESC'); $a['orderby'] = array('u.name ASC', 'u.id DESC');
@ -74,7 +84,9 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$users = $hook->getQuery()->execute(); $users = $hook->getQuery()->execute();
} }
public function testHookWhereAcceptsArrays() {
public function testHookWhereAcceptsArrays()
{
$hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$a['where'] = array('u.name' => 'Jack Daniels', $a['where'] = array('u.name' => 'Jack Daniels',
@ -84,7 +96,9 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.name LIKE ? OR e.name LIKE ?) AND e.loginname LIKE ? AND (e.type = 0)'); $this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.name LIKE ? OR e.name LIKE ?) AND e.loginname LIKE ? AND (e.type = 0)');
$this->assertEqual($hook->getQuery()->getParams(), array('Jack%', 'Daniels%', 'TheMan%')); $this->assertEqual($hook->getQuery()->getParams(), array('Jack%', 'Daniels%', 'TheMan%'));
} }
public function testHookWhereSupportsIntegerTypes() {
public function testHookWhereSupportsIntegerTypes()
{
$hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$a['where'] = array('u.id' => 10000); $a['where'] = array('u.id' => 10000);
@ -94,7 +108,8 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($hook->getQuery()->getParams(), array(10000)); $this->assertEqual($hook->getQuery()->getParams(), array(10000));
} }
public function testHookWhereDoesntAcceptUnknownColumn() { public function testHookWhereDoesntAcceptUnknownColumn()
{
$hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$a['where'] = array('u.unknown' => 'Jack Daniels'); $a['where'] = array('u.unknown' => 'Jack Daniels');
@ -104,7 +119,8 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
} }
public function testEqualParserUsesEqualOperator() { public function testEqualParserUsesEqualOperator()
{
$parser = new Doctrine_Hook_Equal(); $parser = new Doctrine_Hook_Equal();
$parser->parse('u', 'name', 'zYne'); $parser->parse('u', 'name', 'zYne');
@ -112,7 +128,9 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($parser->getCondition(), 'u.name = ?'); $this->assertEqual($parser->getCondition(), 'u.name = ?');
$this->assertEqual($parser->getParams(), array('zYne')); $this->assertEqual($parser->getParams(), array('zYne'));
} }
public function testWordLikeParserUsesLikeOperator() {
public function testWordLikeParserUsesLikeOperator()
{
$parser = new Doctrine_Hook_WordLike(); $parser = new Doctrine_Hook_WordLike();
$parser->parse('u', 'name', 'zYne'); $parser->parse('u', 'name', 'zYne');
@ -120,7 +138,9 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($parser->getCondition(), 'u.name LIKE ?'); $this->assertEqual($parser->getCondition(), 'u.name LIKE ?');
$this->assertEqual($parser->getParams(), array('zYne%')); $this->assertEqual($parser->getParams(), array('zYne%'));
} }
public function testIntegerParserSupportsIntervals() {
public function testIntegerParserSupportsIntervals()
{
$parser = new Doctrine_Hook_Integer(); $parser = new Doctrine_Hook_Integer();
$parser->parse('m', 'year', '1998-2000'); $parser->parse('m', 'year', '1998-2000');
@ -129,7 +149,8 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($parser->getParams(), array('1998', '2000')); $this->assertEqual($parser->getParams(), array('1998', '2000'));
} }
public function testIntegerParserSupportsEqualOperator() { public function testIntegerParserSupportsEqualOperator()
{
$parser = new Doctrine_Hook_Integer(); $parser = new Doctrine_Hook_Integer();
$parser->parse('m', 'year', '1998'); $parser->parse('m', 'year', '1998');
@ -138,7 +159,8 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($parser->getParams(), array('1998')); $this->assertEqual($parser->getParams(), array('1998'));
} }
public function testIntegerParserSupportsNestingConditions() { public function testIntegerParserSupportsNestingConditions()
{
$parser = new Doctrine_Hook_Integer(); $parser = new Doctrine_Hook_Integer();
$parser->parse('m', 'year', '1998-2000 OR 2001'); $parser->parse('m', 'year', '1998-2000 OR 2001');

File diff suppressed because it is too large Load Diff