Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ColumnsRendererTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class ColumnsRendererTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $model;
20 
24  protected $quoteMock;
25 
29  protected $selectMock;
30 
34  protected $sqlWildcard;
35 
41  protected function setUp()
42  {
43  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
44  $this->quoteMock = $this->createPartialMock(\Magento\Framework\DB\Platform\Quote::class, ['quoteColumnAs']);
45  $this->selectMock = $this->createPartialMock(\Magento\Framework\DB\Select::class, ['getPart']);
46  $this->model = $objectManager->getObject(
47  \Magento\Framework\DB\Select\ColumnsRenderer::class,
48  ['quote' => $this->quoteMock]
49  );
50  $this->sqlWildcard = new \Zend_Db_Expr(Select::SQL_WILDCARD);
51  }
52 
53  public function testRenderNotColumns()
54  {
55  $this->selectMock->expects($this->once())
56  ->method('getPart')
57  ->with(Select::COLUMNS)
58  ->willReturn([]);
59  $this->assertNull($this->model->render($this->selectMock));
60  }
61 
68  public function testRender($columns, $sql, $expectedResult)
69  {
70  $mapValues = [
71  ['column', null, '`column`'],
72  [['table', 'column'], null, '`table`.`column`'],
73  [['table', 'column'], 'alias', '`table`.`column` AS `alias`'],
74  ];
75  $this->quoteMock->expects($this->any())
76  ->method('quoteColumnAs')
77  ->willReturnMap($mapValues);
78  $this->selectMock->expects($this->exactly(2))
79  ->method('getPart')
80  ->with(Select::COLUMNS)
81  ->willReturn($columns);
82  $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
83  }
84 
88  public function renderDataProvider()
89  {
90  return [
91  [[['', 'column', null]], 'SELECT', 'SELECT `column`'],
92  [[['table', 'column', null]], 'SELECT', 'SELECT `table`.`column`'],
93  [[['table', 'column', 'alias']], 'SELECT', 'SELECT `table`.`column` AS `alias`'],
94  ];
95  }
96 }
$objectManager
Definition: bootstrap.php:17
$columns
Definition: default.phtml:15
const SQL_WILDCARD
Definition: Select.php:66
const COLUMNS
Definition: Select.php:48