Skip to content

Commit

Permalink
MAGETWO-57943: [Backport] - [GITHUB] Magento 2.0.x and 2.1.x does not…
Browse files Browse the repository at this point in the history
… respect table prefix during installation #5688 - for 2.1
  • Loading branch information
viktym committed Sep 2, 2016
1 parent 9703d00 commit 2f6f4d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
9 changes: 7 additions & 2 deletions setup/src/Magento/Setup/Module/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Setup extends \Magento\Framework\Module\Setup implements SchemaSetupInterf
*/
public function getIdxName($tableName, $fields, $indexType = '')
{
return $this->getConnection()->getIndexName($tableName, $fields, $indexType);
return $this->getConnection()->getIndexName($this->getTable($tableName), $fields, $indexType);
}

/**
Expand All @@ -33,6 +33,11 @@ public function getIdxName($tableName, $fields, $indexType = '')
*/
public function getFkName($priTableName, $priColumnName, $refTableName, $refColumnName)
{
return $this->getConnection()->getForeignKeyName($priTableName, $priColumnName, $refTableName, $refColumnName);
return $this->getConnection()->getForeignKeyName(
$this->getTable($priTableName),
$priColumnName,
$refTableName,
$refColumnName
);
}
}
28 changes: 23 additions & 5 deletions setup/src/Magento/Setup/Test/Unit/Module/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Setup\Test\Unit\Module;

use \Magento\Setup\Module\Setup;
use Magento\Framework\App\ResourceConnection;
use Magento\Setup\Module\Setup;

/**
* Class SetupTest
*/
class SetupTest extends \PHPUnit_Framework_TestCase
{
const CONNECTION_NAME = 'connection';
Expand All @@ -22,15 +25,20 @@ class SetupTest extends \PHPUnit_Framework_TestCase
*/
private $setup;

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

protected function setUp()
{
$resourceModel = $this->getMock('\Magento\Framework\App\ResourceConnection', [], [], '', false);
$this->resourceModelMock = $this->getMock('\Magento\Framework\App\ResourceConnection', [], [], '', false);
$this->connection = $this->getMockForAbstractClass('\Magento\Framework\DB\Adapter\AdapterInterface');
$resourceModel->expects($this->any())
$this->resourceModelMock->expects($this->any())
->method('getConnection')
->with(self::CONNECTION_NAME)
->will($this->returnValue($this->connection));
$this->setup = new Setup($resourceModel, self::CONNECTION_NAME);
$this->setup = new Setup($this->resourceModelMock, self::CONNECTION_NAME);
}

public function testGetIdxName()
Expand All @@ -40,6 +48,11 @@ public function testGetIdxName()
$indexType = 'index_type';
$expectedIdxName = 'idxName';

$this->resourceModelMock->expects($this->once())
->method('getTableName')
->with($tableName)
->will($this->returnValue($tableName));

$this->connection->expects($this->once())
->method('getIndexName')
->with($tableName, $fields, $indexType)
Expand All @@ -55,6 +68,11 @@ public function testGetFkName()
$columnName = 'columnName';
$refColumnName = 'refColumnName';

$this->resourceModelMock->expects($this->once())
->method('getTableName')
->with($tableName)
->will($this->returnValue($tableName));

$this->connection->expects($this->once())
->method('getForeignKeyName')
->with($tableName, $columnName, $refTable, $refColumnName)
Expand Down

0 comments on commit 2f6f4d6

Please sign in to comment.