diff --git a/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php b/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php index 03ed66f29abec3ebd79735f648aefcd633dc44cc..073d23f450a795d81231a4268bc3dece788a784f 100644 --- a/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php +++ b/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php @@ -31,12 +31,19 @@ abstract class AbstractElement implements ElementInterface */ protected $_storeManager; + /** + * @var \Magento\Framework\Module\Manager + */ + protected $moduleManager; + /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Module\Manager $moduleManager */ - public function __construct(StoreManagerInterface $storeManager) + public function __construct(StoreManagerInterface $storeManager, \Magento\Framework\Module\Manager $moduleManager) { $this->_storeManager = $storeManager; + $this->moduleManager = $moduleManager; } /** @@ -134,6 +141,10 @@ abstract class AbstractElement implements ElementInterface */ public function isVisible() { + if (isset($this->_data['if_module_enabled']) && + !$this->moduleManager->isOutputEnabled($this->_data['if_module_enabled'])) { + return false; + } $showInScope = [ \Magento\Store\Model\ScopeInterface::SCOPE_STORE => $this->_hasVisibilityValue('showInStore'), \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE => $this->_hasVisibilityValue('showInWebsite'), diff --git a/app/code/Magento/Config/Model/Config/Structure/Element/AbstractComposite.php b/app/code/Magento/Config/Model/Config/Structure/Element/AbstractComposite.php index a25b1688eea4e08951ea0d082f3d1de0572bd16d..d3707277d55951867088dcda4e96f73b2c3b643e 100644 --- a/app/code/Magento/Config/Model/Config/Structure/Element/AbstractComposite.php +++ b/app/code/Magento/Config/Model/Config/Structure/Element/AbstractComposite.php @@ -16,13 +16,15 @@ abstract class AbstractComposite extends \Magento\Config\Model\Config\Structure\ /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Module\Manager $moduleManager * @param Iterator $childrenIterator */ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Module\Manager $moduleManager, Iterator $childrenIterator ) { - parent::__construct($storeManager); + parent::__construct($storeManager, $moduleManager); $this->_childrenIterator = $childrenIterator; } diff --git a/app/code/Magento/Config/Model/Config/Structure/Element/Field.php b/app/code/Magento/Config/Model/Config/Structure/Element/Field.php index 5d7d5d1e329a1e58dae95a030c1041d9de3b4c8a..8f218a34f02296157738514729562ede40cf32b8 100644 --- a/app/code/Magento/Config/Model/Config/Structure/Element/Field.php +++ b/app/code/Magento/Config/Model/Config/Structure/Element/Field.php @@ -50,21 +50,23 @@ class Field extends \Magento\Config\Model\Config\Structure\AbstractElement /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Module\Manager $moduleManager * @param \Magento\Config\Model\Config\BackendFactory $backendFactory * @param \Magento\Config\Model\Config\SourceFactory $sourceFactory * @param \Magento\Config\Model\Config\CommentFactory $commentFactory * @param \Magento\Framework\View\Element\BlockFactory $blockFactory - * @param \Magento\Config\Model\Config\Structure\Element\Dependency\Mapper $dependencyMapper + * @param Dependency\Mapper $dependencyMapper */ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Module\Manager $moduleManager, \Magento\Config\Model\Config\BackendFactory $backendFactory, \Magento\Config\Model\Config\SourceFactory $sourceFactory, \Magento\Config\Model\Config\CommentFactory $commentFactory, \Magento\Framework\View\Element\BlockFactory $blockFactory, \Magento\Config\Model\Config\Structure\Element\Dependency\Mapper $dependencyMapper ) { - parent::__construct($storeManager); + parent::__construct($storeManager, $moduleManager); $this->_backendFactory = $backendFactory; $this->_sourceFactory = $sourceFactory; $this->_commentFactory = $commentFactory; diff --git a/app/code/Magento/Config/Model/Config/Structure/Element/Group.php b/app/code/Magento/Config/Model/Config/Structure/Element/Group.php index 3c1028812a6bef52222847c912585dc141877257..7e523248c3e3fd0b78b572ed67e5301faea305bc 100644 --- a/app/code/Magento/Config/Model/Config/Structure/Element/Group.php +++ b/app/code/Magento/Config/Model/Config/Structure/Element/Group.php @@ -25,17 +25,19 @@ class Group extends AbstractComposite /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Config\Model\Config\Structure\Element\Iterator\Field $childrenIterator + * @param \Magento\Framework\Module\Manager $moduleManager + * @param Iterator\Field $childrenIterator * @param \Magento\Config\Model\Config\BackendClone\Factory $cloneModelFactory - * @param \Magento\Config\Model\Config\Structure\Element\Dependency\Mapper $dependencyMapper + * @param Dependency\Mapper $dependencyMapper */ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Module\Manager $moduleManager, \Magento\Config\Model\Config\Structure\Element\Iterator\Field $childrenIterator, \Magento\Config\Model\Config\BackendClone\Factory $cloneModelFactory, \Magento\Config\Model\Config\Structure\Element\Dependency\Mapper $dependencyMapper ) { - parent::__construct($storeManager, $childrenIterator); + parent::__construct($storeManager, $moduleManager, $childrenIterator); $this->_cloneModelFactory = $cloneModelFactory; $this->_dependencyMapper = $dependencyMapper; } diff --git a/app/code/Magento/Config/Model/Config/Structure/Element/Section.php b/app/code/Magento/Config/Model/Config/Structure/Element/Section.php index f8839b215d3dc014b4bee149098e82bfb889ef0f..46696967d31f1c0a11cea6a3fb1d4fde061ad8cd 100644 --- a/app/code/Magento/Config/Model/Config/Structure/Element/Section.php +++ b/app/code/Magento/Config/Model/Config/Structure/Element/Section.php @@ -16,15 +16,17 @@ class Section extends AbstractComposite /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Module\Manager $moduleManager * @param Iterator $childrenIterator * @param \Magento\Framework\AuthorizationInterface $authorization */ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Module\Manager $moduleManager, Iterator $childrenIterator, \Magento\Framework\AuthorizationInterface $authorization ) { - parent::__construct($storeManager, $childrenIterator); + parent::__construct($storeManager, $moduleManager, $childrenIterator); $this->_authorization = $authorization; } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php index 778141ab2132096aa8d0e750f7175bebdcea935b..90e0d13c3e60d1c688ffcdf4a152c8dba3c1439c 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php @@ -17,24 +17,33 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $_storeManager; + protected $storeManagerMock; + + /** + * @var \Magento\Config\Model\Config\Structure\AbstractElement | \PHPUnit_Framework_MockObject_MockObject + */ + protected $moduleManagerMock; protected function setUp() { - $this->_storeManager = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $this->moduleManagerMock = $this->getMock( + 'Magento\Framework\Module\Manager', + ['isOutputEnabled'], + [], + '', + false + ); $this->_model = $this->getMockForAbstractClass( 'Magento\Config\Model\Config\Structure\AbstractElement', - [$this->_storeManager] + [ + 'storeManager' => $this->storeManagerMock, + 'moduleManager' => $this->moduleManagerMock, + ] ); } - protected function tearDown() - { - unset($this->_model); - unset($this->_storeManager); - } - public function testGetId() { $this->assertEquals('', $this->_model->getId()); @@ -76,7 +85,7 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase public function testIsVisibleReturnsTrueInSingleStoreModeForNonHiddenElements() { - $this->_storeManager->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); + $this->storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->_model->setData( ['showInDefault' => 1, 'showInStore' => 0, 'showInWebsite' => 0], ScopeConfigInterface::SCOPE_TYPE_DEFAULT @@ -86,7 +95,7 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase public function testIsVisibleReturnsFalseInSingleStoreModeForHiddenElements() { - $this->_storeManager->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); + $this->storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->_model->setData( ['hide_in_single_store_mode' => 1, 'showInDefault' => 1, 'showInStore' => 0, 'showInWebsite' => 0], ScopeConfigInterface::SCOPE_TYPE_DEFAULT @@ -99,7 +108,7 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase */ public function testIsVisibleReturnsFalseInSingleStoreModeForInvisibleElements() { - $this->_storeManager->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); + $this->storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->_model->setData( ['showInDefault' => 0, 'showInStore' => 0, 'showInWebsite' => 0], ScopeConfigInterface::SCOPE_TYPE_DEFAULT @@ -165,6 +174,25 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase ]; } + public function testIsVisibleReturnFalseIfModuleNotEnabled() + { + $this->moduleManagerMock->expects($this->once()) + ->method('isOutputEnabled') + ->with('test_module') + ->willReturn(false); + $this->_model->setData( + [ + 'showInDefault' => 1, + 'showInStore' => 0, + 'showInWebsite' => 0, + 'if_module_enabled' => 'test_module', + ], + 'default' + ); + $this->assertFalse($this->_model->isVisible()); + + } + public function testGetClass() { $this->assertEquals('', $this->_model->getClass()); diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/AbstractCompositeTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/AbstractCompositeTest.php index 08831a5a364b0f6d3ab9317461f73ca9bd339834..555e59eac7acb95674ebc045324459c7344b3330 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/AbstractCompositeTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/AbstractCompositeTest.php @@ -22,6 +22,11 @@ class AbstractCompositeTest extends \PHPUnit_Framework_TestCase */ protected $_iteratorMock; + /** + * @var \Magento\Framework\Module\Manager | \PHPUnit_Framework_MockObject_MockObject + */ + protected $moduleManagerMock; + /** * Test element data * @@ -44,10 +49,10 @@ class AbstractCompositeTest extends \PHPUnit_Framework_TestCase false ); $this->_storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); - + $this->moduleManagerMock = $this->getMock('Magento\Framework\Module\Manager', [], [], '', false); $this->_model = $this->getMockForAbstractClass( 'Magento\Config\Model\Config\Structure\Element\AbstractComposite', - [$this->_storeManagerMock, $this->_iteratorMock] + [$this->_storeManagerMock, $this->moduleManagerMock, $this->_iteratorMock] ); } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/FieldTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/FieldTest.php index bd752f99703a90442d0627423802f7f2f041179b..b20518c411f9eead5bb8adc8de28e1e27da0abc3 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/FieldTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/FieldTest.php @@ -10,6 +10,8 @@ namespace Magento\Config\Test\Unit\Model\Config\Structure\Element; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + class FieldTest extends \PHPUnit_Framework_TestCase { const FIELD_TEST_CONSTANT = "field test constant"; @@ -19,11 +21,6 @@ class FieldTest extends \PHPUnit_Framework_TestCase */ protected $_model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_storeManagerMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -49,21 +46,10 @@ class FieldTest extends \PHPUnit_Framework_TestCase */ protected $_depMapperMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_iteratorMock; - protected function setUp() { - $this->_iteratorMock = $this->getMock( - 'Magento\Config\Model\Config\Structure\Element\Iterator', - [], - [], - '', - false - ); - $this->_storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $objectManager = new ObjectManager($this); + $this->_backendFactoryMock = $this->getMock( 'Magento\Config\Model\Config\BackendFactory', [], @@ -100,20 +86,20 @@ class FieldTest extends \PHPUnit_Framework_TestCase false ); - $this->_model = new \Magento\Config\Model\Config\Structure\Element\Field( - $this->_storeManagerMock, - $this->_backendFactoryMock, - $this->_sourceFactoryMock, - $this->_commentFactoryMock, - $this->_blockFactoryMock, - $this->_depMapperMock + $this->_model = $objectManager->getObject( + 'Magento\Config\Model\Config\Structure\Element\Field', + [ + 'backendFactory' => $this->_backendFactoryMock, + 'sourceFactory' => $this->_sourceFactoryMock, + 'commentFactory' => $this->_commentFactoryMock, + 'blockFactory' => $this->_blockFactoryMock, + 'dependencyMapper' => $this->_depMapperMock, + ] ); } protected function tearDown() { - unset($this->_iteratorMock); - unset($this->_storeManagerMock); unset($this->_backendFactoryMock); unset($this->_sourceFactoryMock); unset($this->_commentFactoryMock); diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/GroupTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/GroupTest.php index b92a76069ec3ec6396ff0e3c8ac58fd33fbea6b3..5490eaa0a07cb308c1df02e4751e346e840e4666 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/GroupTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/GroupTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Config\Test\Unit\Model\Config\Structure\Element; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + class GroupTest extends \PHPUnit_Framework_TestCase { /** @@ -12,21 +14,11 @@ class GroupTest extends \PHPUnit_Framework_TestCase */ protected $_model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_storeManagerMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ protected $_cloneFactoryMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_iteratorMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -34,14 +26,7 @@ class GroupTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->_iteratorMock = $this->getMock( - 'Magento\Config\Model\Config\Structure\Element\Iterator\Field', - [], - [], - '', - false - ); - $this->_storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $objectManager = new ObjectManager($this); $this->_cloneFactoryMock = $this->getMock( 'Magento\Config\Model\Config\BackendClone\Factory', [], @@ -57,19 +42,18 @@ class GroupTest extends \PHPUnit_Framework_TestCase false ); - $this->_model = new \Magento\Config\Model\Config\Structure\Element\Group( - $this->_storeManagerMock, - $this->_iteratorMock, - $this->_cloneFactoryMock, - $this->_depMapperMock + $this->_model = $objectManager->getObject( + 'Magento\Config\Model\Config\Structure\Element\Group', + [ + 'cloneModelFactory' => $this->_cloneFactoryMock, + 'dependencyMapper' => $this->_depMapperMock, + ] ); } protected function tearDown() { unset($this->_model); - unset($this->_iteratorMock); - unset($this->_storeManagerMock); unset($this->_cloneFactoryMock); unset($this->_depMapperMock); } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/SectionTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/SectionTest.php index 86812767f156adfaee9faddd74689b05bb31511f..a14a1e4ad22ba73fd3e0596838b1668dafa3b294 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/SectionTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/SectionTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Config\Test\Unit\Model\Config\Structure\Element; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + class SectionTest extends \PHPUnit_Framework_TestCase { /** @@ -22,34 +24,24 @@ class SectionTest extends \PHPUnit_Framework_TestCase */ protected $_authorizationMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_iteratorMock; - protected function setUp() { - $this->_iteratorMock = $this->getMock( - 'Magento\Config\Model\Config\Structure\Element\Iterator\Field', - [], - [], - '', - false - ); + $objectManager = new ObjectManager($this); $this->_storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $this->_authorizationMock = $this->getMock('Magento\Framework\AuthorizationInterface'); - $this->_model = new \Magento\Config\Model\Config\Structure\Element\Section( - $this->_storeManagerMock, - $this->_iteratorMock, - $this->_authorizationMock + $this->_model = $objectManager->getObject( + 'Magento\Config\Model\Config\Structure\Element\Section', + [ + 'storeManager' => $this->_storeManagerMock, + 'authorization' => $this->_authorizationMock, + ] ); } protected function tearDown() { unset($this->_model); - unset($this->_iteratorMock); unset($this->_storeManagerMock); unset($this->_authorizationMock); } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/TabTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/TabTest.php index d8c9af76865c5c78f112c5fa8bae83b0a3812c16..248cc3c18ffb33654d534f6dc045587ec8c1cdc7 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/TabTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/TabTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Config\Test\Unit\Model\Config\Structure\Element; +use \Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + class TabTest extends \PHPUnit_Framework_TestCase { /** @@ -12,11 +14,6 @@ class TabTest extends \PHPUnit_Framework_TestCase */ protected $_model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_storeManagerMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -31,11 +28,10 @@ class TabTest extends \PHPUnit_Framework_TestCase '', false ); - $this->_storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); - $this->_model = new \Magento\Config\Model\Config\Structure\Element\Tab( - $this->_storeManagerMock, - $this->_iteratorMock + $this->_model = (new ObjectManager($this))->getObject( + 'Magento\Config\Model\Config\Structure\Element\Tab', + ['childrenIterator' => $this->_iteratorMock] ); } @@ -43,7 +39,6 @@ class TabTest extends \PHPUnit_Framework_TestCase { unset($this->_model); unset($this->_iteratorMock); - unset($this->_storeManagerMock); } public function testIsVisibleOnlyChecksPresenceOfChildren() diff --git a/app/code/Magento/Tax/Model/ResourceModel/Calculation.php b/app/code/Magento/Tax/Model/ResourceModel/Calculation.php index 54a76ba286a14b0c78ad720a2b2485555ae71793..b9fbdc230fd581466f1820340d6d048dae0826ca 100644 --- a/app/code/Magento/Tax/Model/ResourceModel/Calculation.php +++ b/app/code/Magento/Tax/Model/ResourceModel/Calculation.php @@ -24,13 +24,6 @@ class Calculation extends \Magento\Framework\Model\ModelResource\Db\AbstractDb */ protected $_ratesCache = []; - /** - * Primary key auto increment flag - * - * @var bool - */ - protected $_isPkAutoIncrement = false; - /** * Tax data * diff --git a/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/FormTest.php b/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/FormTest.php index cc545e0b5537bd4025c7fa2aba8f0113d49cb51b..d1bd13f74a1885c3289c8673beb0cb2691203f28 100644 --- a/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/FormTest.php +++ b/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/FormTest.php @@ -75,19 +75,21 @@ class FormTest extends \PHPUnit_Framework_TestCase /** * @covers \Magento\Config\Block\System\Config\Form::initFields - * @param bool $useConfigField uses the test_field_use_config field if true + * @param string $fieldId uses the test_field_use_config field if true * @param bool $isConfigDataEmpty if the config data array should be empty or not - * @param $configDataValue the value that the field path should be set to in the config data + * @param string $configDataValue The value that the field path should be set to in the config data + * @param int $valueSelCtr Number of time that value is selected * @param bool $expectedUseDefault * @dataProvider initFieldsUseDefaultCheckboxDataProvider */ public function testInitFieldsUseDefaultCheckbox( - $useConfigField, + $fieldId, $isConfigDataEmpty, $configDataValue, - $expectedUseDefault + $expectedUseDefault, + $valueSelCtr = 1 ) { - $this->_setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmpty, $configDataValue); + $this->_setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue); \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( 'Magento\Framework\Config\ScopeInterface' @@ -126,12 +128,17 @@ class FormTest extends \PHPUnit_Framework_TestCase $fieldsetHtml = $fieldset->getElementHtml(); $this->assertSelectCount($fieldsetSel, true, $fieldsetHtml, 'Fieldset HTML is invalid'); - $this->assertSelectCount($valueSel, true, $fieldsetHtml, 'Field input not found in fieldset HTML'); + $this->assertSelectCount( + $valueSel, + $valueSelCtr, + $fieldsetHtml, + 'Field input should appear ' . $valueSelCtr . ' times in fieldset HTML' + ); $this->assertSelectCount( $useDefaultSel, - true, + $valueSelCtr, $fieldsetHtml, - '"Use Default" checkbox not found in fieldset HTML' + '"Use Default" checkbox should appear' . $valueSelCtr . ' times in fieldset HTML.' ); if ($expectedUseDefault) { @@ -159,25 +166,27 @@ class FormTest extends \PHPUnit_Framework_TestCase public static function initFieldsUseDefaultCheckboxDataProvider() { return [ - [false, true, null, true], - [false, false, null, false], - [false, false, '', false], - [false, false, 'value', false], - [true, false, 'config value', false] + ['test_field', true, null, true], + ['test_field', false, null, false], + ['test_field', false, '', false], + ['test_field', false, 'value', false], + ['test_field_use_config_module_1', false, 'config value', false], + ['test_field_use_config_module_0', false, 'config value', false, 0], ]; } /** * @covers \Magento\Config\Block\System\Config\Form::initFields - * @param bool $useConfigField uses the test_field_use_config field if true + * @param string $fieldId uses the test_field_use_config field if true * @param bool $isConfigDataEmpty if the config data array should be empty or not - * @param $configDataValue the value that the field path should be set to in the config data + * @param string $configDataValue Value that the field path should be set to in the config data + * @param int $valueSelCtr Number of time that value is selected * @dataProvider initFieldsUseConfigPathDataProvider * @magentoConfigFixture default/test_config_section/test_group_config_node/test_field_value config value */ - public function testInitFieldsUseConfigPath($useConfigField, $isConfigDataEmpty, $configDataValue) + public function testInitFieldsUseConfigPath($fieldId, $isConfigDataEmpty, $configDataValue, $valueSelCtr = 1) { - $this->_setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmpty, $configDataValue); + $this->_setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue); \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( 'Magento\Framework\Config\ScopeInterface' @@ -208,7 +217,12 @@ class FormTest extends \PHPUnit_Framework_TestCase $fieldsetHtml = $fieldset->getElementHtml(); $this->assertSelectCount($fieldsetSel, true, $fieldsetHtml, 'Fieldset HTML is invalid'); - $this->assertSelectCount($valueSel, true, $fieldsetHtml, 'Field input not found in fieldset HTML'); + $this->assertSelectCount( + $valueSel, + $valueSelCtr, + $fieldsetHtml, + 'Field input should appear ' . $valueSelCtr . ' times in fieldset HTML' + ); } /** @@ -217,20 +231,21 @@ class FormTest extends \PHPUnit_Framework_TestCase public static function initFieldsUseConfigPathDataProvider() { return [ - [false, true, null], - [false, false, null], - [false, false, ''], - [false, false, 'value'], - [true, false, 'config value'] + ['test_field', true, null], + ['test_field', false, null], + ['test_field', false, ''], + ['test_field', false, 'value'], + ['test_field_use_config_module_1', false, 'config value'], + ['test_field_use_config_module_0', false, 'config value', 0] ]; } /** - * @param bool $useConfigField uses the test_field_use_config field if true + * @param string $fieldId uses the test_field_use_config field if true * @param bool $isConfigDataEmpty if the config data array should be empty or not - * @param $configDataValue the value that the field path should be set to in the config data + * @param string $configDataValue the value that the field path should be set to in the config data */ - protected function _setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmpty, $configDataValue) + protected function _setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue) { \Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize([ State::PARAM_BAN_CACHE => true, @@ -273,11 +288,8 @@ class FormTest extends \PHPUnit_Framework_TestCase $this->_group = $structure->getElement('test_section/test_group'); - if ($useConfigField) { - $this->_field = $structure->getElement('test_section/test_group/test_field_use_config'); - } else { - $this->_field = $structure->getElement('test_section/test_group/test_field'); - } + $this->_field = $structure->getElement('test_section/test_group/' . $fieldId); + $fieldPath = $this->_field->getConfigPath(); if ($isConfigDataEmpty) { diff --git a/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/_files/test_section_config.xml b/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/_files/test_section_config.xml index 072e1921a23e5b855d183235bf5192b5e3531b64..d584ff2a9f445ef867e1e6728a6df4eb6702bb3d 100644 --- a/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/_files/test_section_config.xml +++ b/dev/tests/integration/testsuite/Magento/Config/Block/System/Config/_files/test_section_config.xml @@ -20,9 +20,15 @@ <label>Test Field</label> <config_path>test_section/test_group/test_field</config_path> </field> - <field id="test_field_use_config" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20"> + <field id="test_field_use_config_module_1" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20"> <label>Test Field</label> <config_path>test_config_section/test_group_config_node/test_field_value</config_path> + <if_module_enabled>Magento_Config</if_module_enabled> + </field> + <field id="test_field_use_config_module_0" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20"> + <label>Test Field</label> + <config_path>test_config_section/test_group_config_node/test_field_value</config_path> + <if_module_enabled>Test_Module</if_module_enabled> </field> </group> </section> diff --git a/lib/internal/Magento/Framework/Api/Test/Unit/Code/Generator/EntityChildTestAbstract.php b/lib/internal/Magento/Framework/Api/Test/Unit/Code/Generator/EntityChildTestAbstract.php index 0265b6342ab449fac95a9037e1b2a06d7901e4ee..acbc463380d5292bab9de0851a1328ef4cebe3d3 100644 --- a/lib/internal/Magento/Framework/Api/Test/Unit/Code/Generator/EntityChildTestAbstract.php +++ b/lib/internal/Magento/Framework/Api/Test/Unit/Code/Generator/EntityChildTestAbstract.php @@ -126,7 +126,7 @@ abstract class EntityChildTestAbstract extends \PHPUnit_Framework_TestCase protected function mockDefinedClassesCall() { $this->definedClassesMock->expects($this->at(0)) - ->method('classLoadable') + ->method('isClassLoadable') ->with($this->getSourceClassName()) ->willReturn(true); } diff --git a/lib/internal/Magento/Framework/Autoload/AutoloaderInterface.php b/lib/internal/Magento/Framework/Autoload/AutoloaderInterface.php index 6349cbbafcb566e148ccabc229ab88a85ac813a5..dad4426c96bf8ba03d016abcf36c286fc2252517 100644 --- a/lib/internal/Magento/Framework/Autoload/AutoloaderInterface.php +++ b/lib/internal/Magento/Framework/Autoload/AutoloaderInterface.php @@ -55,4 +55,12 @@ interface AutoloaderInterface * @return bool */ public function loadClass($className); + + /** + * Get filepath of class on system or false if it does not exist + * + * @param string $className + * @return string|bool + */ + public function findFile($className); } diff --git a/lib/internal/Magento/Framework/Autoload/ClassLoaderWrapper.php b/lib/internal/Magento/Framework/Autoload/ClassLoaderWrapper.php index f96162b350052e6c94d716757fdf95e01dabe563..c1f2f5d15a12857e5c6ba0e850a832d6541fc72d 100644 --- a/lib/internal/Magento/Framework/Autoload/ClassLoaderWrapper.php +++ b/lib/internal/Magento/Framework/Autoload/ClassLoaderWrapper.php @@ -28,12 +28,7 @@ class ClassLoaderWrapper implements AutoloaderInterface } /** - * Adds a PSR-4 mapping from a namespace prefix to directories to search in for the corresponding class - * - * @param string $nsPrefix The namespace prefix of the PSR-4 mapping - * @param string|array $paths The path or paths to look in for the given prefix - * @param bool $prepend Whether to append the given path or paths to the paths already associated with the prefix - * @return void + * {@inheritdoc} */ public function addPsr4($nsPrefix, $paths, $prepend = false) { @@ -41,12 +36,7 @@ class ClassLoaderWrapper implements AutoloaderInterface } /** - * Adds a PSR-0 mapping from a namespace prefix to directories to search in for the corresponding class - * - * @param string $nsPrefix The namespace prefix of the PSR-0 mapping - * @param string|array $paths The path or paths to look in for the given prefix - * @param bool $prepend Whether to append the given path or paths to the paths already associated with the prefix - * @return void + * {@inheritdoc} */ public function addPsr0($nsPrefix, $paths, $prepend = false) { @@ -54,11 +44,7 @@ class ClassLoaderWrapper implements AutoloaderInterface } /** - * Creates new PSR-0 mappings from the given prefix to the given set of paths, eliminating previous mappings - * - * @param string $nsPrefix The namespace prefix of the PSR-0 mapping - * @param string|array $paths The path or paths to look in for the given prefix - * @return void + * {@inheritdoc} */ public function setPsr0($nsPrefix, $paths) { @@ -66,11 +52,7 @@ class ClassLoaderWrapper implements AutoloaderInterface } /** - * Creates new PSR-4 mappings from the given prefix to the given set of paths, eliminating previous mappings - * - * @param string $nsPrefix The namespace prefix of the PSR-0 mapping - * @param string|array $paths The path or paths to look in for the given prefix - * @return void + * {@inheritdoc} */ public function setPsr4($nsPrefix, $paths) { @@ -78,13 +60,28 @@ class ClassLoaderWrapper implements AutoloaderInterface } /** - * Attempts to load a class and returns true if successful. - * - * @param string $className - * @return bool + * {@inheritdoc} + * @codeCoverageIgnore */ public function loadClass($className) { return $this->autoloader->loadClass($className) === true; } + + /** + * {@inheritdoc} + * @codeCoverageIgnore + */ + public function findFile($className) + { + /** + * Composer remembers that files don't exist even after they are generated. This clears the entry for + * $className so we can check the filesystem again for class existence. + */ + if ($className[0] === '\\') { + $className = substr($className, 1); + } + $this->autoloader->addClassMap([$className => null]); + return $this->autoloader->findFile($className); + } } diff --git a/lib/internal/Magento/Framework/Code/Generator.php b/lib/internal/Magento/Framework/Code/Generator.php index da6d60b14ed9bff46b34410eba6c2c0bb4136926..edd02f6c2049282b6af2fa7f3b8e7d2559492857 100644 --- a/lib/internal/Magento/Framework/Code/Generator.php +++ b/lib/internal/Magento/Framework/Code/Generator.php @@ -74,31 +74,28 @@ class Generator */ public function generateClass($className) { - // check if source class a generated entity - $entity = null; - $entityName = null; + $resultEntityType = null; + $sourceClassName = null; foreach ($this->_generatedEntities as $entityType => $generatorClass) { $entitySuffix = ucfirst($entityType); - // if $className string ends on $entitySuffix substring + // If $className string ends with $entitySuffix substring if (strrpos($className, $entitySuffix) === strlen($className) - strlen($entitySuffix)) { - $entity = $entityType; - $entityName = rtrim( + $resultEntityType = $entityType; + $sourceClassName = rtrim( substr($className, 0, -1 * strlen($entitySuffix)), '\\' ); break; } } - if (!$entity || !$entityName) { - return self::GENERATION_ERROR; - } else if ($this->definedClasses->classLoadable($className)) { - return self::GENERATION_SKIP; - } else if (!isset($this->_generatedEntities[$entity])) { - throw new \InvalidArgumentException('Unknown generation entity.'); + + if ($skipReason = $this->shouldSkipGeneration($resultEntityType, $sourceClassName, $className)) { + return $skipReason; } - $generatorClass = $this->_generatedEntities[$entity]; + + $generatorClass = $this->_generatedEntities[$resultEntityType]; /** @var EntityAbstract $generator */ - $generator = $this->createGeneratorInstance($generatorClass, $entityName, $className); + $generator = $this->createGeneratorInstance($generatorClass, $sourceClassName, $className); if ($generator !== null) { $this->tryToLoadSourceClass($className, $generator); if (!($file = $generator->generate())) { @@ -107,18 +104,23 @@ class Generator new \Magento\Framework\Phrase(implode(' ', $errors)) ); } - $this->includeFile($file); + $this->tryToIncludeFile($file, $className); return self::GENERATION_SUCCESS; } } /** + * Include file only if the class is not already defined in memory + * * @param string $fileName + * @param string $className * @return void */ - public function includeFile($fileName) + public function tryToIncludeFile($fileName, $className) { - include $fileName; + if (!$this->definedClasses->isClassLoadableFromMemory($className)) { + include $fileName; + } } /** @@ -176,7 +178,7 @@ class Generator protected function tryToLoadSourceClass($className, $generator) { $sourceClassName = $generator->getSourceClassName(); - if (!$this->definedClasses->classLoadable($sourceClassName)) { + if (!$this->definedClasses->isClassLoadable($sourceClassName)) { if ($this->generateClass($sourceClassName) !== self::GENERATION_SUCCESS) { throw new \Magento\Framework\Exception\LocalizedException( new \Magento\Framework\Phrase( @@ -187,4 +189,24 @@ class Generator } } } + + /** + * Perform validation surrounding source and result classes and entity type + * + * @param string $resultEntityType + * @param string $sourceClassName + * @param string $resultClass + * @return string|bool + */ + protected function shouldSkipGeneration($resultEntityType, $sourceClassName, $resultClass) + { + if (!$resultEntityType || !$sourceClassName) { + return self::GENERATION_ERROR; + } else if ($this->definedClasses->isClassLoadableFromDisc($resultClass)) { + return self::GENERATION_SKIP; + } else if (!isset($this->_generatedEntities[$resultEntityType])) { + throw new \InvalidArgumentException('Unknown generation entity.'); + } + return false; + } } diff --git a/lib/internal/Magento/Framework/Code/Generator/DefinedClasses.php b/lib/internal/Magento/Framework/Code/Generator/DefinedClasses.php index 20621b72ee3c8c25cae84c0717370bdc09ea21c1..d0babb79f2f562fdefb486ac70f12397dc373af7 100644 --- a/lib/internal/Magento/Framework/Code/Generator/DefinedClasses.php +++ b/lib/internal/Magento/Framework/Code/Generator/DefinedClasses.php @@ -14,40 +14,37 @@ use Magento\Framework\Autoload\AutoloaderRegistry; class DefinedClasses { /** - * Determine if a class can be loaded without using the Code\Generator\Autoloader. + * Determine if a class can be loaded without using Code\Generator\Autoloader. * * @param string $className * @return bool */ - public function classLoadable($className) + public function isClassLoadable($className) { - if ($this->isAlreadyDefined($className)) { - return true; - } - return $this->performAutoload($className); + return $this->isClassLoadableFromMemory($className) || $this->isClassLoadableFromDisc($className); } /** - * Checks whether class is already defined + * Determine if a class exists in memory * * @param string $className * @return bool */ - protected function isAlreadyDefined($className) + public function isClassLoadableFromMemory($className) { return class_exists($className, false) || interface_exists($className, false); } /** - * Performs autoload for given class name + * Determine if a class exists on disc * * @param string $className * @return bool */ - protected function performAutoload($className) + public function isClassLoadableFromDisc($className) { try { - return AutoloaderRegistry::getAutoloader()->loadClass($className); + return (bool)AutoloaderRegistry::getAutoloader()->findFile($className); } catch (\Exception $e) { // Couldn't get access to the autoloader so we need to allow class_exists to call autoloader chain return (class_exists($className) || interface_exists($className)); diff --git a/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php b/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php index 82c7a210c0f11e79597e3b7939b7e50730d19077..fee367f49ca8046d5088bdbda5167bbcab90f82f 100644 --- a/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php +++ b/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php @@ -249,10 +249,10 @@ abstract class EntityAbstract $resultClassName = $this->_getResultClassName(); $resultDir = $this->_ioObject->getResultFileDirectory($resultClassName); - if (!$this->definedClasses->classLoadable($sourceClassName)) { + if (!$this->definedClasses->isClassLoadable($sourceClassName)) { $this->_addError('Source class ' . $sourceClassName . ' doesn\'t exist.'); return false; - } elseif ($this->definedClasses->classLoadable($resultClassName)) { + } elseif ($this->definedClasses->isClassLoadableFromDisc($resultClassName)) { $this->_addError('Result class ' . $resultClassName . ' already exists.'); return false; } elseif ( diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Generator/DefinedClassesTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Generator/DefinedClassesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e0f13bab0b3733f36d8d3b613f2068cf3ecf5f08 --- /dev/null +++ b/lib/internal/Magento/Framework/Code/Test/Unit/Generator/DefinedClassesTest.php @@ -0,0 +1,74 @@ +<?php +/*** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +// @codingStandardsIgnoreStart +namespace Magento\Framework\Code\Generator { + use Magento\Framework\Code\Test\Unit\Generator\DefinedClassesTest; + + function class_exists($className) + { + return DefinedClassesTest::$definedClassesTestActive + ? $className === DefinedClassesTest::$classInMemory + : \class_exists($className); + } +} + +namespace Magento\Framework\Code\Test\Unit\Generator { + use Magento\Framework\Autoload\AutoloaderInterface; + use Magento\Framework\Autoload\AutoloaderRegistry; + use Magento\Framework\Code\Generator\DefinedClasses; + + // @codingStandardsIgnoreEnd + + class DefinedClassesTest extends \PHPUnit_Framework_TestCase + { + /** @var bool */ + public static $definedClassesTestActive = false; + + public static $classInMemory = 'Class\That\Exists\In\Memory'; + + /** @var DefinedClasses */ + private $model; + + /** @var AutoloaderInterface */ + private $initAutoloader; + + public function setUp() + { + $this->model = new DefinedClasses(); + self::$definedClassesTestActive = true; + $this->initAutoloader = AutoloaderRegistry::getAutoloader(); + } + + public function tearDown() + { + self::$definedClassesTestActive = false; + AutoloaderRegistry::registerAutoloader($this->initAutoloader); + } + + public function testClassLoadableFromMemory() + { + $this->assertTrue($this->model->isClassLoadable(self::$classInMemory)); + } + + public function testClassLoadableFromDisc() + { + $classOnDisc = 'Class\That\Exists\On\Disc'; + /** + * @var AutoloaderInterface | \PHPUnit_Framework_MockObject_MockObject $autoloaderMock + */ + $autoloaderMock = $this->getMock('\Magento\Framework\Autoload\AutoloaderInterface'); + $autoloaderMock->expects($this->once())->method('findFile')->with($classOnDisc)->willReturn(true); + AutoloaderRegistry::registerAutoloader($autoloaderMock); + $this->assertTrue($this->model->isClassLoadable($classOnDisc)); + } + + public function testClassNotLoadable() + { + $this->assertFalse($this->model->isClassLoadable('Class\Does\Not\Exist')); + } + } +} diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Generator/EntityAbstractTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Generator/EntityAbstractTest.php index 8ed735e0af5a5309574a42bafa520f9b90019367..cf74e8a67f1573a8eb9ce202c35014f9ca6e263b 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Generator/EntityAbstractTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/Generator/EntityAbstractTest.php @@ -225,13 +225,13 @@ class EntityAbstractTest extends \PHPUnit_Framework_TestCase ) { // Configure DefinedClasses mock $definedClassesMock = $this->getMock('Magento\Framework\Code\Generator\DefinedClasses'); - $definedClassesMock->expects($this->at(0)) - ->method('classLoadable') + $definedClassesMock->expects($this->once()) + ->method('isClassLoadable') ->with(self::SOURCE_CLASS) ->willReturn($sourceClassExists); if ($resultClassExists) { - $definedClassesMock->expects($this->at(1)) - ->method('classLoadable') + $definedClassesMock->expects($this->once()) + ->method('isClassLoadableFromDisc') ->with(self::RESULT_CLASS) ->willReturn($resultClassExists); } diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php index e01f4c529c8274aaa48bc8b37b409da7037a4191..88a043753daa73776e941541651e7cc3b237e555 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php @@ -75,7 +75,9 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase ); $objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); $fullClassName = $className . $entityType; - $entityGeneratorMock = $this->getMockBuilder($fullClassName)->disableOriginalConstructor()->getMock(); + $entityGeneratorMock = $this->getMockBuilder('\Magento\Framework\Code\Generator\EntityAbstract') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->once())->method('create')->willReturn($entityGeneratorMock); $this->model->setObjectManager($objectManagerMock); $this->model->generateClass($fullClassName); @@ -88,7 +90,7 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase { $definedClassesMock = $this->getMock('Magento\Framework\Code\Generator\DefinedClasses'); $definedClassesMock->expects($this->any()) - ->method('classLoadable') + ->method('isClassLoadableFromDisc') ->willReturn(true); $this->model = new \Magento\Framework\Code\Generator( $this->ioObjectMock, @@ -133,7 +135,9 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase $expectedEntities = array_values($this->expectedEntities); $resultClassName = self::SOURCE_CLASS . ucfirst(array_shift($expectedEntities)); $objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $entityGeneratorMock = $this->getMockBuilder($resultClassName)->disableOriginalConstructor()->getMock(); + $entityGeneratorMock = $this->getMockBuilder('\Magento\Framework\Code\Generator\EntityAbstract') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->once())->method('create')->willReturn($entityGeneratorMock); $this->model->setObjectManager($objectManagerMock); $this->model->generateClass($resultClassName); diff --git a/lib/internal/Magento/Framework/Model/ModelResource/Db/AbstractDb.php b/lib/internal/Magento/Framework/Model/ModelResource/Db/AbstractDb.php index d6d202a408c8a85e8c1fef3fed1fa599d6653432..814135e008aa08e61809fbea31ab809d2b205c0b 100644 --- a/lib/internal/Magento/Framework/Model/ModelResource/Db/AbstractDb.php +++ b/lib/internal/Magento/Framework/Model/ModelResource/Db/AbstractDb.php @@ -769,7 +769,9 @@ abstract class AbstractDb extends AbstractResource } $this->getConnection()->insert($this->getMainTable(), $bind); - $object->setId($this->getConnection()->lastInsertId($this->getMainTable())); + if ($this->_isPkAutoIncrement) { + $object->setId($this->getConnection()->lastInsertId($this->getMainTable())); + } if ($this->_useIsObjectNew) { $object->isObjectNew(false); diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ModelResource/Db/AbstractDbTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/ModelResource/Db/AbstractDbTest.php index 480bf65ee6fa1195f5609003ce3f4ee6dff842f9..71d0c2be8b0286e6c53fb217f0c90e09a0782c7d 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ModelResource/Db/AbstractDbTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ModelResource/Db/AbstractDbTest.php @@ -487,4 +487,72 @@ class AbstractDbTest extends \PHPUnit_Framework_TestCase $this->_model->save($abstractModelMock); } + + /** + * Test that we only set/override id on object if PK autoincrement is enabled + * @param bool $pkIncrement + * @dataProvider saveNewObjectDataProvider + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + public function testSaveNewObject($pkIncrement) + { + /** + * Mock SUT so as not to test extraneous logic + */ + $model = $this->getMockBuilder('Magento\Framework\Model\ModelResource\Db\AbstractDb') + ->disableOriginalConstructor() + ->setMethods(['_prepareDataForSave', 'getIdFieldName', 'getConnection', 'getMainTable']) + ->getMockForAbstractClass(); + /** + * Only testing the logic in a protected method and property, must use reflection to avoid dealing with large + * amounts of unrelated logic in save function + * + * make saveNewObject and _isPkAutoIncrement public + */ + $reflectionMethod = new \ReflectionMethod($model, 'saveNewObject'); + $reflectionMethod->setAccessible(true); + $reflectionProperty = new \ReflectionProperty($model, '_isPkAutoIncrement'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($model, $pkIncrement); + + // Mocked behavior + $connectionMock = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface') + ->disableOriginalConstructor() + ->setMethods(['lastInsertId']) + ->getMockForAbstractClass(); + $getConnectionInvokedCount = $pkIncrement ? 2 : 1; + $model->expects($this->exactly($getConnectionInvokedCount)) + ->method('getConnection') + ->willReturn($connectionMock); + + $idFieldName = 'id_field_name'; + $model->expects($this->once())->method('_prepareDataForSave')->willReturn([$idFieldName => 'id',]); + + + // Test expectations + // Only get object's id field name if not PK autoincrement + $getIdFieldNameInvokedCount = $pkIncrement ? 1 : 0; + $model->expects($this->exactly($getIdFieldNameInvokedCount)) + ->method('getIdFieldName') + ->willReturn($idFieldName); + + // Only set object id if not PK autoincrement + $setIdInvokedCount = $pkIncrement ? 1 : 0; + $inputObject = $this->getMockBuilder('\Magento\Framework\Model\AbstractModel') + ->disableOriginalConstructor() + ->getMock(); + $inputObject->expects($this->exactly($setIdInvokedCount))->method('setId'); + + // Only call lastInsertId if not PK autoincrement + $lastInsertIdInvokedCount = $pkIncrement ? 1 : 0; + $connectionMock->expects($this->exactly($lastInsertIdInvokedCount))->method('lastInsertId'); + + $reflectionMethod->invokeArgs($model, [$inputObject]); + } + + public function saveNewObjectDataProvider() + { + return [[true], [false]]; + } + } diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/ConverterTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/ConverterTest.php index c03b20e274c6ce5eb9fc11a7129153a94320b38a..10bafa24672ad8ed72d942d6de81262d8f2434e8 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/ConverterTest.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/ConverterTest.php @@ -77,7 +77,7 @@ class ConverterTest extends \PHPUnit_Framework_TestCase //Mocking _validateData call $this->definedClassesMock->expects($this->at(0)) - ->method('classLoadable') + ->method('isClassLoadable') ->will($this->returnValue(true)); $this->ioObjectMock->expects($this->once()) diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/RepositoryTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/RepositoryTest.php index 08c9586b45de328a218ea0685d9ba32972b50e1f..1be208085ab052389b20c1bc1980818724cac2c8 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/RepositoryTest.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/RepositoryTest.php @@ -41,7 +41,7 @@ class RepositoryTest extends EntityChildTestAbstract protected function mockDefinedClassesCall() { $this->definedClassesMock->expects($this->at(0)) - ->method('classLoadable') + ->method('isClassLoadable') ->with($this->getSourceClassName() . 'Interface') ->willReturn(true); } diff --git a/setup/pub/magento/setup/readiness-check.js b/setup/pub/magento/setup/readiness-check.js index 869fba5caf073c5fc51a4394bb0b4afd7e0579a0..f2b8cf9e48c5f3a1e4cb63d86cdec1249756ab75 100644 --- a/setup/pub/magento/setup/readiness-check.js +++ b/setup/pub/magento/setup/readiness-check.js @@ -305,8 +305,10 @@ angular.module('readiness-check', []) angular.forEach($scope.items, function(item) { item.show(); }); + var $delay = 0; angular.forEach($scope.items, function(item) { - $scope.query(item); + $timeout(function() { $scope.query(item); }, $delay * 1000); + $delay++; }); };