Просмотр исходного кода

Unit test for ZF-1.12.7 (issue #378 & #381) regarding select statements with ordering direction or condition

michelangelo 11 лет назад
Родитель
Сommit
befb8a2137

+ 57 - 0
tests/Zend/Db/Select/Pdo/PgsqlTest.php

@@ -137,4 +137,61 @@ class Zend_Db_Select_Pdo_PgsqlTest extends Zend_Db_Select_TestCommon
         $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($adapter)
+    {
+        $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 - 0
tests/Zend/Db/Select/Pdo/SqliteTest.php

@@ -185,4 +185,61 @@ class Zend_Db_Select_Pdo_SqliteTest extends Zend_Db_Select_TestCommon
         $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($adapter)
+    {
+        $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 - 0
tests/Zend/Db/Select/StaticTest.php

@@ -831,4 +831,61 @@ class Zend_Db_Select_StaticTest extends Zend_Db_Select_TestCommon
         $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($adapter)
+    {
+        $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 - 0
tests/Zend/Db/Select/TestCommon.php

@@ -1767,4 +1767,61 @@ abstract class Zend_Db_Select_TestCommon extends Zend_Db_TestSetup
         $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($adapter)
+    {
+        $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 - 0
tests/Zend/Db/Table/Select/Pdo/PgsqlTest.php

@@ -141,4 +141,61 @@ class Zend_Db_Table_Select_Pdo_PgsqlTest extends Zend_Db_Table_Select_TestCommon
         $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($adapter)
+    {
+        $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 - 0
tests/Zend/Db/Table/Select/Pdo/SqliteTest.php

@@ -189,4 +189,61 @@ class Zend_Db_Table_Select_Pdo_SqliteTest extends Zend_Db_Table_Select_TestCommo
         $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($adapter)
+    {
+        $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 - 0
tests/Zend/Db/Table/Select/StaticTest.php

@@ -708,4 +708,61 @@ class Zend_Db_Table_Select_StaticTest extends Zend_Db_Select_TestCommon
         $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($adapter)
+    {
+        $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');
+    }
+
 }