From 3ee655a31d78a9c9aaa82b0c1a396a61d73c4229 Mon Sep 17 00:00:00 2001 From: Yaroslav Onischenko <yonischenko@magento.com> Date: Fri, 26 Aug 2016 17:22:55 +0300 Subject: [PATCH] MAGETWO-55908: Prepare PR --- .../Product/Form/Modifier/AdvancedPricing.php | 11 ++++----- .../Customer/Model/Config/Source/Group.php | 18 +++++++-------- .../Model/Config/Source/Group/Multiselect.php | 18 ++++++++++++--- .../Model/Customer/Attribute/Source/Group.php | 3 +-- .../GroupSourceLoggedInOnlyInterface.php} | 4 ++-- .../Customer/Model/Customer/Source/Group.php | 19 ++++----------- .../Customer/Source/GroupSourceInterface.php | 1 - .../GroupSourceWithAllGroupsInterface.php | 12 ---------- .../Source/GroupWithoutAllSources.php | 15 ------------ .../Config/Source/Group/MultiselectTest.php | 23 +++++++++++++------ .../Unit/Model/Config/Source/GroupTest.php | 6 ++--- app/code/Magento/Customer/etc/di.xml | 8 +++---- 12 files changed, 59 insertions(+), 79 deletions(-) rename app/code/Magento/Customer/Model/Customer/{Source/GroupSourceForLoggedInCustomersInterface.php => Attribute/Source/GroupSourceLoggedInOnlyInterface.php} (57%) delete mode 100644 app/code/Magento/Customer/Model/Customer/Source/GroupSourceWithAllGroupsInterface.php delete mode 100644 app/code/Magento/Customer/Model/Customer/Source/GroupWithoutAllSources.php diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php index 1f85d81a5df..071bc8d7967 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php @@ -7,11 +7,10 @@ namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier; use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Model\Locator\LocatorInterface; -use Magento\Customer\Model\Customer\Source\GroupSourceWithAllGroupsInterface; +use Magento\Customer\Model\Customer\Source\GroupSourceInterface; use Magento\Directory\Helper\Data; use Magento\Framework\App\ObjectManager; use Magento\Store\Model\StoreManagerInterface; -use Magento\Customer\Api\Data\GroupInterface; use Magento\Customer\Api\GroupManagementInterface; use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Framework\Api\SearchCriteriaBuilder; @@ -84,7 +83,7 @@ class AdvancedPricing extends AbstractModifier protected $meta = []; /** - * @var GroupSourceWithAllGroupsInterface + * @var GroupSourceInterface */ private $customerGroupSource; @@ -98,7 +97,7 @@ class AdvancedPricing extends AbstractModifier * @param Data $directoryHelper * @param ArrayManager $arrayManager * @param string $scopeName - * @param GroupSourceWithAllGroupsInterface $customerGroupSource + * @param GroupSourceInterface $customerGroupSource * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -111,7 +110,7 @@ class AdvancedPricing extends AbstractModifier Data $directoryHelper, ArrayManager $arrayManager, $scopeName = '', - GroupSourceWithAllGroupsInterface $customerGroupSource = null + GroupSourceInterface $customerGroupSource = null ) { $this->locator = $locator; $this->storeManager = $storeManager; @@ -123,7 +122,7 @@ class AdvancedPricing extends AbstractModifier $this->arrayManager = $arrayManager; $this->scopeName = $scopeName; $this->customerGroupSource = $customerGroupSource - ?: ObjectManager::getInstance()->get(GroupSourceWithAllGroupsInterface::class); + ?: ObjectManager::getInstance()->get(GroupSourceInterface::class); } /** diff --git a/app/code/Magento/Customer/Model/Config/Source/Group.php b/app/code/Magento/Customer/Model/Config/Source/Group.php index 76f0b142da0..e693bf7a3c4 100644 --- a/app/code/Magento/Customer/Model/Config/Source/Group.php +++ b/app/code/Magento/Customer/Model/Config/Source/Group.php @@ -6,7 +6,7 @@ namespace Magento\Customer\Model\Config\Source; use Magento\Customer\Api\GroupManagementInterface; -use Magento\Customer\Model\Customer\Source\GroupSourceForLoggedInCustomersInterface; +use Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface; use Magento\Framework\App\ObjectManager; class Group implements \Magento\Framework\Option\ArrayInterface @@ -29,33 +29,33 @@ class Group implements \Magento\Framework\Option\ArrayInterface protected $_converter; /** - * @var GroupSourceForLoggedInCustomersInterface + * @var GroupSourceLoggedInOnlyInterface */ - private $groupSourceForLoggedInCustomers; + private $groupSourceLoggedInOnly; /** * @param GroupManagementInterface $groupManagement * @param \Magento\Framework\Convert\DataObject $converter - * @param GroupSourceForLoggedInCustomersInterface $groupSourceForLoggedInCustomers + * @param GroupSourceLoggedInOnlyInterface $groupSourceForLoggedInCustomers */ public function __construct( GroupManagementInterface $groupManagement, \Magento\Framework\Convert\DataObject $converter, - GroupSourceForLoggedInCustomersInterface $groupSourceForLoggedInCustomers = null + GroupSourceLoggedInOnlyInterface $groupSourceForLoggedInCustomers = null ) { $this->_groupManagement = $groupManagement; $this->_converter = $converter; - $this->groupSourceForLoggedInCustomers = $groupSourceForLoggedInCustomers - ?: ObjectManager::getInstance()->get(GroupSourceForLoggedInCustomersInterface::class); + $this->groupSourceLoggedInOnly = $groupSourceForLoggedInCustomers + ?: ObjectManager::getInstance()->get(GroupSourceLoggedInOnlyInterface::class); } /** - * @return array + * @inheritdoc */ public function toOptionArray() { if (!$this->_options) { - $this->_options = $this->groupSourceForLoggedInCustomers->toOptionArray(); + $this->_options = $this->groupSourceLoggedInOnly->toOptionArray(); array_unshift($this->_options, ['value' => '', 'label' => __('-- Please Select --')]); } diff --git a/app/code/Magento/Customer/Model/Config/Source/Group/Multiselect.php b/app/code/Magento/Customer/Model/Config/Source/Group/Multiselect.php index 708e3243e26..adfc78448cd 100644 --- a/app/code/Magento/Customer/Model/Config/Source/Group/Multiselect.php +++ b/app/code/Magento/Customer/Model/Config/Source/Group/Multiselect.php @@ -5,7 +5,9 @@ */ namespace Magento\Customer\Model\Config\Source\Group; +use Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface; use Magento\Customer\Api\GroupManagementInterface; +use Magento\Framework\App\ObjectManager; class Multiselect implements \Magento\Framework\Option\ArrayInterface { @@ -17,25 +19,36 @@ class Multiselect implements \Magento\Framework\Option\ArrayInterface protected $_options; /** + * @deprecated * @var GroupManagementInterface */ protected $_groupManagement; /** + * @deprecated * @var \Magento\Framework\Convert\DataObject */ protected $_converter; + /** + * @var GroupSourceLoggedInOnlyInterface + */ + private $groupSourceLoggedInOnly; + /** * @param GroupManagementInterface $groupManagement * @param \Magento\Framework\Convert\DataObject $converter + * @param GroupSourceLoggedInOnlyInterface|null $groupSourceLoggedInOnly */ public function __construct( GroupManagementInterface $groupManagement, - \Magento\Framework\Convert\DataObject $converter + \Magento\Framework\Convert\DataObject $converter, + GroupSourceLoggedInOnlyInterface $groupSourceLoggedInOnly = null ) { $this->_groupManagement = $groupManagement; $this->_converter = $converter; + $this->groupSourceLoggedInOnly = $groupSourceLoggedInOnly + ?: ObjectManager::getInstance()->get(GroupSourceLoggedInOnlyInterface::class); } /** @@ -46,8 +59,7 @@ class Multiselect implements \Magento\Framework\Option\ArrayInterface public function toOptionArray() { if (!$this->_options) { - $groups = $this->_groupManagement->getLoggedInGroups(); - $this->_options = $this->_converter->toOptionArray($groups, 'id', 'code'); + $this->_options = $this->groupSourceLoggedInOnly->toOptionArray(); } return $this->_options; } diff --git a/app/code/Magento/Customer/Model/Customer/Attribute/Source/Group.php b/app/code/Magento/Customer/Model/Customer/Attribute/Source/Group.php index 22f196d0c2b..9af4b7fc673 100644 --- a/app/code/Magento/Customer/Model/Customer/Attribute/Source/Group.php +++ b/app/code/Magento/Customer/Model/Customer/Attribute/Source/Group.php @@ -6,14 +6,13 @@ namespace Magento\Customer\Model\Customer\Attribute\Source; use Magento\Customer\Api\GroupManagementInterface; -use Magento\Customer\Model\Customer\Source\GroupSourceForLoggedInCustomersInterface; /** * Customer group attribute source * * @author Magento Core Team <core@magentocommerce.com> */ -class Group extends \Magento\Eav\Model\Entity\Attribute\Source\Table implements GroupSourceForLoggedInCustomersInterface +class Group extends \Magento\Eav\Model\Entity\Attribute\Source\Table implements GroupSourceLoggedInOnlyInterface { /** * @var GroupManagementInterface diff --git a/app/code/Magento/Customer/Model/Customer/Source/GroupSourceForLoggedInCustomersInterface.php b/app/code/Magento/Customer/Model/Customer/Attribute/Source/GroupSourceLoggedInOnlyInterface.php similarity index 57% rename from app/code/Magento/Customer/Model/Customer/Source/GroupSourceForLoggedInCustomersInterface.php rename to app/code/Magento/Customer/Model/Customer/Attribute/Source/GroupSourceLoggedInOnlyInterface.php index be44b12314b..93df78a1be1 100644 --- a/app/code/Magento/Customer/Model/Customer/Source/GroupSourceForLoggedInCustomersInterface.php +++ b/app/code/Magento/Customer/Model/Customer/Attribute/Source/GroupSourceLoggedInOnlyInterface.php @@ -4,11 +4,11 @@ * See COPYING.txt for license details. */ -namespace Magento\Customer\Model\Customer\Source; +namespace Magento\Customer\Model\Customer\Attribute\Source; use Magento\Framework\Option\ArrayInterface as OptionArrayInterface; -interface GroupSourceForLoggedInCustomersInterface extends OptionArrayInterface +interface GroupSourceLoggedInOnlyInterface extends OptionArrayInterface { } diff --git a/app/code/Magento/Customer/Model/Customer/Source/Group.php b/app/code/Magento/Customer/Model/Customer/Source/Group.php index 068d960ea77..5973ec6ffaa 100644 --- a/app/code/Magento/Customer/Model/Customer/Source/Group.php +++ b/app/code/Magento/Customer/Model/Customer/Source/Group.php @@ -11,7 +11,7 @@ use Magento\Customer\Api\Data\GroupInterface; use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Framework\Api\SearchCriteriaBuilder; -class Group implements GroupSourceWithAllGroupsInterface +class Group implements GroupSourceInterface { /** * @var ModuleManager @@ -28,12 +28,6 @@ class Group implements GroupSourceWithAllGroupsInterface */ protected $searchCriteriaBuilder; - /** - * Defines is 'ALL GROUPS' value should be added to options - * @var bool - */ - protected $isShowAllGroupsValue = true; - /** * @param ModuleManager $moduleManager * @param GroupRepositoryInterface $groupRepository @@ -60,13 +54,10 @@ class Group implements GroupSourceWithAllGroupsInterface return []; } $customerGroups = []; - - if ($this->isShowAllGroupsValue) { - $customerGroups[] = [ - 'label' => __('ALL GROUPS'), - 'value' => GroupInterface::CUST_GROUP_ALL, - ]; - } + $customerGroups[] = [ + 'label' => __('ALL GROUPS'), + 'value' => GroupInterface::CUST_GROUP_ALL, + ]; /** @var GroupSearchResultsInterface $groups */ $groups = $this->groupRepository->getList($this->searchCriteriaBuilder->create()); diff --git a/app/code/Magento/Customer/Model/Customer/Source/GroupSourceInterface.php b/app/code/Magento/Customer/Model/Customer/Source/GroupSourceInterface.php index 9d0cfe08af8..d180ad4d491 100644 --- a/app/code/Magento/Customer/Model/Customer/Source/GroupSourceInterface.php +++ b/app/code/Magento/Customer/Model/Customer/Source/GroupSourceInterface.php @@ -5,7 +5,6 @@ */ namespace Magento\Customer\Model\Customer\Source; - use Magento\Framework\Option\ArrayInterface as OptionArrayInterface; interface GroupSourceInterface extends OptionArrayInterface diff --git a/app/code/Magento/Customer/Model/Customer/Source/GroupSourceWithAllGroupsInterface.php b/app/code/Magento/Customer/Model/Customer/Source/GroupSourceWithAllGroupsInterface.php deleted file mode 100644 index 75150ef813e..00000000000 --- a/app/code/Magento/Customer/Model/Customer/Source/GroupSourceWithAllGroupsInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Customer\Model\Customer\Source; - -use Magento\Framework\Option\ArrayInterface as OptionArrayInterface; - -interface GroupSourceWithAllGroupsInterface extends OptionArrayInterface -{ -} diff --git a/app/code/Magento/Customer/Model/Customer/Source/GroupWithoutAllSources.php b/app/code/Magento/Customer/Model/Customer/Source/GroupWithoutAllSources.php deleted file mode 100644 index 44455b418c0..00000000000 --- a/app/code/Magento/Customer/Model/Customer/Source/GroupWithoutAllSources.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Customer\Model\Customer\Source; - -class GroupWithoutAllSources extends Group implements GroupSourceInterface -{ - /** - * @var bool - */ - protected $isShowAllGroupsValue = false; -} diff --git a/app/code/Magento/Customer/Test/Unit/Model/Config/Source/Group/MultiselectTest.php b/app/code/Magento/Customer/Test/Unit/Model/Config/Source/Group/MultiselectTest.php index 3b8bea594ed..bc64351f3d0 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Config/Source/Group/MultiselectTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Config/Source/Group/MultiselectTest.php @@ -6,6 +6,8 @@ */ namespace Magento\Customer\Test\Unit\Model\Config\Source\Group; +use Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface; + class MultiselectTest extends \PHPUnit_Framework_TestCase { /** @@ -23,22 +25,29 @@ class MultiselectTest extends \PHPUnit_Framework_TestCase */ protected $converterMock; + /** + * @var GroupSourceLoggedInOnlyInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $groupSourceLoggedInOnly; + protected function setUp() { $this->groupServiceMock = $this->getMock(\Magento\Customer\Api\GroupManagementInterface::class); $this->converterMock = $this->getMock(\Magento\Framework\Convert\DataObject::class, [], [], '', false); - $this->model = - new \Magento\Customer\Model\Config\Source\Group\Multiselect($this->groupServiceMock, $this->converterMock); + $this->groupSourceLoggedInOnly = $this->getMockBuilder(GroupSourceLoggedInOnlyInterface::class)->getMock(); + $this->model = new \Magento\Customer\Model\Config\Source\Group\Multiselect( + $this->groupServiceMock, + $this->converterMock, + $this->groupSourceLoggedInOnly + ); } public function testToOptionArray() { $expectedValue = ['General', 'Retail']; - $this->groupServiceMock->expects($this->once()) - ->method('getLoggedInGroups') - ->will($this->returnValue($expectedValue)); - $this->converterMock->expects($this->once())->method('toOptionArray') - ->with($expectedValue, 'id', 'code')->will($this->returnValue($expectedValue)); + $this->groupServiceMock->expects($this->never())->method('getLoggedInGroups'); + $this->converterMock->expects($this->never())->method('toOptionArray'); + $this->groupSourceLoggedInOnly->expects($this->once())->method('toOptionArray')->willReturn($expectedValue); $this->assertEquals($expectedValue, $this->model->toOptionArray()); } } diff --git a/app/code/Magento/Customer/Test/Unit/Model/Config/Source/GroupTest.php b/app/code/Magento/Customer/Test/Unit/Model/Config/Source/GroupTest.php index d7693a25653..55b495f9c41 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Config/Source/GroupTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Config/Source/GroupTest.php @@ -8,14 +8,14 @@ namespace Magento\Customer\Test\Unit\Model\Config\Source; use Magento\Customer\Api\GroupManagementInterface; use Magento\Customer\Model\Config\Source\Group; -use Magento\Customer\Model\Customer\Source\GroupSourceForLoggedInCustomersInterface; +use Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface; use Magento\Framework\Convert\DataObject; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; class GroupTest extends \PHPUnit_Framework_TestCase { /** - * @var GroupSourceForLoggedInCustomersInterface|\PHPUnit_Framework_MockObject_MockObject + * @var GroupSourceLoggedInOnlyInterface|\PHPUnit_Framework_MockObject_MockObject */ private $groupSource; @@ -38,7 +38,7 @@ class GroupTest extends \PHPUnit_Framework_TestCase { $this->groupServiceMock = $this->getMock(GroupManagementInterface::class); $this->converterMock = $this->getMock(DataObject::class, [], [], '', false); - $this->groupSource = $this->getMockBuilder(GroupSourceForLoggedInCustomersInterface::class) + $this->groupSource = $this->getMockBuilder(GroupSourceLoggedInOnlyInterface::class) ->getMockForAbstractClass(); $this->model = (new ObjectManager($this))->getObject( Group::class, diff --git a/app/code/Magento/Customer/etc/di.xml b/app/code/Magento/Customer/etc/di.xml index 5229a709ed4..ebde958f75b 100644 --- a/app/code/Magento/Customer/etc/di.xml +++ b/app/code/Magento/Customer/etc/di.xml @@ -51,12 +51,10 @@ type="Magento\Customer\Helper\View" /> <preference for="Magento\Customer\Model\Address\CustomAttributeListInterface" type="Magento\Customer\Model\Address\CustomAttributeList" /> - <preference for="Magento\Customer\Model\Customer\Source\GroupSourceWithAllGroupsInterface" - type="\Magento\Customer\Model\Customer\Source\Group" /> <preference for="Magento\Customer\Model\Customer\Source\GroupSourceInterface" - type="\Magento\Customer\Model\Customer\Source\GroupWithoutAllSources" /> - <preference for="Magento\Customer\Model\Customer\Source\GroupSourceForLoggedInCustomersInterface" - type="\Magento\Customer\Model\Customer\Attribute\Source\Group"/> + type="Magento\Customer\Model\Customer\Source\Group" /> + <preference for="Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface" + type="Magento\Customer\Model\Customer\Attribute\Source\Group"/> <type name="Magento\Customer\Model\Session"> <arguments> <argument name="configShare" xsi:type="object">Magento\Customer\Model\Config\Share\Proxy</argument> -- GitLab