コード例 #1
0
ファイル: DbTest.php プロジェクト: pradeep-wagento/magento2
 /**
  * @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Adapter\Pdo\Mysql
  */
 public function testSetAddOrder()
 {
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['fetchAll'], [], '', false);
     $this->collection->setConnection($adapter);
     $select = $this->collection->getSelect();
     $this->assertEmpty($select->getPart(\Magento\Framework\DB\Select::ORDER));
     /* Direct access to select object is available and many places are using it for sort order declaration */
     $select->order('select_field', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
     $this->collection->addOrder('some_field', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
     $this->collection->setOrder('other_field', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
     $this->collection->addOrder('other_field', \Magento\Framework\Data\Collection::SORT_ORDER_DESC);
     $this->collection->load();
     $selectOrders = $select->getPart(\Magento\Framework\DB\Select::ORDER);
     $this->assertEquals(['select_field', 'ASC'], array_shift($selectOrders));
     $this->assertEquals('some_field ASC', (string) array_shift($selectOrders));
     $this->assertEquals('other_field DESC', (string) array_shift($selectOrders));
     $this->assertEmpty(array_shift($selectOrders));
     return $adapter;
 }
コード例 #2
0
ファイル: AbstractCollection.php プロジェクト: nja78/magento2
 /**
  * Set sorting order
  *
  * Parameter $attribute can also be an array of attributes
  *
  * @param string|array $attribute
  * @param string $dir
  * @return $this
  */
 public function setOrder($attribute, $dir = self::SORT_ORDER_ASC)
 {
     if (is_array($attribute)) {
         foreach ($attribute as $attr) {
             parent::setOrder($attr, $dir);
         }
         return $this;
     }
     return parent::setOrder($attribute, $dir);
 }