Преглед изворни кода

ZF-7906
- Fix for failing static tests added to Zend_Db_Select_TestCommon for ZF-7221


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18345 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph пре 16 година
родитељ
комит
2e859aa61d

+ 33 - 0
tests/Zend/Db/Select/StaticTest.php

@@ -653,6 +653,39 @@ class Zend_Db_Select_StaticTest extends Zend_Db_Select_TestCommon
         $sql = preg_replace('/\\s+/', ' ', $select->__toString());
         $this->assertEquals('SELECT "bug_id" AS "id", "bug_status" AS "name" FROM "zfbugs" UNION SELECT "product_id" AS "id", "product_name" AS "name" FROM "zfproducts" ORDER BY "id" ASC', $sql);
     }
+    
+    public function testSelectOrderByPosition()
+    {
+        $select = $this->_selectOrderByPosition(); 
+        
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 ASC', $sql);
+    }
+
+    public function testSelectOrderByPositionAsc()
+    {
+        $select = $this->_selectOrderByPositionAsc(); 
+        
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 ASC', $sql);
+    }
+
+    public function testSelectOrderByPositionDesc()
+    {
+        $select = $this->_selectOrderByPositionDesc();
+
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 DESC', $sql);
+    }
+
+    public function testSelectOrderByMultiplePositions()
+    {
+        $select = $this->_selectOrderByMultiplePositions();
+
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 DESC, 1 DESC', $sql);
+    }
+    
 
     public function getDriver()
     {

+ 28 - 4
tests/Zend/Db/Select/TestCommon.php

@@ -1229,11 +1229,17 @@ abstract class Zend_Db_Select_TestCommon extends Zend_Db_TestSetup
         $this->assertEquals(1, $result[0]['product_id']);
     }
 
-    public function testSelectOrderByPosition()
+    protected function _selectOrderByPosition()
     {
         $select = $this->_db->select()
             ->from('zfproducts')
             ->order('2');
+        return $select;
+    }
+    
+    public function testSelectOrderByPosition()
+    {
+        $select = $this->_selectOrderByPosition();
 
         $stmt = $this->_db->query($select);
         $result = $stmt->fetchAll();
@@ -1243,11 +1249,17 @@ abstract class Zend_Db_Select_TestCommon extends Zend_Db_TestSetup
         $this->assertEquals(1, $result[2]['product_id']);
     }
 
-    public function testSelectOrderByPositionAsc()
+    protected function _selectOrderByPositionAsc()
     {
         $select = $this->_db->select()
             ->from('zfproducts')
             ->order('2 ASC');
+        return $select;
+    }
+    
+    public function testSelectOrderByPositionAsc()
+    {
+        $select = $this->_selectOrderByPositionAsc();
 
         $stmt = $this->_db->query($select);
         $result = $stmt->fetchAll();
@@ -1257,11 +1269,17 @@ abstract class Zend_Db_Select_TestCommon extends Zend_Db_TestSetup
         $this->assertEquals(1, $result[2]['product_id']);
     }
 
-    public function testSelectOrderByPositionDesc()
+    protected function _selectOrderByPositionDesc()
     {
         $select = $this->_db->select()
             ->from('zfproducts')
             ->order('2 DESC');
+        return $select;
+    }
+    
+    public function testSelectOrderByPositionDesc()
+    {
+        $select = $this->_selectOrderByPositionDesc();
 
         $stmt = $this->_db->query($select);
         $result = $stmt->fetchAll();
@@ -1271,11 +1289,17 @@ abstract class Zend_Db_Select_TestCommon extends Zend_Db_TestSetup
         $this->assertEquals(2, $result[2]['product_id']);
     }
 
-    public function testSelectOrderByMultiplePositions()
+    protected function _selectOrderByMultiplePositions()
     {
         $select = $this->_db->select()
             ->from('zfproducts')
             ->order(array('2 DESC', '1 DESC'));
+        return $select;
+    }
+    
+    public function testSelectOrderByMultiplePositions()
+    {
+        $select = $this->_selectOrderByMultiplePositions();
 
         $stmt = $this->_db->query($select);
         $result = $stmt->fetchAll();

+ 32 - 0
tests/Zend/Db/Table/Select/StaticTest.php

@@ -662,6 +662,38 @@ class Zend_Db_Table_Select_StaticTest extends Zend_Db_Select_TestCommon
         $sql = preg_replace('/\\s+/', ' ', $select->__toString());
         $this->assertEquals('SELECT "bug_id" AS "id", "bug_status" AS "name" FROM "zfbugs" UNION SELECT "product_id" AS "id", "product_name" AS "name" FROM "zfproducts" ORDER BY "id" ASC', $sql);
     }
+    
+    public function testSelectOrderByPosition()
+    {
+        $select = $this->_selectOrderByPosition(); 
+        
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 ASC', $sql);
+    }
+
+    public function testSelectOrderByPositionAsc()
+    {
+        $select = $this->_selectOrderByPositionAsc(); 
+        
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 ASC', $sql);
+    }
+
+    public function testSelectOrderByPositionDesc()
+    {
+        $select = $this->_selectOrderByPositionDesc();
+
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 DESC', $sql);
+    }
+
+    public function testSelectOrderByMultiplePositions()
+    {
+        $select = $this->_selectOrderByMultiplePositions();
+
+        $sql = preg_replace('/\\s+/', ' ', $select->__toString());
+        $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" ORDER BY 2 DESC, 1 DESC', $sql);
+    }
 
     public function getDriver()
     {