Skip to content

Commit

Permalink
add unittest for nested functions in columns in Zend_Db_Select
Browse files Browse the repository at this point in the history
  • Loading branch information
globin authored and Dimitris Giotas committed Jun 17, 2016
1 parent 820c728 commit 2339b43
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/Zend/Db/Select/StaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,26 @@ public function testSqlInjectionInColumn()
$this->assertEquals('SELECT "p"."MD5(1); drop table products; -- )" FROM "products" AS "p"', $select->assemble());
}

public function testIfInColumn()
{
$select = $this->_db->select();
$select->from('table1', '*');
$select->join(array('table2'),
'table1.id = table2.id',
array('bar' => 'IF(table2.id IS NOT NULL, 1, 0)'));
$this->assertEquals("SELECT \"table1\".*, IF(table2.id IS NOT NULL, 1, 0) AS \"bar\" FROM \"table1\"\n INNER JOIN \"table2\" ON table1.id = table2.id", $select->assemble());
}

public function testNestedIfInColumn()
{
$select = $this->_db->select();
$select->from('table1', '*');
$select->join(array('table2'),
'table1.id = table2.id',
array('bar' => 'IF(table2.id IS NOT NULL, IF(table2.id2 IS NOT NULL, 1, 2), 0)'));
$this->assertEquals("SELECT \"table1\".*, IF(table2.id IS NOT NULL, IF(table2.id2 IS NOT NULL, 1, 2), 0) AS \"bar\" FROM \"table1\"\n INNER JOIN \"table2\" ON table1.id = table2.id", $select->assemble());
}

/**
* @group ZF-378
*/
Expand Down

0 comments on commit 2339b43

Please sign in to comment.