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

Commit

Permalink
Merge pull request #383 from DragonBe/zdbselect-ordertests
Browse files Browse the repository at this point in the history
Unit test for ZF-1.12.7 (issue #378 & #381)
  • Loading branch information
ezimuel committed Jun 19, 2014
2 parents 3f5a21e + d4fb7d0 commit 91b0baf
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/Zend/Db/Select/Pdo/PgsqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,61 @@ public function testSqlInjectionWithOrder()
$select->from(array('p' => 'products'))->order('name;select;MD5(1)');
$this->assertEquals('SELECT "p".* FROM "products" AS "p" ORDER BY "name;select;MD5(1)" ASC', $select->assemble());
}

/**
* @group ZF-378
*/
public function testOrderOfSingleFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('productId DESC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId DESC', 'userId ASC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC, "userId" ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldButOnlyOneWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId', 'userId DESC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" ASC, "userId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
* @group ZF-381
*/
public function testOrderOfConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF("productId" > 5,1,0) ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY IF("productId" > 5,1,0) ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}
}
57 changes: 57 additions & 0 deletions tests/Zend/Db/Select/Pdo/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,61 @@ public function testSqlInjectionWithOrder()
$this->assertEquals('SELECT "p".* FROM "products" AS "p" ORDER BY "name;select;MD5(1)" ASC', $select->assemble());
}

/**
* @group ZF-378
*/
public function testOrderOfSingleFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('productId DESC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId DESC', 'userId ASC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC, "userId" ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldButOnlyOneWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId', 'userId DESC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" ASC, "userId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
* @group ZF-381
*/
public function testOrderOfConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF("productId" > 5,1,0) ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY IF("productId" > 5,1,0) ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

}
57 changes: 57 additions & 0 deletions tests/Zend/Db/Select/StaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,4 +831,61 @@ public function testSqlInjectionWithOrder()
$select->from(array('p' => 'products'))->order('name;select;MD5(1)');
$this->assertEquals('SELECT "p".* FROM "products" AS "p" ORDER BY "name;select;MD5(1)" ASC', $select->assemble());
}

/**
* @group ZF-378
*/
public function testOrderOfSingleFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('productId DESC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId DESC', 'userId ASC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC, "userId" ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldButOnlyOneWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId', 'userId DESC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" ASC, "userId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
* @group ZF-381
*/
public function testOrderOfConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF("productId" > 5,1,0) ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY IF("productId" > 5,1,0) ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}
}
57 changes: 57 additions & 0 deletions tests/Zend/Db/Select/TestCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -1767,4 +1767,61 @@ public function testSqlInjectionWithOrder()
$select->from(array('p' => 'products'))->order('name;select;MD5(1)');
$this->assertEquals('SELECT `p`.* FROM `products` AS `p` ORDER BY `name;select;MD5(1)` ASC', $select->assemble());
}

/**
* @group ZF-378
*/
public function testOrderOfSingleFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('productId DESC');

$expected = 'SELECT `p`.* FROM `product` AS `p` ORDER BY `productId` DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId DESC', 'userId ASC'));

$expected = 'SELECT `p`.* FROM `product` AS `p` ORDER BY `productId` DESC, `userId` ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldButOnlyOneWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId', 'userId DESC'));

$expected = 'SELECT `p`.* FROM `product` AS `p` ORDER BY `productId` ASC, `userId` DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
* @group ZF-381
*/
public function testOrderOfConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF(`productId` > 5,1,0) ASC');

$expected = 'SELECT `p`.* FROM `product` AS `p` ORDER BY IF(`productId` > 5,1,0) ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}
}
57 changes: 57 additions & 0 deletions tests/Zend/Db/Table/Select/Pdo/PgsqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,61 @@ public function testSqlInjectionWithOrder()
$select->from(array('p' => 'products'))->order('name;select;MD5(1)');
$this->assertEquals('SELECT "p".* FROM "products" AS "p" ORDER BY "name;select;MD5(1)" ASC', $select->assemble());
}

/**
* @group ZF-378
*/
public function testOrderOfSingleFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('productId DESC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId DESC', 'userId ASC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC, "userId" ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldButOnlyOneWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId', 'userId DESC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" ASC, "userId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
* @group ZF-381
*/
public function testOrderOfConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF("productId" > 5,1,0) ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY IF("productId" > 5,1,0) ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}
}
57 changes: 57 additions & 0 deletions tests/Zend/Db/Table/Select/Pdo/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,61 @@ public function testSqlInjectionWithOrder()
$this->assertEquals('SELECT "p".* FROM "products" AS "p" ORDER BY "name;select;MD5(1)" ASC', $select->assemble());
}

/**
* @group ZF-378
*/
public function testOrderOfSingleFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('productId DESC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId DESC', 'userId ASC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" DESC, "userId" ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
*/
public function testOrderOfMultiFieldButOnlyOneWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order(array ('productId', 'userId DESC'));

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY "productId" ASC, "userId" DESC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

/**
* @group ZF-378
* @group ZF-381
*/
public function testOrderOfConditionalFieldWithDirection()
{
$select = $this->_db->select();
$select->from(array ('p' => 'product'))
->order('IF("productId" > 5,1,0) ASC');

$expected = 'SELECT "p".* FROM "product" AS "p" ORDER BY IF("productId" > 5,1,0) ASC';
$this->assertEquals($expected, $select->assemble(),
'Order direction of field failed');
}

}
Loading

0 comments on commit 91b0baf

Please sign in to comment.