public function testaddUsingOperatorResetsDefaultOperator()
 {
     $c = new Criteria();
     $c->addUsingOperator('foo1', 'bar1');
     $c->_or();
     $c->addUsingOperator('foo2', 'bar2');
     $c->addUsingOperator('foo3', 'bar3');
     $expected = 'SELECT  FROM  WHERE (foo1=:p1 OR foo2=:p2) AND foo3=:p3';
     $params = array();
     $result = BasePeer::createSelectSql($c, $params);
     $this->assertEquals($expected, $result);
 }
Esempio n. 2
0
 public function testMerge_OrWithWhereConditions()
 {
     $c1 = new Criteria();
     $c1->add(BookPeer::TITLE, 'foo');
     $c2 = new Criteria();
     $c1->_or();
     $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->_or();
     $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);
     $c1->_or();
     $c2 = new Criteria();
     $c2->add(BookPeer::TITLE, 'foo');
     $c1->mergeWith($c2);
     $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');
     $c1->_or();
     $c2 = new Criteria();
     $c2->add(BookPeer::TITLE, 'bar');
     $c1->mergeWith($c2);
     $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);
     $c1->_or();
     $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 OR author.FIRST_NAME=:p2)';
     $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions on the different tables');
 }