Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /** * @link https://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Soft..

Decoded Output download

<?php
/**
 * @link https://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license https://www.yiiframework.com/license/
 */

namespace yiiunitramework\data;

use yii\data\SqlDataProvider;
use yiiunitramework\db\DatabaseTestCase;

/**
 * @group data
 */
class SqlDataProviderTest extends DatabaseTestCase
{
    protected $driverName = 'sqlite';

    public function testGetModels()
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer`',
            'db' => $this->getConnection(),
        ]);
        $this->assertCount(3, $dataProvider->getModels());
    }

    public function testTotalCount()
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer`',
            'db' => $this->getConnection(),
        ]);
        $this->assertEquals(3, $dataProvider->getTotalCount());
    }

    public function testTotalCountWithParams()
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer` where id > :minimum',
            'params' => [
                ':minimum' => -1,
            ],
            'db' => $this->getConnection(),
        ]);
        $this->assertEquals(3, $dataProvider->getTotalCount());
    }

    public function providerForOrderByColumn()
    {
        return [
            'no marks' => ['name'],
            'no marks dot' => ['customer.name'],
            'mysql' => ['`name`'],
            'mysql dot' => ['`customer`.`name`'],
            'sqlite, pgsql, oracle, mysql ansi quotes' => ['"name"'],
            'sqlite, pgsql, oracle, mysql ansi quotes dot' => ['"customer"."name"'],
            'mssql' => ['[name]'],
            'mssql dot' => ['[customer].[name]'],
        ];
    }

    /**
     * @dataProvider providerForOrderByColumn
     * @see https://github.com/yiisoft/yii2/issues/18552
     */
    public function testRemovingOrderBy($column)
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer` order by ' . $column . ' desc',
            'db' => $this->getConnection(),
            'sort' => [
                'attributes' => ['email'],
                'params' => ['sort' => '-email']
            ],
        ]);
        $modelsSorted = $dataProvider->getModels();
        $this->assertSame('user3', $modelsSorted[0]['name']);
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php
/**
 * @link https://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license https://www.yiiframework.com/license/
 */

namespace yiiunit\framework\data;

use yii\data\SqlDataProvider;
use yiiunit\framework\db\DatabaseTestCase;

/**
 * @group data
 */
class SqlDataProviderTest extends DatabaseTestCase
{
    protected $driverName = 'sqlite';

    public function testGetModels()
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer`',
            'db' => $this->getConnection(),
        ]);
        $this->assertCount(3, $dataProvider->getModels());
    }

    public function testTotalCount()
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer`',
            'db' => $this->getConnection(),
        ]);
        $this->assertEquals(3, $dataProvider->getTotalCount());
    }

    public function testTotalCountWithParams()
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer` where id > :minimum',
            'params' => [
                ':minimum' => -1,
            ],
            'db' => $this->getConnection(),
        ]);
        $this->assertEquals(3, $dataProvider->getTotalCount());
    }

    public function providerForOrderByColumn()
    {
        return [
            'no marks' => ['name'],
            'no marks dot' => ['customer.name'],
            'mysql' => ['`name`'],
            'mysql dot' => ['`customer`.`name`'],
            'sqlite, pgsql, oracle, mysql ansi quotes' => ['"name"'],
            'sqlite, pgsql, oracle, mysql ansi quotes dot' => ['"customer"."name"'],
            'mssql' => ['[name]'],
            'mssql dot' => ['[customer].[name]'],
        ];
    }

    /**
     * @dataProvider providerForOrderByColumn
     * @see https://github.com/yiisoft/yii2/issues/18552
     */
    public function testRemovingOrderBy($column)
    {
        $dataProvider = new SqlDataProvider([
            'sql' => 'select * from `customer` order by ' . $column . ' desc',
            'db' => $this->getConnection(),
            'sort' => [
                'attributes' => ['email'],
                'params' => ['sort' => '-email']
            ],
        ]);
        $modelsSorted = $dataProvider->getModels();
        $this->assertSame('user3', $modelsSorted[0]['name']);
    }
}

Function Calls

None

Variables

None

Stats

MD5 b883356fdd37c16fd48f6da67f812e59
Eval Count 0
Decode Time 131 ms