Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Added tests for order and group
Browse files Browse the repository at this point in the history
  • Loading branch information
foxel committed May 19, 2015
1 parent da05e5c commit 7dd5c48
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/Zend/Db/Select/StaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,26 @@ public function testNestedUnbalancedParenthesesInColumn()
$this->assertEquals("SELECT \"table1\".*, \"table2\".\"IF(SUM()\" AS \"bar\" FROM \"table1\"\n INNER JOIN \"table2\" ON table1.id = table2.id", $select->assemble());
}

public function testNestedIfInGroup()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->group('IF(p.id IS NOT NULL, IF(p.id2 IS NOT NULL, SUM(1), 2), 0)');

$expected = 'SELECT "p".* FROM "product" AS "p" GROUP BY IF(p.id IS NOT NULL, IF(p.id2 IS NOT NULL, SUM(1), 2), 0)';
$this->assertEquals($expected, $select->assemble());
}

public function testUnbalancedParenthesesInGroup()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->group('IF(SUM() ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" GROUP BY "IF(SUM() ASC"';
$this->assertEquals($expected, $select->assemble());
}

/**
* @group ZF-378
*/
Expand Down Expand Up @@ -950,4 +970,45 @@ public function testOrderOfConditionalFieldWithDirection()
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

public function testOrderOfDeepConditionalField()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF(p.id IS NOT NULL, IF(p.id2 IS NOT NULL, SUM(1), 2), 0)');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY IF(p.id IS NOT NULL, IF(p.id2 IS NOT NULL, SUM(1), 2), 0) ASC';
$this->assertEquals($expected, $select->assemble());
}

public function testOrderOfDeepUnbalancedConditionalField()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF(SUM()');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "IF(SUM()" ASC';
$this->assertEquals($expected, $select->assemble());
}

public function testOrderOfDeepConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF(p.id IS NOT NULL, IF(p.id2 IS NOT NULL, SUM(1), 2), 0) ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY IF(p.id IS NOT NULL, IF(p.id2 IS NOT NULL, SUM(1), 2), 0) ASC';
$this->assertEquals($expected, $select->assemble());
}

public function testOrderOfDeepUnbalancedConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF(SUM() ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "IF(SUM()" ASC';
$this->assertEquals($expected, $select->assemble());
}

}

0 comments on commit 7dd5c48

Please sign in to comment.