Skip to content

Commit d595a13

Browse files
author
Oleksii Korshenko
authored
MAGETWO-88039: [Forwardport] Fix adding values to system variable collection #13735
2 parents e14f93b + 6e26280 commit d595a13

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

app/code/Magento/Variable/Model/ResourceModel/Variable/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function addValuesToResult()
6262
$this->getSelect()->join(
6363
['value_table' => $this->getTable('variable_value')],
6464
'value_table.variable_id = main_table.variable_id',
65-
['value_table.value']
65+
['value_table.plain_value', 'value_table.html_value']
6666
);
6767
$this->addFieldToFilter('value_table.store_id', ['eq' => $this->getStoreId()]);
6868
return $this;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/***
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Variable\Test\Unit\Model\ResourceModel\Variable;
8+
9+
use Magento\Framework\DB\Adapter\AdapterInterface;
10+
use Magento\Framework\DB\Select;
11+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Variable\Model\ResourceModel\Variable\Collection;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Provide tests for Variable collection class.
18+
*/
19+
class CollectionTest extends TestCase
20+
{
21+
/**
22+
* Test Collection::addValuesToResult() build correct query.
23+
*
24+
* @return void
25+
*/
26+
public function testAddValuesToResult()
27+
{
28+
$mainTableName = 'testMainTable';
29+
$tableName = 'variable_value';
30+
$field = 'value_table.store_id';
31+
32+
$select = $this->getMockBuilder(Select::class)
33+
->disableOriginalConstructor()
34+
->getMock();
35+
$select->expects($this->once())
36+
->method('from')
37+
->with($this->identicalTo(['main_table' => $mainTableName]))
38+
->willReturnSelf();
39+
$select->expects($this->once())
40+
->method('join')
41+
->with(
42+
$this->identicalTo(['value_table' => $tableName]),
43+
$this->identicalTo('value_table.variable_id = main_table.variable_id'),
44+
$this->identicalTo(['value_table.plain_value', 'value_table.html_value'])
45+
)->willReturnSelf();
46+
47+
$connection = $this->getMockBuilder(AdapterInterface::class)
48+
->disableOriginalConstructor()
49+
->setMethods(['select', 'prepareSqlCondition', 'quoteIdentifier'])
50+
->getMockForAbstractClass();
51+
$connection->expects($this->any())
52+
->method('select')
53+
->willReturn($select);
54+
$connection->expects($this->once())
55+
->method('quoteIdentifier')
56+
->with($this->identicalTo($field))
57+
->willReturn($field);
58+
$connection->expects($this->once())
59+
->method('prepareSqlCondition')
60+
->with(
61+
$this->identicalTo($field),
62+
$this->identicalTo(['eq' => 0])
63+
)->willReturn('testResultCondition');
64+
65+
$resource = $this->getMockBuilder(AbstractDb::class)
66+
->setMethods(['getTable', 'getMainTable', 'getConnection'])
67+
->disableOriginalConstructor()
68+
->getMockForAbstractClass();
69+
$resource->expects($this->any())
70+
->method('getConnection')
71+
->willReturn($connection);
72+
$resource->expects($this->once())
73+
->method('getMainTable')
74+
->willReturn('testMainTable');
75+
$resource->expects($this->exactly(2))
76+
->method('getTable')
77+
->withConsecutive(
78+
[$mainTableName],
79+
[$tableName]
80+
)->willReturnOnConsecutiveCalls(
81+
$mainTableName,
82+
$tableName
83+
);
84+
85+
$objectManager = new ObjectManager($this);
86+
$collection = $objectManager->getObject(
87+
Collection::class,
88+
[
89+
'resource' => $resource,
90+
]
91+
);
92+
$this->assertInstanceOf(Collection::class, $collection->addValuesToResult());
93+
}
94+
}

0 commit comments

Comments
 (0)