Skip to content

Commit

Permalink
Merge pull request #469 from magento-troll/troll_bugfix
Browse files Browse the repository at this point in the history
MAGETWO-59144 [FT] Magento\ConfigurableProduct\Test\TestCase\CreateConfigurableProductEntityTest failed
MAGETWO-56052 MySQL triggers for Indexers not removed after upgrade from 2.0.7ce to 2.1ce
MAGETWO-59304 Test Magento\Test\Legacy\ModuleDBChangeTest:testModuleSetupFiles fails on developer branch
MAGETWO-56676 Related Products Target Rule not working
  • Loading branch information
rganin authored Oct 7, 2016
2 parents b4ab1f9 + 0fb698f commit c0f4002
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 20 deletions.
56 changes: 56 additions & 0 deletions app/code/Magento/Indexer/Setup/RecurringData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Indexer\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Indexer\Model\IndexerFactory;
use Magento\Framework\Indexer\ConfigInterface;

/**
* Recurring data upgrade for indexer module
*/
class RecurringData implements InstallDataInterface
{
/**
* @var IndexerFactory
*/
private $indexerFactory;

/**
* @var ConfigInterface
*/
private $configInterface;

/**
* RecurringData constructor.
*
* @param IndexerFactory $indexerFactory
* @param ConfigInterface $configInterface
*/
public function __construct(
IndexerFactory $indexerFactory,
ConfigInterface $configInterface
) {
$this->indexerFactory = $indexerFactory;
$this->configInterface = $configInterface;
}

/**
* {@inheritdoc}
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
foreach (array_keys($this->configInterface->getIndexers()) as $indexerId) {
$indexer = $this->indexerFactory->create()->load($indexerId);
if ($indexer->isScheduled()) {
$indexer->getView()->unsubscribe()->subscribe();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ public function getBindArgumentValue()
*/
public function getMappedSqlField()
{
if (!$this->isAttributeSetOrCategory()) {
if ($this->getAttribute() == 'sku') {
$mappedSqlField = 'e.sku';
} elseif (!$this->isAttributeSetOrCategory()) {
$mappedSqlField = $this->getEavAttributeTableAlias() . '.value';
} elseif ($this->getAttribute() == 'category_ids') {
$mappedSqlField = 'e.entity_id';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductPage" />
</variation>
<variation name="CreateConfigurableProductEntityTestVariation6" summary="Create Configurable Product with Creating New Category and New Attribute (Required Fields Only)" ticketId="MAGETWO-13361">
<data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test, stable:no</data>
<data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test</data>
<data name="product/data/configurable_attributes_data/dataset" xsi:type="string">two_searchable_options</data>
<data name="product/data/name" xsi:type="string">Configurable Product %isolation%</data>
<data name="product/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class ModuleDBChangeTest extends \PHPUnit_Framework_TestCase
*/
protected static $changedFileList = '';

/**
* @var string Path for Magento's composer.json
*/
protected static $composerFilePath = BP . '/composer.json';

/**
* @var bool Is tests executes on develop branch
*/
protected static $isOnDevVersion = false;

/**
* Set changed files paths and list for all projects
*/
Expand All @@ -30,13 +40,23 @@ public static function setUpBeforeClass()
foreach (glob(self::$changedFilesPattern) as $changedFile) {
self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL;
}

if (file_exists(self::$composerFilePath)) {
$jsonData = json_decode(file_get_contents(self::$composerFilePath));
if (substr((string) $jsonData->version, -4) == '-dev') {
self::$isOnDevVersion = true;
}
}
}

/**
* Test changes for module.xml files
*/
public function testModuleXmlFiles()
{
if (self::$isOnDevVersion) {
$this->markTestSkipped('This test isn\'t applicable to the developer version of Magento');
}
preg_match_all('|etc/module\.xml$|mi', self::$changedFileList, $matches);
$this->assertEmpty(
reset($matches),
Expand All @@ -50,6 +70,9 @@ public function testModuleXmlFiles()
*/
public function testModuleSetupFiles()
{
if (self::$isOnDevVersion) {
$this->markTestSkipped('This test isn\'t applicable to the developer version of Magento');
}
preg_match_all('|app/code/Magento/[^/]+/Setup/[^/]+$|mi', self::$changedFileList, $matches);
$this->assertEmpty(
reset($matches),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class SubscriptionTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->connectionMock = $this->getMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class, [], [], '', false);
$this->resourceMock = $this->getMock(
\Magento\Framework\App\ResourceConnection::class,
[],
[],
'',
false,
false
$this->resourceMock = $this->getMock(
\Magento\Framework\App\ResourceConnection::class,
[],
[],
'',
false,
false
);

$this->connectionMock->expects($this->any())
Expand All @@ -57,19 +57,19 @@ protected function setUp()
->method('getConnection')
->willReturn($this->connectionMock);

$this->triggerFactoryMock = $this->getMock(
$this->triggerFactoryMock = $this->getMock(
\Magento\Framework\DB\Ddl\TriggerFactory::class, [], [], '', false, false
);
$this->viewCollectionMock = $this->getMockForAbstractClass(
$this->viewCollectionMock = $this->getMockForAbstractClass(
\Magento\Framework\Mview\View\CollectionInterface::class, [], '', false, false, true, []
);
$this->viewMock = $this->getMockForAbstractClass(
$this->viewMock = $this->getMockForAbstractClass(
\Magento\Framework\Mview\ViewInterface::class, [], '', false, false, true, []
);

$this->resourceMock->expects($this->any())
->method('getTableName')
->willReturn($this->tableName);
->will($this->returnArgument(0));

$this->model = new Subscription(
$this->resourceMock,
Expand All @@ -96,11 +96,15 @@ public function testGetColumnName()
$this->assertEquals('columnName', $this->model->getColumnName());
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testCreate()
{
$triggerName = 'trigger_name';
$this->resourceMock->expects($this->atLeastOnce())->method('getTriggerName')->willReturn($triggerName);
$triggerMock = $this->getMockBuilder(\Magento\Framework\DB\Ddl\Trigger::class)
->setMethods(['setName', 'getName', 'setTime', 'setEvent', 'setTable', 'addStatement'])
->disableOriginalConstructor()
->getMock();
$triggerMock->expects($this->exactly(3))
Expand All @@ -121,11 +125,38 @@ public function testCreate()
->method('setTable')
->with($this->tableName)
->will($this->returnSelf());
$triggerMock->expects($this->exactly(6))

$triggerMock->expects($this->at(4))
->method('addStatement')
->with("INSERT IGNORE INTO test_view_cl (entity_id) VALUES (NEW.columnName);")
->will($this->returnSelf());

$triggerMock->expects($this->at(5))
->method('addStatement')
->with("INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (NEW.columnName);")
->will($this->returnSelf());

$triggerMock->expects($this->at(11))
->method('addStatement')
->with("INSERT IGNORE INTO test_view_cl (entity_id) VALUES (NEW.columnName);")
->will($this->returnSelf());

$triggerMock->expects($this->at(12))
->method('addStatement')
->with("INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (NEW.columnName);")
->will($this->returnSelf());

$triggerMock->expects($this->at(18))
->method('addStatement')
->with("INSERT IGNORE INTO test_view_cl (entity_id) VALUES (OLD.columnName);")
->will($this->returnSelf());

$triggerMock->expects($this->at(19))
->method('addStatement')
->with("INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (OLD.columnName);")
->will($this->returnSelf());

$changelogMock = $this->getMockForAbstractClass(
$changelogMock = $this->getMockForAbstractClass(
\Magento\Framework\Mview\View\ChangelogInterface::class, [], '', false, false, true, []
);
$changelogMock->expects($this->exactly(3))
Expand All @@ -143,7 +174,7 @@ public function testCreate()
->method('create')
->will($this->returnValue($triggerMock));

$otherChangelogMock = $this->getMockForAbstractClass(
$otherChangelogMock = $this->getMockForAbstractClass(
\Magento\Framework\Mview\View\ChangelogInterface::class, [], '', false, false, true, []
);
$otherChangelogMock->expects($this->exactly(3))
Expand All @@ -153,7 +184,7 @@ public function testCreate()
->method('getColumnName')
->will($this->returnValue('entity_id'));

$otherViewMock = $this->getMockForAbstractClass(
$otherViewMock = $this->getMockForAbstractClass(
\Magento\Framework\Mview\ViewInterface::class, [], '', false, false, true, []
);
$otherViewMock->expects($this->exactly(1))
Expand Down Expand Up @@ -216,7 +247,7 @@ public function testRemove()
->method('create')
->will($this->returnValue($triggerMock));

$otherChangelogMock = $this->getMockForAbstractClass(
$otherChangelogMock = $this->getMockForAbstractClass(
\Magento\Framework\Mview\View\ChangelogInterface::class, [], '', false, false, true, []
);
$otherChangelogMock->expects($this->exactly(3))
Expand All @@ -226,7 +257,7 @@ public function testRemove()
->method('getColumnName')
->will($this->returnValue('entity_id'));

$otherViewMock = $this->getMockForAbstractClass(
$otherViewMock = $this->getMockForAbstractClass(
\Magento\Framework\Mview\ViewInterface::class, [], '', false, false, true, []
);
$otherViewMock->expects($this->exactly(1))
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Mview/etc/mview.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<xs:simpleType name="subscriptionModelType">
<xs:annotation>
<xs:documentation>
Subscription model must be a valid PHP class or interface name.
DEPRECATED. Subscription model must be a valid PHP class or interface name.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
Expand Down

0 comments on commit c0f4002

Please sign in to comment.