CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.
This commit is contained in:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
|
@ -0,0 +1,385 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/BaseTestCase.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/query/Criteria.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/util/BasePeer.php';
|
||||
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "fixtures/bookstore/build/classes");
|
||||
Propel::init('fixtures/bookstore/build/conf/bookstore-conf.php');
|
||||
|
||||
/**
|
||||
* Test class for Criteria combinations.
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @version $Id: CriteriaCombineTest.php 1773 2010-05-25 10:25:06Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class CriteriaCombineTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* The criteria to use in the test.
|
||||
* @var Criteria
|
||||
*/
|
||||
private $c;
|
||||
|
||||
/**
|
||||
* DB adapter saved for later.
|
||||
*
|
||||
* @var DBAdapter
|
||||
*/
|
||||
private $savedAdapter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->c = new Criteria();
|
||||
$this->savedAdapter = Propel::getDB(null);
|
||||
Propel::setDB(null, new DBSQLite());
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Propel::setDB(null, $this->savedAdapter);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* test various properties of Criterion and nested criterion
|
||||
*/
|
||||
public function testNestedCriterion()
|
||||
{
|
||||
$table2 = "myTable2";
|
||||
$column2 = "myColumn2";
|
||||
$value2 = "myValue2";
|
||||
$key2 = "$table2.$column2";
|
||||
|
||||
$table3 = "myTable3";
|
||||
$column3 = "myColumn3";
|
||||
$value3 = "myValue3";
|
||||
$key3 = "$table3.$column3";
|
||||
|
||||
$table4 = "myTable4";
|
||||
$column4 = "myColumn4";
|
||||
$value4 = "myValue4";
|
||||
$key4 = "$table4.$column4";
|
||||
|
||||
$table5 = "myTable5";
|
||||
$column5 = "myColumn5";
|
||||
$value5 = "myValue5";
|
||||
$key5 = "$table5.$column5";
|
||||
|
||||
$crit2 = $this->c->getNewCriterion($key2, $value2, Criteria::EQUAL);
|
||||
$crit3 = $this->c->getNewCriterion($key3, $value3, Criteria::EQUAL);
|
||||
$crit4 = $this->c->getNewCriterion($key4, $value4, Criteria::EQUAL);
|
||||
$crit5 = $this->c->getNewCriterion($key5, $value5, Criteria::EQUAL);
|
||||
|
||||
$crit2->addAnd($crit3)->addOr($crit4->addAnd($crit5));
|
||||
$expect = "((myTable2.myColumn2=:p1 AND myTable3.myColumn3=:p2) "
|
||||
. "OR (myTable4.myColumn4=:p3 AND myTable5.myColumn5=:p4))";
|
||||
|
||||
$sb = "";
|
||||
$params = array();
|
||||
$crit2->appendPsTo($sb, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable2', 'column' => 'myColumn2', 'value' => 'myValue2'),
|
||||
array('table' => 'myTable3', 'column' => 'myColumn3', 'value' => 'myValue3'),
|
||||
array('table' => 'myTable4', 'column' => 'myColumn4', 'value' => 'myValue4'),
|
||||
array('table' => 'myTable5', 'column' => 'myColumn5', 'value' => 'myValue5'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $sb);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
|
||||
$crit6 = $this->c->getNewCriterion($key2, $value2, Criteria::EQUAL);
|
||||
$crit7 = $this->c->getNewCriterion($key3, $value3, Criteria::EQUAL);
|
||||
$crit8 = $this->c->getNewCriterion($key4, $value4, Criteria::EQUAL);
|
||||
$crit9 = $this->c->getNewCriterion($key5, $value5, Criteria::EQUAL);
|
||||
|
||||
$crit6->addAnd($crit7)->addOr($crit8)->addAnd($crit9);
|
||||
$expect = "(((myTable2.myColumn2=:p1 AND myTable3.myColumn3=:p2) "
|
||||
. "OR myTable4.myColumn4=:p3) AND myTable5.myColumn5=:p4)";
|
||||
|
||||
$sb = "";
|
||||
$params = array();
|
||||
$crit6->appendPsTo($sb, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable2', 'column' => 'myColumn2', 'value' => 'myValue2'),
|
||||
array('table' => 'myTable3', 'column' => 'myColumn3', 'value' => 'myValue3'),
|
||||
array('table' => 'myTable4', 'column' => 'myColumn4', 'value' => 'myValue4'),
|
||||
array('table' => 'myTable5', 'column' => 'myColumn5', 'value' => 'myValue5'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $sb);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
|
||||
// should make sure we have tests for all possibilities
|
||||
|
||||
$crita = $crit2->getAttachedCriterion();
|
||||
|
||||
$this->assertEquals($crit2, $crita[0]);
|
||||
$this->assertEquals($crit3, $crita[1]);
|
||||
$this->assertEquals($crit4, $crita[2]);
|
||||
$this->assertEquals($crit5, $crita[3]);
|
||||
|
||||
$tables = $crit2->getAllTables();
|
||||
|
||||
$this->assertEquals($crit2->getTable(), $tables[0]);
|
||||
$this->assertEquals($crit3->getTable(), $tables[1]);
|
||||
$this->assertEquals($crit4->getTable(), $tables[2]);
|
||||
$this->assertEquals($crit5->getTable(), $tables[3]);
|
||||
|
||||
// simple confirmations that equality operations work
|
||||
$this->assertTrue($crit2->hashCode() === $crit2->hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests <= and >=.
|
||||
*/
|
||||
public function testBetweenCriterion()
|
||||
{
|
||||
$cn1 = $this->c->getNewCriterion("INVOICE.COST", 1000, Criteria::GREATER_EQUAL);
|
||||
$cn2 = $this->c->getNewCriterion("INVOICE.COST", 5000, Criteria::LESS_EQUAL);
|
||||
$this->c->add($cn1->addAnd($cn2));
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE (INVOICE.COST>=:p1 AND INVOICE.COST<=:p2)";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => 1000),
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => 5000),
|
||||
);
|
||||
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
} catch (PropelException $e) {
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ".$e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that AND and OR criterion are nested correctly.
|
||||
*/
|
||||
public function testPrecedence()
|
||||
{
|
||||
$cn1 = $this->c->getNewCriterion("INVOICE.COST", "1000", Criteria::GREATER_EQUAL);
|
||||
$cn2 = $this->c->getNewCriterion("INVOICE.COST", "2000", Criteria::LESS_EQUAL);
|
||||
$cn3 = $this->c->getNewCriterion("INVOICE.COST", "8000", Criteria::GREATER_EQUAL);
|
||||
$cn4 = $this->c->getNewCriterion("INVOICE.COST", "9000", Criteria::LESS_EQUAL);
|
||||
$this->c->add($cn1->addAnd($cn2));
|
||||
$this->c->addOr($cn3->addAnd($cn4));
|
||||
|
||||
$expect =
|
||||
"SELECT FROM INVOICE WHERE ((INVOICE.COST>=:p1 AND INVOICE.COST<=:p2) OR (INVOICE.COST>=:p3 AND INVOICE.COST<=:p4))";
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '2000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '8000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '9000'),
|
||||
);
|
||||
|
||||
try {
|
||||
$params=array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
} catch (PropelException $e) {
|
||||
$this->fail("PropelException thrown in BasePeer::createSelectSql()");
|
||||
}
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineCriterionAndSimple()
|
||||
{
|
||||
$this->c->addCond('cond1', "INVOICE.COST", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2'), Criteria::LOGICAL_AND);
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE (INVOICE.COST>=:p1 AND INVOICE.COST<=:p2)";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '2000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineCriterionAndLessSimple()
|
||||
{
|
||||
$this->c->addCond('cond1', "INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->add("INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2'), Criteria::LOGICAL_AND);
|
||||
$this->c->add("INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE INVOICE.COST3>=:p1 AND (INVOICE.COST1>=:p2 AND INVOICE.COST2<=:p3) AND INVOICE.COST4<=:p4";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineCriterionAndMultiple()
|
||||
{
|
||||
$this->c->addCond('cond1',"INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->addCond('cond3', "INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond4', "INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2', 'cond3', 'cond4'), Criteria::LOGICAL_AND);
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE (((INVOICE.COST1>=:p1 AND INVOICE.COST2<=:p2) AND INVOICE.COST3>=:p3) AND INVOICE.COST4<=:p4)";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineCriterionOrSimple()
|
||||
{
|
||||
$this->c->addCond('cond1', "INVOICE.COST", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2'), Criteria::LOGICAL_OR);
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE (INVOICE.COST>=:p1 OR INVOICE.COST<=:p2)";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST', 'value' => '2000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineCriterionOrLessSimple()
|
||||
{
|
||||
$this->c->addCond('cond1', "INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->add("INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2'), Criteria::LOGICAL_OR);
|
||||
$this->c->addOr("INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE INVOICE.COST3>=:p1 AND ((INVOICE.COST1>=:p2 OR INVOICE.COST2<=:p3) OR INVOICE.COST4<=:p4)";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineCriterionOrMultiple()
|
||||
{
|
||||
$this->c->addCond('cond1',"INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->addCond('cond3', "INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond4', "INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2', 'cond3', 'cond4'), Criteria::LOGICAL_OR);
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE (((INVOICE.COST1>=:p1 OR INVOICE.COST2<=:p2) OR INVOICE.COST3>=:p3) OR INVOICE.COST4<=:p4)";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineNamedCriterions()
|
||||
{
|
||||
$this->c->addCond('cond1', "INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2'), Criteria::LOGICAL_AND, 'cond12');
|
||||
$this->c->addCond('cond3', "INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond4', "INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond3', 'cond4'), Criteria::LOGICAL_AND, 'cond34');
|
||||
$this->c->combine(array('cond12', 'cond34'), Criteria::LOGICAL_OR);
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE ((INVOICE.COST1>=:p1 AND INVOICE.COST2<=:p2) OR (INVOICE.COST3>=:p3 AND INVOICE.COST4<=:p4))";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
public function testCombineDirtyOperators()
|
||||
{
|
||||
$this->c->addCond('cond1', "INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond1', 'cond2'), 'AnD', 'cond12');
|
||||
$this->c->addCond('cond3', "INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
|
||||
$this->c->addCond('cond4', "INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
|
||||
$this->c->combine(array('cond3', 'cond4'), 'aNd', 'cond34');
|
||||
$this->c->combine(array('cond12', 'cond34'), 'oR');
|
||||
|
||||
$expect = "SELECT FROM INVOICE WHERE ((INVOICE.COST1>=:p1 AND INVOICE.COST2<=:p2) OR (INVOICE.COST3>=:p3 AND INVOICE.COST4<=:p4))";
|
||||
$expect_params = array(
|
||||
array('table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'),
|
||||
array('table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000'),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($expect_params, $params);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/BaseTestCase.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/query/Criteria.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/util/PropelConditionalProxy.php';
|
||||
|
||||
/**
|
||||
* Test class for Criteria fluid conditions.
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @version $Id: CriteriaCombineTest.php 1347 2009-12-03 21:06:36Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class CriteriaFluidConditionTest extends BaseTestCase
|
||||
{
|
||||
public function testIf()
|
||||
{
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(true)->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertTrue($f->getTest(), '_if() executes the next method if the test is true');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
foo()->
|
||||
_endif();
|
||||
$this->assertFalse($f->getTest(), '_if() does not check the existence of the next method if the test is false');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(true)->
|
||||
dummy()->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertTrue($f->getTest(), '_if() executes the next methods until _endif() if the test is true');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
dummy()->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertFalse($f->getTest(), '_if() does not execute the next methods until _endif() if the test is false');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PropelException
|
||||
*/
|
||||
public function testNestedIf()
|
||||
{
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
_if(true)->
|
||||
test()->
|
||||
_endif();
|
||||
}
|
||||
|
||||
public function testElseIf()
|
||||
{
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(true)->
|
||||
_elseif(true)->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertFalse($f->getTest(), '_elseif() does not execute the next method if the main test is true');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(true)->
|
||||
_elseif(false)->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertFalse($f->getTest(), '_elseif() does not execute the next method if the main test is true');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
_elseif(true)->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertTrue($f->getTest(), '_elseif() executes the next method if the main test is false and the elseif test is true');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
_elseif(false)->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertFalse($f->getTest(), '_elseif() does not execute the next method if the main test is false and the elseif test is false');
|
||||
}
|
||||
|
||||
public function testElse()
|
||||
{
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(true)->
|
||||
_else()->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertFalse($f->getTest(), '_else() does not execute the next method if the main test is true');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
_else()->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertTrue($f->getTest(), '_else() executes the next method if the main test is false');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
_elseif(true)->
|
||||
_else()->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertFalse($f->getTest(), '_else() does not execute the next method if the previous test is true');
|
||||
$f->
|
||||
_if(false)->
|
||||
_elseif(false)->
|
||||
_else()->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertTrue($f->getTest(), '_else() executes the next method if all the previous tests are false');
|
||||
}
|
||||
|
||||
public function testEndif()
|
||||
{
|
||||
$f = new TestableCriteria();
|
||||
$res = $f->
|
||||
_if(true)->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertEquals($res, $f, '_endif() returns the main object if the test is true');
|
||||
$f = new TestableCriteria();
|
||||
$res = $f->
|
||||
_if(false)->
|
||||
test()->
|
||||
_endif();
|
||||
$this->assertEquals($res, $f, '_endif() returns the main object if the test is false');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(true)->
|
||||
_endif()->
|
||||
test();
|
||||
$this->assertTrue($f->getTest(), '_endif() stops the condition check');
|
||||
$f = new TestableCriteria();
|
||||
$f->
|
||||
_if(false)->
|
||||
_endif()->
|
||||
test();
|
||||
$this->assertTrue($f->getTest(), '_endif() stops the condition check');
|
||||
}
|
||||
}
|
||||
|
||||
class TestableCriteria extends Criteria
|
||||
{
|
||||
protected $test = false;
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->test = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dummy()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,399 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/BaseTestCase.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/query/Criteria.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/util/BasePeer.php';
|
||||
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "fixtures/bookstore/build/classes");
|
||||
Propel::init('fixtures/bookstore/build/conf/bookstore-conf.php');
|
||||
|
||||
/**
|
||||
* Test class for Criteria.
|
||||
*
|
||||
* @author <a href="mailto:celkins@scardini.com">Christopher Elkins</a>
|
||||
* @author <a href="mailto:sam@neurogrid.com">Sam Joseph</a>
|
||||
* @version $Id: CriteriaTest.php 1347 2009-12-03 21:06:36Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class CriteriaMergeTest extends BaseTestCase
|
||||
{
|
||||
|
||||
protected function assertCriteriaTranslation($criteria, $expectedSql, $message = '')
|
||||
{
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($criteria, $params);
|
||||
$this->assertEquals($expectedSql, $result, $message);
|
||||
}
|
||||
|
||||
public function testMergeWithLimit()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->setLimit(123);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(123, $c1->getLimit(), 'mergeWith() does not remove an existing limit');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->setLimit(123);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(123, $c1->getLimit(), 'mergeWith() merges the limit');
|
||||
$c1 = new Criteria();
|
||||
$c1->setLimit(456);
|
||||
$c2 = new Criteria();
|
||||
$c2->setLimit(123);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(456, $c1->getLimit(), 'mergeWith() does not merge the limit in case of conflict');
|
||||
}
|
||||
|
||||
public function testMergeWithOffset()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->setOffset(123);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(123, $c1->getOffset(), 'mergeWith() does not remove an existing offset');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->setOffset(123);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(123, $c1->getOffset(), 'mergeWith() merges the offset');
|
||||
$c1 = new Criteria();
|
||||
$c1->setOffset(456);
|
||||
$c2 = new Criteria();
|
||||
$c2->setOffset(123);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(456, $c1->getOffset(), 'mergeWith() does not merge the offset in case of conflict');
|
||||
}
|
||||
|
||||
public function testMergeWithSelectModifiers()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->setDistinct();
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(Criteria::DISTINCT), $c1->getSelectModifiers(), 'mergeWith() does not remove an existing select modifier');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->setDistinct();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(Criteria::DISTINCT), $c1->getSelectModifiers(), 'mergeWith() merges the select modifiers');
|
||||
$c1 = new Criteria();
|
||||
$c1->setDistinct();
|
||||
$c2 = new Criteria();
|
||||
$c2->setDistinct();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(Criteria::DISTINCT), $c1->getSelectModifiers(), 'mergeWith() does not duplicate select modifiers');
|
||||
$c1 = new Criteria();
|
||||
$c1->setAll();
|
||||
$c2 = new Criteria();
|
||||
$c2->setDistinct();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(Criteria::ALL), $c1->getSelectModifiers(), 'mergeWith() does not merge the select modifiers in case of conflict');
|
||||
}
|
||||
|
||||
public function testMergeWithSelectColumns()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addSelectColumn(BookPeer::TITLE);
|
||||
$c1->addSelectColumn(BookPeer::ID);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getSelectColumns(), 'mergeWith() does not remove an existing select columns');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->addSelectColumn(BookPeer::TITLE);
|
||||
$c2->addSelectColumn(BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getSelectColumns(), 'mergeWith() merges the select columns to an empty select');
|
||||
$c1 = new Criteria();
|
||||
$c1->addSelectColumn(BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addSelectColumn(BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getSelectColumns(), 'mergeWith() merges the select columns after the existing select columns');
|
||||
$c1 = new Criteria();
|
||||
$c1->addSelectColumn(BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addSelectColumn(BookPeer::TITLE);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE, BookPeer::TITLE), $c1->getSelectColumns(), 'mergeWith() merges the select columns to an existing select, even if duplicated');
|
||||
}
|
||||
|
||||
public function testMergeWithAsColumns()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addAsColumn('foo', BookPeer::TITLE);
|
||||
$c1->addAsColumn('bar', BookPeer::ID);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array('foo' => BookPeer::TITLE, 'bar' => BookPeer::ID), $c1->getAsColumns(), 'mergeWith() does not remove an existing as columns');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->addAsColumn('foo', BookPeer::TITLE);
|
||||
$c2->addAsColumn('bar', BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array('foo' => BookPeer::TITLE, 'bar' => BookPeer::ID), $c1->getAsColumns(), 'mergeWith() merges the select columns to an empty as');
|
||||
$c1 = new Criteria();
|
||||
$c1->addAsColumn('foo', BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addAsColumn('bar', BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array('foo' => BookPeer::TITLE, 'bar' => BookPeer::ID), $c1->getAsColumns(), 'mergeWith() merges the select columns after the existing as columns');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PropelException
|
||||
*/
|
||||
public function testMergeWithAsColumnsThrowsException()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addAsColumn('foo', BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addAsColumn('foo', BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
}
|
||||
|
||||
public function testMergeWithOrderByColumns()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addAscendingOrderByColumn(BookPeer::TITLE);
|
||||
$c1->addAscendingOrderByColumn(BookPeer::ID);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE . ' ASC', BookPeer::ID . ' ASC'), $c1->getOrderByColumns(), 'mergeWith() does not remove an existing orderby columns');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->addAscendingOrderByColumn(BookPeer::TITLE);
|
||||
$c2->addAscendingOrderByColumn(BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE . ' ASC', BookPeer::ID . ' ASC'), $c1->getOrderByColumns(), 'mergeWith() merges the select columns to an empty order by');
|
||||
$c1 = new Criteria();
|
||||
$c1->addAscendingOrderByColumn(BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addAscendingOrderByColumn(BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE . ' ASC', BookPeer::ID . ' ASC'), $c1->getOrderByColumns(), 'mergeWith() merges the select columns after the existing orderby columns');
|
||||
$c1 = new Criteria();
|
||||
$c1->addAscendingOrderByColumn(BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addAscendingOrderByColumn(BookPeer::TITLE);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE . ' ASC'), $c1->getOrderByColumns(), 'mergeWith() does not merge duplicated orderby columns');
|
||||
$c1 = new Criteria();
|
||||
$c1->addAscendingOrderByColumn(BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addDescendingOrderByColumn(BookPeer::TITLE);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE . ' ASC', BookPeer::TITLE . ' DESC'), $c1->getOrderByColumns(), 'mergeWith() merges duplicated orderby columns with inverse direction');
|
||||
}
|
||||
|
||||
public function testMergeWithGroupByColumns()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addGroupByColumn(BookPeer::TITLE);
|
||||
$c1->addGroupByColumn(BookPeer::ID);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getGroupByColumns(), 'mergeWith() does not remove an existing groupby columns');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->addGroupByColumn(BookPeer::TITLE);
|
||||
$c2->addGroupByColumn(BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getGroupByColumns(), 'mergeWith() merges the select columns to an empty groupby');
|
||||
$c1 = new Criteria();
|
||||
$c1->addGroupByColumn(BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addGroupByColumn(BookPeer::ID);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getGroupByColumns(), 'mergeWith() merges the select columns after the existing groupby columns');
|
||||
$c1 = new Criteria();
|
||||
$c1->addGroupByColumn(BookPeer::TITLE);
|
||||
$c2 = new Criteria();
|
||||
$c2->addGroupByColumn(BookPeer::TITLE);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array(BookPeer::TITLE), $c1->getGroupByColumns(), 'mergeWith() does not merge duplicated groupby columns');
|
||||
}
|
||||
|
||||
public function testMergeWithWhereConditions()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::TITLE, 'foo');
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM `book` WHERE book.TITLE=:p1';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() does not remove an existing where condition');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->add(BookPeer::TITLE, 'foo');
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM `book` WHERE book.TITLE=:p1';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to an empty condition');
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::ID, 123);
|
||||
$c2 = new Criteria();
|
||||
$c2->add(BookPeer::TITLE, 'foo');
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM `book` WHERE book.ID=:p1 AND book.TITLE=:p2';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions');
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::TITLE, 'foo');
|
||||
$c2 = new Criteria();
|
||||
$c2->add(BookPeer::TITLE, 'bar');
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM `book` WHERE (book.TITLE=:p1 AND book.TITLE=:p2)';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions on the same column');
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::TITLE, 'foo');
|
||||
$c1->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
|
||||
$c2 = new Criteria();
|
||||
$c2->add(AuthorPeer::FIRST_NAME, 'bar');
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM `book` LEFT JOIN author ON (book.AUTHOR_ID=author.ID) WHERE book.TITLE=:p1 AND author.FIRST_NAME=:p2';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions on the different tables');
|
||||
}
|
||||
|
||||
public function testMergeOrWithWhereConditions()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::TITLE, 'foo');
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2, Criteria::LOGICAL_OR);
|
||||
$sql = 'SELECT FROM `book` WHERE book.TITLE=:p1';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() does not remove an existing where condition');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->add(BookPeer::TITLE, 'foo');
|
||||
$c1->mergeWith($c2, Criteria::LOGICAL_OR);
|
||||
$sql = 'SELECT FROM `book` WHERE book.TITLE=:p1';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to an empty condition');
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::ID, 123);
|
||||
$c2 = new Criteria();
|
||||
$c2->add(BookPeer::TITLE, 'foo');
|
||||
$c1->mergeWith($c2, Criteria::LOGICAL_OR);
|
||||
$sql = 'SELECT FROM `book` WHERE (book.ID=:p1 OR book.TITLE=:p2)';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions');
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::TITLE, 'foo');
|
||||
$c2 = new Criteria();
|
||||
$c2->add(BookPeer::TITLE, 'bar');
|
||||
$c1->mergeWith($c2, Criteria::LOGICAL_OR);
|
||||
$sql = 'SELECT FROM `book` WHERE (book.TITLE=:p1 OR book.TITLE=:p2)';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions on the same column');
|
||||
$c1 = new Criteria();
|
||||
$c1->add(BookPeer::TITLE, 'foo');
|
||||
$c1->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
|
||||
$c2 = new Criteria();
|
||||
$c2->add(AuthorPeer::FIRST_NAME, 'bar');
|
||||
$c1->mergeWith($c2, Criteria::LOGICAL_OR);
|
||||
$sql = 'SELECT FROM `book` LEFT JOIN author ON (book.AUTHOR_ID=author.ID) WHERE (book.TITLE=:p1 OR author.FIRST_NAME=:p2)';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions on the different tables');
|
||||
}
|
||||
|
||||
public function testMergeWithHavingConditions()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$cton = $c1->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
|
||||
$c1->addHaving($cton);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM HAVING book.TITLE=:p1';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() does not remove an existing having condition');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$cton = $c2->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
|
||||
$c2->addHaving($cton);
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM HAVING book.TITLE=:p1';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges having condition to an empty having');
|
||||
$c1 = new Criteria();
|
||||
$cton = $c1->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
|
||||
$c1->addHaving($cton);
|
||||
$c2 = new Criteria();
|
||||
$cton = $c2->getNewCriterion(BookPeer::TITLE, 'bar', Criteria::EQUAL);
|
||||
$c2->addHaving($cton);
|
||||
$c1->mergeWith($c2);
|
||||
$sql = 'SELECT FROM HAVING (book.TITLE=:p1 AND book.TITLE=:p2)';
|
||||
$this->assertCriteriaTranslation($c1, $sql, 'mergeWith() combines having with AND');
|
||||
}
|
||||
|
||||
public function testMergeWithAliases()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addAlias('b', BookPeer::TABLE_NAME);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array('b' => BookPeer::TABLE_NAME), $c1->getAliases(), 'mergeWith() does not remove an existing alias');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->addAlias('a', AuthorPeer::TABLE_NAME);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array('a' => AuthorPeer::TABLE_NAME), $c1->getAliases(), 'mergeWith() merge aliases to an empty alias');
|
||||
$c1 = new Criteria();
|
||||
$c1->addAlias('b', BookPeer::TABLE_NAME);
|
||||
$c2 = new Criteria();
|
||||
$c2->addAlias('a', AuthorPeer::TABLE_NAME);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(array('b' => BookPeer::TABLE_NAME, 'a' => AuthorPeer::TABLE_NAME), $c1->getAliases(), 'mergeWith() merge aliases to an existing alias');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PropelException
|
||||
*/
|
||||
public function testMergeWithAliasesThrowsException()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addAlias('b', BookPeer::TABLE_NAME);
|
||||
$c2 = new Criteria();
|
||||
$c2->addAlias('b', AuthorPeer::TABLE_NAME);
|
||||
$c1->mergeWith($c2);
|
||||
}
|
||||
|
||||
public function testMergeWithJoins()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
|
||||
$c2 = new Criteria();
|
||||
$c1->mergeWith($c2);
|
||||
$joins = $c1->getJoins();
|
||||
$this->assertEquals(1, count($joins), 'mergeWith() does not remove an existing join');
|
||||
$this->assertEquals('LEFT JOIN : book.AUTHOR_ID=author.ID(ignoreCase not considered)', $joins[0]->toString(), 'mergeWith() does not remove an existing join');
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
|
||||
$c1->mergeWith($c2);
|
||||
$joins = $c1->getJoins();
|
||||
$this->assertEquals(1, count($joins), 'mergeWith() merge joins to an empty join');
|
||||
$this->assertEquals('LEFT JOIN : book.AUTHOR_ID=author.ID(ignoreCase not considered)', $joins[0]->toString(), 'mergeWith() merge joins to an empty join');
|
||||
$c1 = new Criteria();
|
||||
$c1->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
|
||||
$c2 = new Criteria();
|
||||
$c2->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::INNER_JOIN);
|
||||
$c1->mergeWith($c2);
|
||||
$joins = $c1->getJoins();
|
||||
$this->assertEquals(2, count($joins), 'mergeWith() merge joins to an existing join');
|
||||
$this->assertEquals('LEFT JOIN : book.AUTHOR_ID=author.ID(ignoreCase not considered)', $joins[0]->toString(), 'mergeWith() merge joins to an empty join');
|
||||
$this->assertEquals('INNER JOIN : book.PUBLISHER_ID=publisher.ID(ignoreCase not considered)', $joins[1]->toString(), 'mergeWith() merge joins to an empty join');
|
||||
}
|
||||
|
||||
public function testMergeWithFurtherModified()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c2 = new Criteria();
|
||||
$c2->setLimit(123);
|
||||
$c1->mergeWith($c2);
|
||||
$this->assertEquals(123, $c1->getLimit(), 'mergeWith() makes the merge');
|
||||
$c2->setLimit(456);
|
||||
$this->assertEquals(123, $c1->getLimit(), 'further modifying a merged criteria does not affect the merger');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,974 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/BaseTestCase.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/query/Criteria.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/util/BasePeer.php';
|
||||
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "fixtures/bookstore/build/classes");
|
||||
Propel::init('fixtures/bookstore/build/conf/bookstore-conf.php');
|
||||
|
||||
/**
|
||||
* Test class for Criteria.
|
||||
*
|
||||
* @author <a href="mailto:celkins@scardini.com">Christopher Elkins</a>
|
||||
* @author <a href="mailto:sam@neurogrid.com">Sam Joseph</a>
|
||||
* @version $Id: CriteriaTest.php 1773 2010-05-25 10:25:06Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class CriteriaTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* The criteria to use in the test.
|
||||
* @var Criteria
|
||||
*/
|
||||
private $c;
|
||||
|
||||
/**
|
||||
* DB adapter saved for later.
|
||||
*
|
||||
* @var DBAdapter
|
||||
*/
|
||||
private $savedAdapter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->c = new Criteria();
|
||||
$this->savedAdapter = Propel::getDB(null);
|
||||
Propel::setDB(null, new DBSQLite());
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Propel::setDB(null, $this->savedAdapter);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic adding of strings.
|
||||
*/
|
||||
public function testAddString()
|
||||
{
|
||||
$table = "myTable";
|
||||
$column = "myColumn";
|
||||
$value = "myValue";
|
||||
|
||||
// Add the string
|
||||
$this->c->add($table . '.' . $column, $value);
|
||||
|
||||
// Verify that the key exists
|
||||
$this->assertTrue($this->c->containsKey($table . '.' . $column));
|
||||
|
||||
// Verify that what we get out is what we put in
|
||||
$this->assertTrue($this->c->getValue($table . '.' . $column) === $value);
|
||||
}
|
||||
|
||||
public function testAddAndSameColumns()
|
||||
{
|
||||
$table1 = "myTable1";
|
||||
$column1 = "myColumn1";
|
||||
$value1 = "myValue1";
|
||||
$key1 = "$table1.$column1";
|
||||
|
||||
$table2 = "myTable1";
|
||||
$column2 = "myColumn1";
|
||||
$value2 = "myValue2";
|
||||
$key2 = "$table2.$column2";
|
||||
|
||||
$this->c->add($key1, $value1, Criteria::EQUAL);
|
||||
$this->c->addAnd($key2, $value2, Criteria::EQUAL);
|
||||
|
||||
$expect = "SELECT FROM myTable1 WHERE (myTable1.myColumn1=:p1 AND myTable1.myColumn1=:p2)";
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'),
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue2'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $result, 'addAnd() called on an existing column creates a combined criterion');
|
||||
$this->assertEquals($expect_params, $params, 'addAnd() called on an existing column creates a combined criterion');
|
||||
}
|
||||
|
||||
public function testAddAndSameColumnsPropel14Compatibility()
|
||||
{
|
||||
$table1 = "myTable1";
|
||||
$column1 = "myColumn1";
|
||||
$value1 = "myValue1";
|
||||
$key1 = "$table1.$column1";
|
||||
|
||||
$table2 = "myTable1";
|
||||
$column2 = "myColumn1";
|
||||
$value2 = "myValue2";
|
||||
$key2 = "$table2.$column2";
|
||||
|
||||
$table3 = "myTable3";
|
||||
$column3 = "myColumn3";
|
||||
$value3 = "myValue3";
|
||||
$key3 = "$table3.$column3";
|
||||
|
||||
$this->c->add($key1, $value1, Criteria::EQUAL);
|
||||
$this->c->add($key3, $value3, Criteria::EQUAL);
|
||||
$this->c->addAnd($key2, $value2, Criteria::EQUAL);
|
||||
|
||||
$expect = "SELECT FROM myTable1, myTable3 WHERE (myTable1.myColumn1=:p1 AND myTable1.myColumn1=:p2) AND myTable3.myColumn3=:p3";
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'),
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue2'),
|
||||
array('table' => 'myTable3', 'column' => 'myColumn3', 'value' => 'myValue3'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $result, 'addAnd() called on an existing column creates a combined criterion');
|
||||
$this->assertEquals($expect_params, $params, 'addAnd() called on an existing column creates a combined criterion');
|
||||
}
|
||||
|
||||
public function testAddAndDistinctColumns()
|
||||
{
|
||||
$table1 = "myTable1";
|
||||
$column1 = "myColumn1";
|
||||
$value1 = "myValue1";
|
||||
$key1 = "$table1.$column1";
|
||||
|
||||
$table2 = "myTable2";
|
||||
$column2 = "myColumn2";
|
||||
$value2 = "myValue2";
|
||||
$key2 = "$table2.$column2";
|
||||
|
||||
$this->c->add($key1, $value1, Criteria::EQUAL);
|
||||
$this->c->addAnd($key2, $value2, Criteria::EQUAL);
|
||||
|
||||
$expect = "SELECT FROM myTable1, myTable2 WHERE myTable1.myColumn1=:p1 AND myTable2.myColumn2=:p2";
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'),
|
||||
array('table' => 'myTable2', 'column' => 'myColumn2', 'value' => 'myValue2'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $result, 'addAnd() called on a distinct column adds a criterion to the criteria');
|
||||
$this->assertEquals($expect_params, $params, 'addAnd() called on a distinct column adds a criterion to the criteria');
|
||||
}
|
||||
|
||||
public function testAddOrSameColumns()
|
||||
{
|
||||
$table1 = "myTable1";
|
||||
$column1 = "myColumn1";
|
||||
$value1 = "myValue1";
|
||||
$key1 = "$table1.$column1";
|
||||
|
||||
$table2 = "myTable1";
|
||||
$column2 = "myColumn1";
|
||||
$value2 = "myValue2";
|
||||
$key2 = "$table2.$column2";
|
||||
|
||||
$this->c->add($key1, $value1, Criteria::EQUAL);
|
||||
$this->c->addOr($key2, $value2, Criteria::EQUAL);
|
||||
|
||||
$expect = "SELECT FROM myTable1 WHERE (myTable1.myColumn1=:p1 OR myTable1.myColumn1=:p2)";
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'),
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue2'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $result, 'addOr() called on an existing column creates a combined criterion');
|
||||
$this->assertEquals($expect_params, $params, 'addOr() called on an existing column creates a combined criterion');
|
||||
}
|
||||
|
||||
public function testAddAndOrColumnsPropel14Compatibility()
|
||||
{
|
||||
$table1 = "myTable1";
|
||||
$column1 = "myColumn1";
|
||||
$value1 = "myValue1";
|
||||
$key1 = "$table1.$column1";
|
||||
|
||||
$table2 = "myTable1";
|
||||
$column2 = "myColumn1";
|
||||
$value2 = "myValue2";
|
||||
$key2 = "$table2.$column2";
|
||||
|
||||
$table3 = "myTable3";
|
||||
$column3 = "myColumn3";
|
||||
$value3 = "myValue3";
|
||||
$key3 = "$table3.$column3";
|
||||
|
||||
$this->c->add($key1, $value1, Criteria::EQUAL);
|
||||
$this->c->add($key3, $value3, Criteria::EQUAL);
|
||||
$this->c->addOr($key2, $value2, Criteria::EQUAL);
|
||||
|
||||
$expect = "SELECT FROM myTable1, myTable3 WHERE (myTable1.myColumn1=:p1 OR myTable1.myColumn1=:p2) AND myTable3.myColumn3=:p3";
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'),
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue2'),
|
||||
array('table' => 'myTable3', 'column' => 'myColumn3', 'value' => 'myValue3'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $result, 'addOr() called on an existing column creates a combined criterion');
|
||||
$this->assertEquals($expect_params, $params, 'addOr() called on an existing column creates a combined criterion');
|
||||
}
|
||||
|
||||
public function testAddOrDistinctColumns()
|
||||
{
|
||||
$table1 = "myTable1";
|
||||
$column1 = "myColumn1";
|
||||
$value1 = "myValue1";
|
||||
$key1 = "$table1.$column1";
|
||||
|
||||
$table2 = "myTable2";
|
||||
$column2 = "myColumn2";
|
||||
$value2 = "myValue2";
|
||||
$key2 = "$table2.$column2";
|
||||
|
||||
$this->c->add($key1, $value1, Criteria::EQUAL);
|
||||
$this->c->addOr($key2, $value2, Criteria::EQUAL);
|
||||
|
||||
$expect = "SELECT FROM myTable1, myTable2 WHERE (myTable1.myColumn1=:p1 OR myTable2.myColumn2=:p2)";
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'),
|
||||
array('table' => 'myTable2', 'column' => 'myColumn2', 'value' => 'myValue2'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $result, 'addOr() called on a distinct column adds a criterion to the latest criterion');
|
||||
$this->assertEquals($expect_params, $params, 'addOr() called on a distinct column adds a criterion to the latest criterion');
|
||||
}
|
||||
|
||||
public function testAddOrEmptyCriteria()
|
||||
{
|
||||
$table1 = "myTable1";
|
||||
$column1 = "myColumn1";
|
||||
$value1 = "myValue1";
|
||||
$key1 = "$table1.$column1";
|
||||
|
||||
$this->c->addOr($key1, $value1, Criteria::EQUAL);
|
||||
|
||||
$expect = "SELECT FROM myTable1 WHERE myTable1.myColumn1=:p1";
|
||||
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
|
||||
$expect_params = array(
|
||||
array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expect, $result, 'addOr() called on an empty Criteria adds a criterion to the criteria');
|
||||
$this->assertEquals($expect_params, $params, 'addOr() called on an empty Criteria adds a criterion to the criteria');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Criterion.setIgnoreCase().
|
||||
* As the output is db specific the test just prints the result to
|
||||
* System.out
|
||||
*/
|
||||
public function testCriterionIgnoreCase()
|
||||
{
|
||||
$originalDB = Propel::getDB();
|
||||
$adapters = array(new DBMySQL(), new DBPostgres());
|
||||
$expectedIgnore = array("UPPER(TABLE.COLUMN) LIKE UPPER(:p1)", "TABLE.COLUMN ILIKE :p1");
|
||||
|
||||
$i =0;
|
||||
foreach ($adapters as $adapter) {
|
||||
|
||||
Propel::setDB(null, $adapter);
|
||||
$myCriteria = new Criteria();
|
||||
|
||||
$myCriterion = $myCriteria->getNewCriterion(
|
||||
"TABLE.COLUMN", "FoObAr", Criteria::LIKE);
|
||||
$sb = "";
|
||||
$params=array();
|
||||
$myCriterion->appendPsTo($sb, $params);
|
||||
$expected = "TABLE.COLUMN LIKE :p1";
|
||||
|
||||
$this->assertEquals($expected, $sb);
|
||||
|
||||
$ignoreCriterion = $myCriterion->setIgnoreCase(true);
|
||||
|
||||
$sb = "";
|
||||
$params=array();
|
||||
$ignoreCriterion->appendPsTo($sb, $params);
|
||||
// $expected = "UPPER(TABLE.COLUMN) LIKE UPPER(?)";
|
||||
$this->assertEquals($expectedIgnore[$i], $sb);
|
||||
$i++;
|
||||
}
|
||||
Propel::setDB(null, $originalDB);
|
||||
}
|
||||
|
||||
public function testOrderByIgnoreCase()
|
||||
{
|
||||
$originalDB = Propel::getDB();
|
||||
Propel::setDB(null, new DBMySQL());
|
||||
|
||||
$criteria = new Criteria();
|
||||
$criteria->setIgnoreCase(true);
|
||||
$criteria->addAscendingOrderByColumn(BookPeer::TITLE);
|
||||
BookPeer::addSelectColumns($criteria);
|
||||
$params=array();
|
||||
$sql = BasePeer::createSelectSql($criteria, $params);
|
||||
$expectedSQL = 'SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, UPPER(book.TITLE) FROM `book` ORDER BY UPPER(book.TITLE) ASC';
|
||||
$this->assertEquals($expectedSQL, $sql);
|
||||
|
||||
Propel::setDB(null, $originalDB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that true is evaluated correctly.
|
||||
*/
|
||||
public function testBoolean()
|
||||
{
|
||||
$this->c = new Criteria();
|
||||
$this->c->add("TABLE.COLUMN", true);
|
||||
|
||||
$expect = "SELECT FROM TABLE WHERE TABLE.COLUMN=:p1";
|
||||
$expect_params = array( array('table' => 'TABLE', 'column' => 'COLUMN', 'value' => true),
|
||||
);
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
} catch (PropelException $e) {
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals($expect, $result, "Boolean test failed.");
|
||||
$this->assertEquals($expect_params, $params);
|
||||
|
||||
}
|
||||
|
||||
public function testCurrentDate()
|
||||
{
|
||||
$this->c = new Criteria();
|
||||
$this->c->add("TABLE.TIME_COLUMN", Criteria::CURRENT_TIME);
|
||||
$this->c->add("TABLE.DATE_COLUMN", Criteria::CURRENT_DATE);
|
||||
|
||||
$expect = "SELECT FROM TABLE WHERE TABLE.TIME_COLUMN=CURRENT_TIME AND TABLE.DATE_COLUMN=CURRENT_DATE";
|
||||
|
||||
$result = null;
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals($expect, $result, "Current date test failed!");
|
||||
|
||||
}
|
||||
|
||||
public function testCountAster()
|
||||
{
|
||||
$this->c = new Criteria();
|
||||
$this->c->addSelectColumn("COUNT(*)");
|
||||
$this->c->add("TABLE.TIME_COLUMN", Criteria::CURRENT_TIME);
|
||||
$this->c->add("TABLE.DATE_COLUMN", Criteria::CURRENT_DATE);
|
||||
|
||||
$expect = "SELECT COUNT(*) FROM TABLE WHERE TABLE.TIME_COLUMN=CURRENT_TIME AND TABLE.DATE_COLUMN=CURRENT_DATE";
|
||||
|
||||
$result = null;
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($this->c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals($expect, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testIn()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$c->add("TABLE.SOME_COLUMN", array(), Criteria::IN);
|
||||
$c->add("TABLE.OTHER_COLUMN", array(1, 2, 3), Criteria::IN);
|
||||
|
||||
$expect = "SELECT * FROM TABLE WHERE 1<>1 AND TABLE.OTHER_COLUMN IN (:p1,:p2,:p3)";
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testInEmptyAfterFull()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$c->add("TABLE.OTHER_COLUMN", array(1, 2, 3), Criteria::IN);
|
||||
$c->add("TABLE.SOME_COLUMN", array(), Criteria::IN);
|
||||
|
||||
$expect = "SELECT * FROM TABLE WHERE TABLE.OTHER_COLUMN IN (:p1,:p2,:p3) AND 1<>1";
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testInNested()
|
||||
{
|
||||
// now do a nested logic test, just for sanity (not that this should be any surprise)
|
||||
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$myCriterion = $c->getNewCriterion("TABLE.COLUMN", array(), Criteria::IN);
|
||||
$myCriterion->addOr($c->getNewCriterion("TABLE.COLUMN2", array(1,2), Criteria::IN));
|
||||
$c->add($myCriterion);
|
||||
|
||||
$expect = "SELECT * FROM TABLE WHERE (1<>1 OR TABLE.COLUMN2 IN (:p1,:p2))";
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testJoinObject ()
|
||||
{
|
||||
$j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_2');
|
||||
$this->assertEquals(null, $j->getJoinType());
|
||||
$this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn());
|
||||
$this->assertEquals('TABLE_A', $j->getLeftTableName());
|
||||
$this->assertEquals('COL_1', $j->getLeftColumnName());
|
||||
$this->assertEquals('TABLE_B.COL_2', $j->getRightColumn());
|
||||
$this->assertEquals('TABLE_B', $j->getRightTableName());
|
||||
$this->assertEquals('COL_2', $j->getRightColumnName());
|
||||
|
||||
$j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::LEFT_JOIN);
|
||||
$this->assertEquals('LEFT JOIN', $j->getJoinType());
|
||||
$this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn());
|
||||
$this->assertEquals('TABLE_B.COL_1', $j->getRightColumn());
|
||||
|
||||
$j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::RIGHT_JOIN);
|
||||
$this->assertEquals('RIGHT JOIN', $j->getJoinType());
|
||||
$this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn());
|
||||
$this->assertEquals('TABLE_B.COL_1', $j->getRightColumn());
|
||||
|
||||
$j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::INNER_JOIN);
|
||||
$this->assertEquals('INNER JOIN', $j->getJoinType());
|
||||
$this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn());
|
||||
$this->assertEquals('TABLE_B.COL_1', $j->getRightColumn());
|
||||
|
||||
$j = new Join(array('TABLE_A.COL_1', 'TABLE_A.COL_2'), array('TABLE_B.COL_1', 'TABLE_B.COL_2'), Criteria::INNER_JOIN);
|
||||
$this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn(0));
|
||||
$this->assertEquals('TABLE_A.COL_2', $j->getLeftColumn(1));
|
||||
$this->assertEquals('TABLE_B.COL_1', $j->getRightColumn(0));
|
||||
$this->assertEquals('TABLE_B.COL_2', $j->getRightColumn(1));
|
||||
}
|
||||
|
||||
public function testAddStraightJoin ()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_1'); // straight join
|
||||
|
||||
$expect = "SELECT * FROM TABLE_A, TABLE_B WHERE TABLE_A.COL_1=TABLE_B.COL_1";
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testAddSeveralJoins ()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_1');
|
||||
$c->addJoin('TABLE_B.COL_X', 'TABLE_D.COL_X');
|
||||
|
||||
$expect = 'SELECT * FROM TABLE_A, TABLE_B, TABLE_D '
|
||||
.'WHERE TABLE_A.COL_1=TABLE_B.COL_1 AND TABLE_B.COL_X=TABLE_D.COL_X';
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testAddLeftJoin ()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("TABLE_A.*");
|
||||
$c->addSelectColumn("TABLE_B.*");
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_2', Criteria::LEFT_JOIN);
|
||||
|
||||
$expect = "SELECT TABLE_A.*, TABLE_B.* FROM TABLE_A LEFT JOIN TABLE_B ON (TABLE_A.COL_1=TABLE_B.COL_2)";
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testAddSeveralLeftJoins ()
|
||||
{
|
||||
// Fails.. Suspect answer in the chunk starting at BasePeer:605
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn('*');
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::LEFT_JOIN);
|
||||
$c->addJoin('TABLE_A.COL_2', 'TABLE_C.COL_2', Criteria::LEFT_JOIN);
|
||||
|
||||
$expect = 'SELECT * FROM TABLE_A '
|
||||
.'LEFT JOIN TABLE_B ON (TABLE_A.COL_1=TABLE_B.COL_1) '
|
||||
.'LEFT JOIN TABLE_C ON (TABLE_A.COL_2=TABLE_C.COL_2)';
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testAddRightJoin ()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_2', Criteria::RIGHT_JOIN);
|
||||
|
||||
$expect = "SELECT * FROM TABLE_A RIGHT JOIN TABLE_B ON (TABLE_A.COL_1=TABLE_B.COL_2)";
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testAddSeveralRightJoins ()
|
||||
{
|
||||
// Fails.. Suspect answer in the chunk starting at BasePeer:605
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn('*');
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::RIGHT_JOIN);
|
||||
$c->addJoin('TABLE_A.COL_2', 'TABLE_C.COL_2', Criteria::RIGHT_JOIN);
|
||||
|
||||
$expect = 'SELECT * FROM TABLE_A '
|
||||
.'RIGHT JOIN TABLE_B ON (TABLE_A.COL_1=TABLE_B.COL_1) '
|
||||
.'RIGHT JOIN TABLE_C ON (TABLE_A.COL_2=TABLE_C.COL_2)';
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testAddInnerJoin ()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::INNER_JOIN);
|
||||
|
||||
$expect = "SELECT * FROM TABLE_A INNER JOIN TABLE_B ON (TABLE_A.COL_1=TABLE_B.COL_1)";
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
public function testAddSeveralInnerJoin ()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("*");
|
||||
$c->addJoin('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::INNER_JOIN);
|
||||
$c->addJoin('TABLE_B.COL_1', 'TABLE_C.COL_1', Criteria::INNER_JOIN);
|
||||
|
||||
$expect = 'SELECT * FROM TABLE_A '
|
||||
.'INNER JOIN TABLE_B ON (TABLE_A.COL_1=TABLE_B.COL_1) '
|
||||
.'INNER JOIN TABLE_C ON (TABLE_B.COL_1=TABLE_C.COL_1)';
|
||||
try {
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
} catch (PropelException $e) {
|
||||
print $e->getTraceAsString();
|
||||
$this->fail("PropelException thrown in BasePeer.createSelectSql(): ". $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @link http://propel.phpdb.org/trac/ticket/451
|
||||
*/
|
||||
public function testSeveralMixedJoinOrders()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->clearSelectColumns()->
|
||||
addJoin("TABLE_A.FOO_ID", "TABLE_B.ID", Criteria::LEFT_JOIN)->
|
||||
addJoin("TABLE_A.BAR_ID", "TABLE_C.ID")->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
# These are no longer different, see http://propel.phpdb.org/trac/ticket/283#comment:8
|
||||
#$db = Propel::getDB();
|
||||
#
|
||||
#if ($db instanceof DBMySQL) {
|
||||
# $expect = 'SELECT TABLE_A.ID FROM (TABLE_A CROSS JOIN TABLE_C)'
|
||||
# .' LEFT JOIN TABLE_B ON (TABLE_A.FOO_ID=TABLE_B.ID) WHERE TABLE_A.BAR_ID=TABLE_C.ID';
|
||||
#} else {
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A CROSS JOIN TABLE_C'
|
||||
.' LEFT JOIN TABLE_B ON (TABLE_A.FOO_ID=TABLE_B.ID) WHERE TABLE_A.BAR_ID=TABLE_C.ID';
|
||||
#}
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @link http://propel.phpdb.org/trac/ticket/606
|
||||
*/
|
||||
public function testAddJoinArray()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->clearSelectColumns()->
|
||||
addJoin(array('TABLE_A.FOO_ID'), array('TABLE_B.ID'), Criteria::LEFT_JOIN)->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A'
|
||||
.' LEFT JOIN TABLE_B ON (TABLE_A.FOO_ID=TABLE_B.ID)';
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @link http://propel.phpdb.org/trac/ticket/606
|
||||
*/
|
||||
public function testAddJoinArrayMultiple()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->clearSelectColumns()->
|
||||
addJoin(
|
||||
array('TABLE_A.FOO_ID', 'TABLE_A.BAR'),
|
||||
array('TABLE_B.ID', 'TABLE_B.BAZ'),
|
||||
Criteria::LEFT_JOIN)->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A'
|
||||
.' LEFT JOIN TABLE_B ON (TABLE_A.FOO_ID=TABLE_B.ID AND TABLE_A.BAR=TABLE_B.BAZ)';
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Criteria::addJoinMultiple() method with an implicit join
|
||||
*
|
||||
* @link http://propel.phpdb.org/trac/ticket/606
|
||||
*/
|
||||
public function testAddJoinMultiple()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->
|
||||
clearSelectColumns()->
|
||||
addMultipleJoin(array(
|
||||
array('TABLE_A.FOO_ID', 'TABLE_B.ID'),
|
||||
array('TABLE_A.BAR', 'TABLE_B.BAZ')))->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A, TABLE_B '
|
||||
. 'WHERE TABLE_A.FOO_ID=TABLE_B.ID AND TABLE_A.BAR=TABLE_B.BAZ';
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Criteria::addJoinMultiple() method with a value as second argument
|
||||
*
|
||||
* @link http://propel.phpdb.org/trac/ticket/606
|
||||
*/
|
||||
public function testAddJoinMultipleValue()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->
|
||||
clearSelectColumns()->
|
||||
addMultipleJoin(array(
|
||||
array('TABLE_A.FOO_ID', 'TABLE_B.ID'),
|
||||
array('TABLE_A.BAR', 3)))->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A, TABLE_B '
|
||||
. 'WHERE TABLE_A.FOO_ID=TABLE_B.ID AND TABLE_A.BAR=3';
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Criteria::addJoinMultiple() method with a joinType
|
||||
*
|
||||
* @link http://propel.phpdb.org/trac/ticket/606
|
||||
*/
|
||||
public function testAddJoinMultipleWithJoinType()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->
|
||||
clearSelectColumns()->
|
||||
addMultipleJoin(array(
|
||||
array('TABLE_A.FOO_ID', 'TABLE_B.ID'),
|
||||
array('TABLE_A.BAR', 'TABLE_B.BAZ')),
|
||||
Criteria::LEFT_JOIN)->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A '
|
||||
. 'LEFT JOIN TABLE_B ON (TABLE_A.FOO_ID=TABLE_B.ID AND TABLE_A.BAR=TABLE_B.BAZ)';
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Criteria::addJoinMultiple() method with operator
|
||||
*
|
||||
* @link http://propel.phpdb.org/trac/ticket/606
|
||||
*/
|
||||
public function testAddJoinMultipleWithOperator()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->
|
||||
clearSelectColumns()->
|
||||
addMultipleJoin(array(
|
||||
array('TABLE_A.FOO_ID', 'TABLE_B.ID', Criteria::GREATER_EQUAL),
|
||||
array('TABLE_A.BAR', 'TABLE_B.BAZ', Criteria::LESS_THAN)))->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A, TABLE_B '
|
||||
. 'WHERE TABLE_A.FOO_ID>=TABLE_B.ID AND TABLE_A.BAR<TABLE_B.BAZ';
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Criteria::addJoinMultiple() method with join type and operator
|
||||
*
|
||||
* @link http://propel.phpdb.org/trac/ticket/606
|
||||
*/
|
||||
public function testAddJoinMultipleWithJoinTypeAndOperator()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->
|
||||
clearSelectColumns()->
|
||||
addMultipleJoin(array(
|
||||
array('TABLE_A.FOO_ID', 'TABLE_B.ID', Criteria::GREATER_EQUAL),
|
||||
array('TABLE_A.BAR', 'TABLE_B.BAZ', Criteria::LESS_THAN)),
|
||||
Criteria::LEFT_JOIN)->
|
||||
addSelectColumn("TABLE_A.ID");
|
||||
|
||||
$expect = 'SELECT TABLE_A.ID FROM TABLE_A '
|
||||
. 'LEFT JOIN TABLE_B ON (TABLE_A.FOO_ID>=TABLE_B.ID AND TABLE_A.BAR<TABLE_B.BAZ)';
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Criteria::CUSTOM behavior.
|
||||
*/
|
||||
public function testCustomOperator()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn('A.COL');
|
||||
$c->add('A.COL', 'date_part(\'YYYY\', A.COL) = \'2007\'', Criteria::CUSTOM);
|
||||
|
||||
$expected = "SELECT A.COL FROM A WHERE date_part('YYYY', A.COL) = '2007'";
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests adding duplicate joins.
|
||||
* @link http://propel.phpdb.org/trac/ticket/613
|
||||
*/
|
||||
public function testAddJoin_Duplicate()
|
||||
{
|
||||
$c = new Criteria();
|
||||
|
||||
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
|
||||
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
|
||||
$this->assertEquals(1, count($c->getJoins()), "Expected not to have duplciate LJOIN added.");
|
||||
|
||||
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
|
||||
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
|
||||
$this->assertEquals(2, count($c->getJoins()), "Expected 1 new right join to be added.");
|
||||
|
||||
$c->addJoin("tbl.COL1", "tbl.COL2");
|
||||
$c->addJoin("tbl.COL1", "tbl.COL2");
|
||||
$this->assertEquals(3, count($c->getJoins()), "Expected 1 new implicit join to be added.");
|
||||
|
||||
$c->addJoin("tbl.COL3", "tbl.COL4");
|
||||
$this->assertEquals(4, count($c->getJoins()), "Expected new col join to be added.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @link http://propel.phpdb.org/trac/ticket/634
|
||||
*/
|
||||
public function testHasSelectClause()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn("foo");
|
||||
|
||||
$this->assertTrue($c->hasSelectClause());
|
||||
|
||||
$c = new Criteria();
|
||||
$c->addAsColumn("foo", "bar");
|
||||
|
||||
$this->assertTrue($c->hasSelectClause());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests including aliases in criterion objects.
|
||||
* @link http://propel.phpdb.org/trac/ticket/636
|
||||
*/
|
||||
public function testAliasInCriterion()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addAsColumn("column_alias", "tbl.COL1");
|
||||
$crit = $c->getNewCriterion("column_alias", "FOO");
|
||||
$this->assertNull($crit->getTable());
|
||||
$this->assertEquals("column_alias", $crit->getColumn());
|
||||
$c->addHaving($crit); // produces invalid SQL referring to '.olumn_alias'
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether GROUP BY is being respected in equals() check.
|
||||
* @link http://propel.phpdb.org/trac/ticket/674
|
||||
*/
|
||||
public function testEqualsGroupBy()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->addGroupByColumn('GBY1');
|
||||
|
||||
$c2 = new Criteria();
|
||||
$c2->addGroupByColumn('GBY2');
|
||||
|
||||
$this->assertFalse($c2->equals($c1), "Expected Criteria NOT to be the same with different GROUP BY columns");
|
||||
|
||||
$c3 = new Criteria();
|
||||
$c3->addGroupByColumn('GBY1');
|
||||
$c4 = new Criteria();
|
||||
$c4->addGroupByColumn('GBY1');
|
||||
$this->assertTrue($c4->equals($c3), "Expected Criteria objects to match.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether calling setDistinct twice puts in two distinct keywords or not.
|
||||
* @link http://propel.phpdb.org/trac/ticket/716
|
||||
*/
|
||||
public function testDoubleSelectModifiers()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->setDistinct();
|
||||
$this->assertEquals(array(Criteria::DISTINCT), $c->getSelectModifiers(), 'Initial setDistinct works');
|
||||
$c->setDistinct();
|
||||
$this->assertEquals(array(Criteria::DISTINCT), $c->getSelectModifiers(), 'Calling setDistinct again leaves a single distinct');
|
||||
$c->setAll();
|
||||
$this->assertEquals(array(Criteria::ALL), $c->getSelectModifiers(), 'All keyword is swaps distinct out');
|
||||
$c->setAll();
|
||||
$this->assertEquals(array(Criteria::ALL), $c->getSelectModifiers(), 'Calling setAll leaves a single all');
|
||||
$c->setDistinct();
|
||||
$this->assertEquals(array(Criteria::DISTINCT), $c->getSelectModifiers(), 'All back to distinct works');
|
||||
|
||||
$c2 = new Criteria();
|
||||
$c2->setAll();
|
||||
$this->assertEquals(array(Criteria::ALL), $c2->getSelectModifiers(), 'Initial setAll works');
|
||||
}
|
||||
|
||||
public function testAddSelectModifier()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->setDistinct();
|
||||
$c->addSelectModifier('SQL_CALC_FOUND_ROWS');
|
||||
$this->assertEquals(array(Criteria::DISTINCT, 'SQL_CALC_FOUND_ROWS'), $c->getSelectModifiers(), 'addSelectModifier() adds a select modifier to the Criteria');
|
||||
$c->addSelectModifier('SQL_CALC_FOUND_ROWS');
|
||||
$this->assertEquals(array(Criteria::DISTINCT, 'SQL_CALC_FOUND_ROWS'), $c->getSelectModifiers(), 'addSelectModifier() adds a select modifier only once');
|
||||
$params = array();
|
||||
$result = BasePeer::createSelectSql($c, $params);
|
||||
$this->assertEquals('SELECT DISTINCT SQL_CALC_FOUND_ROWS FROM ', $result, 'addSelectModifier() adds a modifier to the final query');
|
||||
}
|
||||
|
||||
public function testClone()
|
||||
{
|
||||
$c1 = new Criteria();
|
||||
$c1->add('tbl.COL1', 'foo', Criteria::EQUAL);
|
||||
$c2 = clone $c1;
|
||||
$c2->addAnd('tbl.COL1', 'bar', Criteria::EQUAL);
|
||||
$nbCrit = 0;
|
||||
foreach ($c1->keys() as $key) {
|
||||
foreach ($c1->getCriterion($key)->getAttachedCriterion() as $criterion) {
|
||||
$nbCrit++;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(1, $nbCrit, 'cloning a Criteria clones its Criterions');
|
||||
}
|
||||
|
||||
public function testComment()
|
||||
{
|
||||
$c = new Criteria();
|
||||
$this->assertNull($c->getComment(), 'Comment is null by default');
|
||||
$c2 = $c->setComment('foo');
|
||||
$this->assertEquals('foo', $c->getComment(), 'Comment is set by setComment()');
|
||||
$this->assertEquals($c, $c2, 'setComment() returns the current Criteria');
|
||||
$c->setComment();
|
||||
$this->assertNull($c->getComment(), 'Comment is reset by setComment(null)');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/BaseTestCase.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/query/Criteria.php';
|
||||
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "fixtures/bookstore/build/classes");
|
||||
Propel::init('fixtures/bookstore/build/conf/bookstore-conf.php');
|
||||
|
||||
/**
|
||||
* Test class for Join.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: JoinTest.php 1773 2010-05-25 10:25:06Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class JoinTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* DB adapter saved for later.
|
||||
*
|
||||
* @var DBAdapter
|
||||
*/
|
||||
private $savedAdapter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->savedAdapter = Propel::getDB(null);
|
||||
Propel::setDB(null, new DBSQLite());
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Propel::setDB(null, $this->savedAdapter);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testEmptyConditions()
|
||||
{
|
||||
$j = new Join();
|
||||
$this->assertEquals(array(), $j->getConditions());
|
||||
}
|
||||
|
||||
public function testAddCondition()
|
||||
{
|
||||
$j = new Join();
|
||||
$j->addCondition('foo', 'bar');
|
||||
$this->assertEquals('=', $j->getOperator());
|
||||
$this->assertEquals('foo', $j->getLeftColumn());
|
||||
$this->assertEquals('bar', $j->getRightColumn());
|
||||
}
|
||||
|
||||
public function testGetConditions()
|
||||
{
|
||||
$j = new Join();
|
||||
$j->addCondition('foo', 'bar');
|
||||
$expect = array(array('left' => 'foo', 'operator' => '=', 'right' => 'bar'));
|
||||
$this->assertEquals($expect, $j->getConditions());
|
||||
}
|
||||
|
||||
public function testAddConditionWithOperator()
|
||||
{
|
||||
$j = new Join();
|
||||
$j->addCondition('foo', 'bar', '>=');
|
||||
$expect = array(array('left' => 'foo', 'operator' => '>=', 'right' => 'bar'));
|
||||
$this->assertEquals($expect, $j->getConditions());
|
||||
}
|
||||
|
||||
public function testAddConditions()
|
||||
{
|
||||
$j = new Join();
|
||||
$j->addCondition('foo', 'bar');
|
||||
$j->addCondition('baz', 'bal');
|
||||
$expect = array(
|
||||
array('left' => 'foo', 'operator' => '=', 'right' => 'bar'),
|
||||
array('left' => 'baz', 'operator' => '=', 'right' => 'bal')
|
||||
);
|
||||
$this->assertEquals(array('=', '='), $j->getOperators());
|
||||
$this->assertEquals(array('foo', 'baz'), $j->getLeftColumns());
|
||||
$this->assertEquals(array('bar', 'bal'), $j->getRightColumns());
|
||||
$this->assertEquals($expect, $j->getConditions());
|
||||
}
|
||||
|
||||
public function testEmptyJoinType()
|
||||
{
|
||||
$j = new Join();
|
||||
$this->assertNull($j->getJoinType());
|
||||
}
|
||||
|
||||
public function testSetJoinType()
|
||||
{
|
||||
$j = new Join();
|
||||
$j->setJoinType('foo');
|
||||
$this->assertEquals('foo', $j->getJoinType());
|
||||
}
|
||||
|
||||
public function testSimpleConstructor()
|
||||
{
|
||||
$j = new Join('foo', 'bar', 'LEFT JOIN');
|
||||
$expect = array(array('left' => 'foo', 'operator' => '=', 'right' => 'bar'));
|
||||
$this->assertEquals($expect, $j->getConditions());
|
||||
$this->assertEquals('LEFT JOIN', $j->getJoinType());
|
||||
}
|
||||
|
||||
public function testCompositeeConstructor()
|
||||
{
|
||||
$j = new Join(array('foo1', 'foo2'), array('bar1', 'bar2'), 'LEFT JOIN');
|
||||
$expect = array(
|
||||
array('left' => 'foo1', 'operator' => '=', 'right' => 'bar1'),
|
||||
array('left' => 'foo2', 'operator' => '=', 'right' => 'bar2')
|
||||
);
|
||||
$this->assertEquals($expect, $j->getConditions());
|
||||
$this->assertEquals('LEFT JOIN', $j->getJoinType());
|
||||
}
|
||||
|
||||
public function testCountConditions()
|
||||
{
|
||||
$j = new Join();
|
||||
$this->assertEquals(0, $j->countConditions());
|
||||
$j->addCondition('foo', 'bar');
|
||||
$this->assertEquals(1, $j->countConditions());
|
||||
$j->addCondition('foo1', 'bar1');
|
||||
$this->assertEquals(2, $j->countConditions());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/bookstore/BookstoreTestBase.php';
|
||||
require_once 'tools/helpers/bookstore/BookstoreDataPopulator.php';
|
||||
|
||||
/**
|
||||
* Test class for ModelCriteria.
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @version $Id: ModelCriteriaTest.php 1662 2010-04-10 22:02:49Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class ModelCriteriaHooksTest extends BookstoreTestBase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
BookstoreDataPopulator::depopulate();
|
||||
BookstoreDataPopulator::populate();
|
||||
}
|
||||
|
||||
public function testPreSelect()
|
||||
{
|
||||
$c = new ModelCriteriaWithPreSelectHook('bookstore', 'Book');
|
||||
$books = $c->find();
|
||||
$this->assertEquals(1, count($books), 'preSelect() can modify the Criteria before find() fires the query');
|
||||
|
||||
$c = new ModelCriteriaWithPreSelectHook('bookstore', 'Book');
|
||||
$nbBooks = $c->count();
|
||||
$this->assertEquals(1, $nbBooks, 'preSelect() can modify the Criteria before count() fires the query');
|
||||
}
|
||||
|
||||
public function testPreDelete()
|
||||
{
|
||||
$c = new ModelCriteria('bookstore', 'Book');
|
||||
$books = $c->find();
|
||||
$count = count($books);
|
||||
$book = $books->shift();
|
||||
|
||||
$c = new ModelCriteriaWithPreDeleteHook('bookstore', 'Book', 'b');
|
||||
$c->where('b.Id = ?', $book->getId());
|
||||
$nbBooks = $c->delete();
|
||||
$this->assertEquals(12, $nbBooks, 'preDelete() can change the return value of delete()');
|
||||
|
||||
$c = new ModelCriteria('bookstore', 'Book');
|
||||
$nbBooks = $c->count();
|
||||
$this->assertEquals($count, $nbBooks, 'preDelete() can bypass the row deletion');
|
||||
|
||||
$c = new ModelCriteriaWithPreDeleteHook('bookstore', 'Book');
|
||||
$nbBooks = $c->deleteAll();
|
||||
$this->assertEquals(12, $nbBooks, 'preDelete() can change the return value of deleteAll()');
|
||||
|
||||
$c = new ModelCriteria('bookstore', 'Book');
|
||||
$nbBooks = $c->count();
|
||||
$this->assertEquals($count, $nbBooks, 'preDelete() can bypass the row deletion');
|
||||
}
|
||||
|
||||
public function testPostDelete()
|
||||
{
|
||||
$c = new ModelCriteria('bookstore', 'Book');
|
||||
$books = $c->find();
|
||||
$count = count($books);
|
||||
$book = $books->shift();
|
||||
|
||||
$this->con->lastAffectedRows = 0;
|
||||
|
||||
$c = new ModelCriteriaWithPostDeleteHook('bookstore', 'Book', 'b');
|
||||
$c->where('b.Id = ?', $book->getId());
|
||||
$nbBooks = $c->delete($this->con);
|
||||
$this->assertEquals(1, $this->con->lastAffectedRows, 'postDelete() is called after delete()');
|
||||
|
||||
$this->con->lastAffectedRows = 0;
|
||||
|
||||
$c = new ModelCriteriaWithPostDeleteHook('bookstore', 'Book');
|
||||
$nbBooks = $c->deleteAll($this->con);
|
||||
$this->assertEquals(3, $this->con->lastAffectedRows, 'postDelete() is called after deleteAll()');
|
||||
}
|
||||
|
||||
public function testPreAndPostDelete()
|
||||
{
|
||||
$c = new ModelCriteria('bookstore', 'Book');
|
||||
$books = $c->find();
|
||||
$count = count($books);
|
||||
$book = $books->shift();
|
||||
|
||||
$this->con->lastAffectedRows = 0;
|
||||
|
||||
$c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book', 'b');
|
||||
$c->where('b.Id = ?', $book->getId());
|
||||
$nbBooks = $c->delete($this->con);
|
||||
$this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after delete() even if preDelete() returns not null');
|
||||
|
||||
$this->con->lastAffectedRows = 0;
|
||||
|
||||
$c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book');
|
||||
$nbBooks = $c->deleteAll($this->con);
|
||||
$this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after deleteAll() even if preDelete() returns not null');
|
||||
}
|
||||
|
||||
public function testPreUpdate()
|
||||
{
|
||||
$c = new ModelCriteriaWithPreUpdateHook('bookstore', 'Book', 'b');
|
||||
$c->where('b.Title = ?', 'Don Juan');
|
||||
$nbBooks = $c->update(array('Title' => 'foo'));
|
||||
|
||||
$c = new ModelCriteriaWithPreUpdateHook('bookstore', 'Book', 'b');
|
||||
$c->where('b.Title = ?', 'foo');
|
||||
$book = $c->findOne();
|
||||
|
||||
$this->assertEquals('1234', $book->getISBN(), 'preUpdate() can modify the values');
|
||||
}
|
||||
|
||||
public function testPostUpdate()
|
||||
{
|
||||
$this->con->lastAffectedRows = 0;
|
||||
|
||||
$c = new ModelCriteriaWithPostUpdateHook('bookstore', 'Book', 'b');
|
||||
$c->where('b.Title = ?', 'Don Juan');
|
||||
$nbBooks = $c->update(array('Title' => 'foo'), $this->con);
|
||||
$this->assertEquals(1, $this->con->lastAffectedRows, 'postUpdate() is called after update()');
|
||||
}
|
||||
|
||||
public function testPreAndPostUpdate()
|
||||
{
|
||||
$this->con->lastAffectedRows = 0;
|
||||
|
||||
$c = new ModelCriteriaWithPreAndPostUpdateHook('bookstore', 'Book', 'b');
|
||||
$c->where('b.Title = ?', 'Don Juan');
|
||||
$nbBooks = $c->update(array('Title' => 'foo'), $this->con);
|
||||
$this->assertEquals(52, $this->con->lastAffectedRows, 'postUpdate() is called after update() even if preUpdate() returns not null');
|
||||
}
|
||||
}
|
||||
|
||||
class ModelCriteriaWithPreSelectHook extends ModelCriteria
|
||||
{
|
||||
public function preSelect(PropelPDO $con)
|
||||
{
|
||||
$this->where($this->getModelAliasOrName() . '.Title = ?', 'Don Juan');
|
||||
}
|
||||
}
|
||||
|
||||
class ModelCriteriaWithPreDeleteHook extends ModelCriteria
|
||||
{
|
||||
public function preDelete(PropelPDO $con)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
|
||||
class ModelCriteriaWithPostDeleteHook extends ModelCriteria
|
||||
{
|
||||
public function postDelete($affectedRows, PropelPDO $con)
|
||||
{
|
||||
$con->lastAffectedRows = $affectedRows;
|
||||
}
|
||||
}
|
||||
|
||||
class ModelCriteriaWithPreAndPostDeleteHook extends ModelCriteriaWithPostDeleteHook
|
||||
{
|
||||
public function preDelete(PropelPDO $con)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
|
||||
class ModelCriteriaWithPreUpdateHook extends ModelCriteria
|
||||
{
|
||||
public function preUpdate(&$values, PropelPDO $con, $forceIndividualSaves = false)
|
||||
{
|
||||
$values['ISBN'] = '1234';
|
||||
}
|
||||
}
|
||||
|
||||
class ModelCriteriaWithPostUpdateHook extends ModelCriteria
|
||||
{
|
||||
public function postUpdate($affectedRows, PropelPDO $con)
|
||||
{
|
||||
$con->lastAffectedRows = $affectedRows;
|
||||
}
|
||||
}
|
||||
|
||||
class ModelCriteriaWithPreAndPostUpdateHook extends ModelCriteriaWithPostUpdateHook
|
||||
{
|
||||
public function preUpdate(&$values, PropelPDO $con, $forceIndividualSaves = false)
|
||||
{
|
||||
return 52;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/bookstore/BookstoreTestBase.php';
|
||||
require_once 'tools/helpers/bookstore/BookstoreDataPopulator.php';
|
||||
|
||||
/**
|
||||
* Test class for ModelJoin.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: ModelJoinTest.php 1347 2009-12-03 21:06:36Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class ModelJoinTest extends BookstoreTestBase
|
||||
{
|
||||
public function testTableMap()
|
||||
{
|
||||
$join = new ModelJoin();
|
||||
$this->assertNull($join->getTableMap(), 'getTableMap() returns null as long as no table map is set');
|
||||
|
||||
$tmap = new TableMap();
|
||||
$tmap->foo = 'bar';
|
||||
|
||||
$join->setTableMap($tmap);
|
||||
$this->assertEquals($tmap, $join->getTableMap(), 'getTableMap() returns the TableMap previously set by setTableMap()');
|
||||
}
|
||||
|
||||
public function testSetRelationMap()
|
||||
{
|
||||
$join = new ModelJoin();
|
||||
$this->assertNull($join->getRelationMap(), 'getRelationMap() returns null as long as no relation map is set');
|
||||
$bookTable = BookPeer::getTableMap();
|
||||
$relationMap = $bookTable->getRelation('Author');
|
||||
$join->setRelationMap($relationMap);
|
||||
$this->assertEquals($relationMap, $join->getRelationMap(), 'getRelationMap() returns the RelationMap previously set by setRelationMap()');
|
||||
}
|
||||
|
||||
public function testSetRelationMapDefinesJoinColumns()
|
||||
{
|
||||
$bookTable = BookPeer::getTableMap();
|
||||
$join = new ModelJoin();
|
||||
$join->setTableMap($bookTable);
|
||||
$join->setRelationMap($bookTable->getRelation('Author'));
|
||||
$this->assertEquals(array(BookPeer::AUTHOR_ID), $join->getLeftColumns(), 'setRelationMap() automatically sets the left columns');
|
||||
$this->assertEquals(array(AuthorPeer::ID), $join->getRightColumns(), 'setRelationMap() automatically sets the right columns');
|
||||
}
|
||||
|
||||
public function testSetRelationMapLeftAlias()
|
||||
{
|
||||
$bookTable = BookPeer::getTableMap();
|
||||
$join = new ModelJoin();
|
||||
$join->setTableMap($bookTable);
|
||||
$join->setRelationMap($bookTable->getRelation('Author'), 'b');
|
||||
$this->assertEquals(array('b.AUTHOR_ID'), $join->getLeftColumns(), 'setRelationMap() automatically sets the left columns using the left table alias');
|
||||
$this->assertEquals(array(AuthorPeer::ID), $join->getRightColumns(), 'setRelationMap() automatically sets the right columns');
|
||||
}
|
||||
|
||||
public function testSetRelationMapRightAlias()
|
||||
{
|
||||
$bookTable = BookPeer::getTableMap();
|
||||
$join = new ModelJoin();
|
||||
$join->setTableMap($bookTable);
|
||||
$join->setRelationMap($bookTable->getRelation('Author'), null, 'a');
|
||||
$this->assertEquals(array(BookPeer::AUTHOR_ID), $join->getLeftColumns(), 'setRelationMap() automatically sets the left columns');
|
||||
$this->assertEquals(array('a.ID'), $join->getRightColumns(), 'setRelationMap() automatically sets the right columns using the right table alias');
|
||||
}
|
||||
|
||||
public function testSetRelationMapComposite()
|
||||
{
|
||||
$table = ReaderFavoritePeer::getTableMap();
|
||||
$join = new ModelJoin();
|
||||
$join->setTableMap($table);
|
||||
$join->setRelationMap($table->getRelation('BookOpinion'));
|
||||
$this->assertEquals(array(ReaderFavoritePeer::BOOK_ID, ReaderFavoritePeer::READER_ID), $join->getLeftColumns(), 'setRelationMap() automatically sets the left columns for composite relationships');
|
||||
$this->assertEquals(array(BookOpinionPeer::BOOK_ID, BookOpinionPeer::READER_ID), $join->getRightColumns(), 'setRelationMap() automatically sets the right columns for composite relationships');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/bookstore/BookstoreTestBase.php';
|
||||
require_once 'tools/helpers/bookstore/BookstoreDataPopulator.php';
|
||||
|
||||
/**
|
||||
* Test class for ModelWith.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: ModelJoinTest.php 1347 2009-12-03 21:06:36Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class ModelWithTest extends BookstoreTestBase
|
||||
{
|
||||
|
||||
public function testModelNameManyToOne()
|
||||
{
|
||||
$q = BookQuery::create()
|
||||
->joinAuthor();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Author'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getModelName(), 'Author', 'A ModelWith computes the model name from the join');
|
||||
$this->assertEquals($with->getModelPeerName(), 'AuthorPeer', 'A ModelWith computes the model peer name from the join');
|
||||
}
|
||||
|
||||
public function testModelNameOneToMany()
|
||||
{
|
||||
$q = AuthorQuery::create()
|
||||
->joinBook();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Book'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getModelName(), 'Book', 'A ModelWith computes the model peer name from the join');
|
||||
$this->assertEquals($with->getModelPeerName(), 'BookPeer', 'A ModelWith computes the model peer name from the join');
|
||||
}
|
||||
|
||||
public function testModelNameAlias()
|
||||
{
|
||||
$q = BookQuery::create()
|
||||
->joinAuthor('a');
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['a'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getModelName(), 'Author', 'A ModelWith computes the model peer name from the join');
|
||||
$this->assertEquals($with->getModelPeerName(), 'AuthorPeer', 'A ModelWith computes the model peer name from the join');
|
||||
}
|
||||
|
||||
public function testRelationManyToOne()
|
||||
{
|
||||
$q = BookQuery::create()
|
||||
->joinAuthor();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Author'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelationMethod(), 'setAuthor', 'A ModelWith computes the relation method from the join');
|
||||
$this->assertEquals($with->getRelationName(), 'Author', 'A ModelWith computes the relation name from the join');
|
||||
$this->assertFalse($with->isAdd(), 'A ModelWith computes the relation cardinality from the join');
|
||||
}
|
||||
|
||||
public function testRelationOneToMany()
|
||||
{
|
||||
$q = AuthorQuery::create()
|
||||
->joinBook();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Book'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelationMethod(), 'addBook', 'A ModelWith computes the relation method from the join');
|
||||
$this->assertEquals($with->getRelationName(), 'Books', 'A ModelWith computes the relation name from the join');
|
||||
$this->assertTrue($with->isAdd(), 'A ModelWith computes the relation cardinality from the join');
|
||||
}
|
||||
|
||||
public function testRelationOneToOne()
|
||||
{
|
||||
$q = BookstoreEmployeeQuery::create()
|
||||
->joinBookstoreEmployeeAccount();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['BookstoreEmployeeAccount'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelationMethod(), 'setBookstoreEmployeeAccount', 'A ModelWith computes the relation method from the join');
|
||||
$this->assertEquals($with->getRelationName(), 'BookstoreEmployeeAccount', 'A ModelWith computes the relation name from the join');
|
||||
$this->assertFalse($with->isAdd(), 'A ModelWith computes the relation cardinality from the join');
|
||||
}
|
||||
|
||||
public function testIsPrimary()
|
||||
{
|
||||
$q = AuthorQuery::create()
|
||||
->joinBook();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Book'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertTrue($with->isPrimary(), 'A ModelWith initialized from a primary join is primary');
|
||||
|
||||
$q = BookQuery::create()
|
||||
->joinAuthor()
|
||||
->joinReview();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Review'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertTrue($with->isPrimary(), 'A ModelWith initialized from a primary join is primary');
|
||||
|
||||
$q = AuthorQuery::create()
|
||||
->join('Author.Book')
|
||||
->join('Book.Publisher');
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Publisher'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertFalse($with->isPrimary(), 'A ModelWith initialized from a non-primary join is not primary');
|
||||
}
|
||||
|
||||
public function testGetRelatedClass()
|
||||
{
|
||||
$q = AuthorQuery::create()
|
||||
->joinBook();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Book'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertNull($with->getRelatedClass(), 'A ModelWith initialized from a primary join has a null related class');
|
||||
|
||||
$q = AuthorQuery::create('a')
|
||||
->joinBook();
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Book'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertNull($with->getRelatedClass(), 'A ModelWith initialized from a primary join with alias has a null related class');
|
||||
|
||||
$q = AuthorQuery::create()
|
||||
->joinBook('b');
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['b'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertNull($with->getRelatedClass(), 'A ModelWith initialized from a primary join with alias has a null related class');
|
||||
|
||||
$q = AuthorQuery::create()
|
||||
->join('Author.Book')
|
||||
->join('Book.Publisher');
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Publisher'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
|
||||
|
||||
$q = ReviewQuery::create()
|
||||
->join('Review.Book')
|
||||
->join('Book.Author')
|
||||
->join('Book.Publisher');
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Publisher'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
|
||||
|
||||
$q = ReviewQuery::create()
|
||||
->join('Review.Book')
|
||||
->join('Book.BookOpinion')
|
||||
->join('BookOpinion.BookReader');
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['BookOpinion'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
|
||||
$join = $joins['BookReader'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelatedClass(), 'BookOpinion', 'A ModelWith uses the previous join relation name as related class');
|
||||
|
||||
$q = BookReaderQuery::create()
|
||||
->join('BookReader.BookOpinion')
|
||||
->join('BookOpinion.Book')
|
||||
->join('Book.Author');
|
||||
$joins = $q->getJoins();
|
||||
$join = $joins['Book'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelatedClass(), 'BookOpinion', 'A ModelWith uses the previous join relation name as related class');
|
||||
$join = $joins['Author'];
|
||||
$with = new ModelWith($join);
|
||||
$this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'tools/helpers/bookstore/BookstoreTestBase.php';
|
||||
require_once 'tools/helpers/bookstore/BookstoreDataPopulator.php';
|
||||
|
||||
/**
|
||||
* Test class for PropelQuery
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @version $Id: PropelQueryTest.php 1351 2009-12-04 22:05:01Z francois $
|
||||
* @package runtime.query
|
||||
*/
|
||||
class PropelQueryTest extends BookstoreTestBase
|
||||
{
|
||||
public function testFrom()
|
||||
{
|
||||
$q = PropelQuery::from('Book');
|
||||
$expected = new BookQuery();
|
||||
$this->assertEquals($expected, $q, 'from() returns a Model query instance based on the model name');
|
||||
|
||||
$q = PropelQuery::from('Book b');
|
||||
$expected = new BookQuery();
|
||||
$expected->setModelAlias('b');
|
||||
$this->assertEquals($expected, $q, 'from() sets the model alias if found after the blank');
|
||||
|
||||
$q = PropelQuery::from('myBook');
|
||||
$expected = new myBookQuery();
|
||||
$this->assertEquals($expected, $q, 'from() can find custom query classes');
|
||||
|
||||
try {
|
||||
$q = PropelQuery::from('Foo');
|
||||
$this->fail('PropelQuery::from() throws an exception when called on a non-existing query class');
|
||||
} catch (PropelException $e) {
|
||||
$this->assertTrue(true, 'PropelQuery::from() throws an exception when called on a non-existing query class');
|
||||
}
|
||||
}
|
||||
|
||||
public function testQuery()
|
||||
{
|
||||
BookstoreDataPopulator::depopulate();
|
||||
BookstoreDataPopulator::populate();
|
||||
|
||||
$book = PropelQuery::from('Book b')
|
||||
->where('b.Title like ?', 'Don%')
|
||||
->orderBy('b.ISBN', 'desc')
|
||||
->findOne();
|
||||
$this->assertTrue($book instanceof Book);
|
||||
$this->assertEquals('Don Juan', $book->getTitle());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class myBookQuery extends BookQuery
|
||||
{
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue