Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.3-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #17205: [Forwardport] Added unit test for DB model in backup module (by @torhoehn)
 - #17238: [Forwardport] Remove commented code (by @tiagosampaio)
 - #16805: [Forwardport] Fixed set template syntax in block file (by @gelanivishal)
 - #16853: [Forwardport] Corrected return message from ProductRuleTest.php (by @sanganinamrata)
 - #17215: [Forwardport] Correct return type of methods (by @mage2pratik)
 - #17197: [Forwardport] Fixed a grammatical error on the vault tooltip (by @mage2pratik)
 - #17208: [Forwardport] Fix misprint ('_requesetd' > '_requested') (by @torhoehn)


Fixed GitHub Issues:
 - #15345: Template syntax in block file (reported by @gelanivishal) has been fixed in #16805 by @gelanivishal in 2.3-develop branch
   Related commits:
     1. 98cc752
     2. 4499034
     3. b405dfa
  • Loading branch information
Stanislav Idolov authored Jul 29, 2018
2 parents fd076ae + 88a2b09 commit 137fcbf
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 31 deletions.
243 changes: 243 additions & 0 deletions app/code/Magento/Backup/Test/Unit/Model/DbTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backup\Test\Unit\Model;

use Magento\Backup\Model\Db;
use Magento\Backup\Model\ResourceModel\Db as DbResource;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Backup\Db\BackupInterface;
use Magento\Framework\DataObject;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class DbTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var Db
*/
private $dbModel;

/**
* @var DbResource|\PHPUnit_Framework_MockObject_MockObject
*/
private $dbResourceMock;

/**
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
*/
private $connectionResourceMock;

protected function setUp()
{
$this->dbResourceMock = $this->getMockBuilder(DbResource::class)
->disableOriginalConstructor()
->getMock();
$this->connectionResourceMock = $this->getMockBuilder(ResourceConnection::class)
->disableOriginalConstructor()
->getMock();

$this->objectManager = new ObjectManager($this);
$this->dbModel = $this->objectManager->getObject(
Db::class,
[
'resourceDb' => $this->dbResourceMock,
'resource' => $this->connectionResourceMock
]
);
}

public function testGetResource()
{
self::assertEquals($this->dbResourceMock, $this->dbModel->getResource());
}

public function testGetTables()
{
$tables = [];
$this->dbResourceMock->expects($this->once())
->method('getTables')
->willReturn($tables);

self::assertEquals($tables, $this->dbModel->getTables());
}

public function testGetTableCreateScript()
{
$tableName = 'some_table';
$script = 'script';
$this->dbResourceMock->expects($this->once())
->method('getTableCreateScript')
->with($tableName, false)
->willReturn($script);

self::assertEquals($script, $this->dbModel->getTableCreateScript($tableName, false));
}

public function testGetTableDataDump()
{
$tableName = 'some_table';
$dump = 'dump';
$this->dbResourceMock->expects($this->once())
->method('getTableDataDump')
->with($tableName)
->willReturn($dump);

self::assertEquals($dump, $this->dbModel->getTableDataDump($tableName));
}

public function testGetHeader()
{
$header = 'header';
$this->dbResourceMock->expects($this->once())
->method('getHeader')
->willReturn($header);

self::assertEquals($header, $this->dbModel->getHeader());
}

public function testGetFooter()
{
$footer = 'footer';
$this->dbResourceMock->expects($this->once())
->method('getFooter')
->willReturn($footer);

self::assertEquals($footer, $this->dbModel->getFooter());
}

public function testRenderSql()
{
$header = 'header';
$script = 'script';
$tableName = 'some_table';
$tables = [$tableName, $tableName];
$dump = 'dump';
$footer = 'footer';

$this->dbResourceMock->expects($this->once())
->method('getTables')
->willReturn($tables);
$this->dbResourceMock->expects($this->once())
->method('getHeader')
->willReturn($header);
$this->dbResourceMock->expects($this->exactly(2))
->method('getTableCreateScript')
->with($tableName, true)
->willReturn($script);
$this->dbResourceMock->expects($this->exactly(2))
->method('getTableDataDump')
->with($tableName)
->willReturn($dump);
$this->dbResourceMock->expects($this->once())
->method('getFooter')
->willReturn($footer);

self::assertEquals(
$header . $script . $dump . $script . $dump . $footer,
$this->dbModel->renderSql()
);
}

public function testCreateBackup()
{
/** @var BackupInterface|\PHPUnit_Framework_MockObject_MockObject $backupMock */
$backupMock = $this->getMockBuilder(BackupInterface::class)->getMock();
/** @var DataObject $tableStatus */
$tableStatus = new DataObject();

$tableName = 'some_table';
$tables = [$tableName];
$header = 'header';
$footer = 'footer';
$dropSql = 'drop_sql';
$createSql = 'create_sql';
$beforeSql = 'before_sql';
$afterSql = 'after_sql';
$dataSql = 'data_sql';
$foreignKeysSql = 'foreign_keys';
$triggersSql = 'triggers_sql';
$rowsCount = 2;
$dataLength = 1;

$this->dbResourceMock->expects($this->once())
->method('beginTransaction');
$this->dbResourceMock->expects($this->once())
->method('commitTransaction');
$this->dbResourceMock->expects($this->once())
->method('getTables')
->willReturn($tables);
$this->dbResourceMock->expects($this->once())
->method('getTableDropSql')
->willReturn($dropSql);
$this->dbResourceMock->expects($this->once())
->method('getTableCreateSql')
->with($tableName, false)
->willReturn($createSql);
$this->dbResourceMock->expects($this->once())
->method('getTableDataBeforeSql')
->with($tableName)
->willReturn($beforeSql);
$this->dbResourceMock->expects($this->once())
->method('getTableDataAfterSql')
->with($tableName)
->willReturn($afterSql);
$this->dbResourceMock->expects($this->once())
->method('getTableDataSql')
->with($tableName, $rowsCount, 0)
->willReturn($dataSql);
$this->dbResourceMock->expects($this->once())
->method('getTableStatus')
->with($tableName)
->willReturn($tableStatus);
$this->dbResourceMock->expects($this->once())
->method('getTables')
->willReturn($createSql);
$this->dbResourceMock->expects($this->once())
->method('getHeader')
->willReturn($header);
$this->dbResourceMock->expects($this->once())
->method('getTableHeader')
->willReturn($header);
$this->dbResourceMock->expects($this->once())
->method('getFooter')
->willReturn($footer);
$this->dbResourceMock->expects($this->once())
->method('getTableForeignKeysSql')
->willReturn($foreignKeysSql);
$this->dbResourceMock->expects($this->once())
->method('getTableTriggersSql')
->willReturn($triggersSql);
$backupMock->expects($this->once())
->method('open');
$backupMock->expects($this->once())
->method('close');

$tableStatus->setRows($rowsCount);
$tableStatus->setDataLength($dataLength);

$backupMock->expects($this->any())
->method('write')
->withConsecutive(
[$this->equalTo($header)],
[$this->equalTo($header . $dropSql . "\n")],
[$this->equalTo($createSql . "\n")],
[$this->equalTo($beforeSql)],
[$this->equalTo($dataSql)],
[$this->equalTo($afterSql)],
[$this->equalTo($foreignKeysSql)],
[$this->equalTo($triggersSql)],
[$this->equalTo($footer)]
);

$this->dbModel->createBackup($backupMock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</span>
<div class="field-tooltip-content"
data-target="dropdown"
translate="'We store you payment information securely on Braintree servers via SSL.'"></div>
translate="'We store your payment information securely on Braintree servers via SSL.'"></div>
</div>
</div>
<!-- /ko -->
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Controller/Category/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function __construct(
/**
* Initialize requested category object
*
* @return \Magento\Catalog\Model\Category
* @return \Magento\Catalog\Model\Category|bool
*/
protected function _initCategory()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private function getProductEmulator($typeId)
* @param array $indexData
* @param array $productData
* @param int $storeId
* @return string
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @since 100.0.3
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function processAttributeValue($attribute, $value);
*
* @param array $index
* @param string $separator
* @return string
* @return array
*/
public function prepareEntityIndex($index, $separator = ' ');
}
2 changes: 1 addition & 1 deletion app/code/Magento/Integration/Test/Unit/Oauth/OauthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public function testGetAccessTokenVerifierInvalid($verifier, $verifierFromToken)
public function dataProviderForGetAccessTokenVerifierInvalidTest()
{
// Verifier is not a string
return [[3, 3], ['wrong_length', 'wrong_length'], ['verifier', 'doesnt match']];
return [[3, 3], ['wrong_length', 'wrong_length'], ['verifier', 'doesn\'t match']];
}

public function testGetAccessToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ApiWizard extends \Magento\Config\Block\System\Config\Form\Field
/**
* Path to block template
*/
const WIZARD_TEMPLATE = 'system/config/api_wizard.phtml';
const WIZARD_TEMPLATE = 'Magento_Paypal::system/config/api_wizard.phtml';

/**
* Set template to itself
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BmlApiWizard extends ApiWizard
/**
* Path to block template
*/
const WIZARD_TEMPLATE = 'system/config/bml_api_wizard.phtml';
const WIZARD_TEMPLATE = 'Magento_Paypal::system/config/bml_api_wizard.phtml';

/**
* Get the button and scripts contents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public function setStoreFilter($storeId)
'main_table.rating_id = store.rating_id',
[]
);
// ->group('main_table.rating_id')
$this->_isStoreJoined = true;
}
$inCondition = $connection->prepareSqlCondition('store.store_id', ['in' => $storeId]);
Expand Down
7 changes: 0 additions & 7 deletions app/code/Magento/Sales/Model/Order/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,6 @@ public function getStateName($stateId = null)
*/
public function setShippingAmount($amount)
{
// base shipping amount calculated in total model
// $amount = $this->getStore()->round($amount);
// $this->setData('base_shipping_amount', $amount);
//
// $amount = $this->getStore()->round(
// $amount*$this->getOrder()->getStoreToOrderRate()
// );
return $this->setData(CreditmemoInterface::SHIPPING_AMOUNT, $amount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define([

Element = _.extend({
defaults: {
_requesetd: {},
_requested: {},
containers: [],
exports: {},
imports: {},
Expand Down Expand Up @@ -249,7 +249,7 @@ define([
* @returns {Function} Async module wrapper.
*/
requestModule: function (name) {
var requested = this._requesetd;
var requested = this._requested;

if (!requested[name]) {
requested[name] = registry.async(name);
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/User/Block/Role/Tab/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ protected function _construct()
$roleId = $this->getRequest()->getParam('rid', false);
/** @var \Magento\User\Model\ResourceModel\User\Collection $users */
$users = $this->_userCollectionFactory->create()->load();
$this->setTemplate('role/users.phtml')->assign('users', $users->getItems())->assign('roleId', $roleId);
$this->setTemplate('role/users.phtml')
->assign('users', $users->getItems())
->assign('roleId', $roleId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,6 @@ public function getOnchange($value)
return;
}

// public function getName($value)
// {
// if ($name = $this->getData('name')) {
// return str_replace('$value', $value, $name);
// }
// return ;
// }

/**
* @param array $option
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function force($entityType, $identifier)

if (!isset($sequenceInfo['sequenceTable'])) {
throw new \Exception(
'TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesnt exists'
'TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesn\'t exists'
);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public function delete($entityType, $identifier)
$metadata = $this->metadataPool->getMetadata($entityType);
$sequenceInfo = $this->sequenceRegistry->retrieve($entityType);
if (!isset($sequenceInfo['sequenceTable'])) {
throw new \Exception('TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesnt exists');
throw new \Exception('TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesn\'t exists');
}
try {
$connection = $this->appResource->getConnectionByName($metadata->getEntityConnectionName());
Expand Down
Loading

0 comments on commit 137fcbf

Please sign in to comment.