Skip to content

Commit e309a2a

Browse files
committed
MAGETWO-66718: Constants' Usage Elimination
1 parent 238cd3d commit e309a2a

File tree

8 files changed

+245
-4
lines changed

8 files changed

+245
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Api;
7+
8+
/**
9+
* Interface for system configuration operations for customer groups.
10+
*
11+
* @api
12+
*/
13+
interface CustomerGroupConfigInterface
14+
{
15+
/**
16+
* Set system default customer group.
17+
*
18+
* @param int $id
19+
* @return int
20+
* @throws \UnexpectedValueException
21+
* @throws \Exception
22+
* @throws \Magento\Framework\Exception\NoSuchEntityException
23+
* @throws \Magento\Framework\Exception\LocalizedException
24+
*/
25+
public function setDefaultCustomerGroup($id);
26+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model;
8+
9+
/**
10+
* System configuration operations for customer groups.
11+
*/
12+
class CustomerGroupConfig implements \Magento\Customer\Api\CustomerGroupConfigInterface
13+
{
14+
/**
15+
* @var \Magento\Config\Model\Config
16+
*/
17+
private $config;
18+
19+
/**
20+
* @var \Magento\Customer\Api\GroupRepositoryInterface
21+
*/
22+
private $groupRepository;
23+
24+
/**
25+
* @param \Magento\Config\Model\Config $config
26+
* @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
27+
*/
28+
public function __construct(
29+
\Magento\Config\Model\Config $config,
30+
\Magento\Customer\Api\GroupRepositoryInterface $groupRepository
31+
) {
32+
$this->config = $config;
33+
$this->groupRepository = $groupRepository;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function setDefaultCustomerGroup($id)
40+
{
41+
if ($this->groupRepository->getById($id)) {
42+
$this->config->setDataByPath(
43+
\Magento\Customer\Model\GroupManagement::XML_PATH_DEFAULT_ID,
44+
$id
45+
);
46+
$this->config->save();
47+
}
48+
49+
return $id;
50+
}
51+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Test\Unit\Model;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
11+
class CustomerGroupConfigTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var ObjectManagerHelper
15+
*/
16+
private $objectManagerHelper;
17+
18+
/**
19+
* @var \Magento\Customer\Model\CustomerGroupConfig
20+
*/
21+
private $customerGroupConfig;
22+
23+
/**
24+
* @var \Magento\Config\Model\Config|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $configMock;
27+
28+
/**
29+
* @var \Magento\Customer\Api\GroupRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $groupRepositoryMock;
32+
33+
/**
34+
* Set up.
35+
*
36+
* @return void
37+
*/
38+
public function setUp()
39+
{
40+
$this->configMock = $this->getMockBuilder(\Magento\Config\Model\Config::class)
41+
->disableOriginalConstructor()
42+
->getMock();
43+
$this->groupRepositoryMock = $this->getMockBuilder(\Magento\Customer\Api\GroupRepositoryInterface::class)
44+
->disableOriginalConstructor()
45+
->getMock();
46+
47+
$this->objectManagerHelper = new ObjectManagerHelper($this);
48+
$this->customerGroupConfig = $this->objectManagerHelper->getObject(
49+
\Magento\Customer\Model\CustomerGroupConfig::class,
50+
[
51+
'config' => $this->configMock,
52+
'groupRepository' => $this->groupRepositoryMock
53+
]
54+
);
55+
}
56+
57+
/**
58+
* @return void
59+
*/
60+
public function testSetDefaultCustomerGroup()
61+
{
62+
$customerGroupId = 1;
63+
64+
$customerGroupMock = $this->getMockBuilder(\Magento\Customer\Api\Data\GroupInterface::class)
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$this->groupRepositoryMock->expects($this->once())->method('getById')->willReturn($customerGroupMock);
68+
$this->configMock->expects($this->once())->method('setDataByPath')
69+
->with(\Magento\Customer\Model\GroupManagement::XML_PATH_DEFAULT_ID, $customerGroupId)->willReturnSelf();
70+
$this->configMock->expects($this->once())->method('save');
71+
72+
$this->assertEquals($customerGroupId, $this->customerGroupConfig->setDefaultCustomerGroup($customerGroupId));
73+
}
74+
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
type="Magento\Customer\Model\ResourceModel\CustomerRepository" />
1313
<preference for="Magento\Customer\Api\GroupManagementInterface"
1414
type="Magento\Customer\Model\GroupManagement" />
15+
<preference for="Magento\Customer\Api\CustomerGroupConfigInterface"
16+
type="Magento\Customer\Model\CustomerGroupConfig" />
1517
<preference for="Magento\Customer\Api\GroupRepositoryInterface"
1618
type="Magento\Customer\Model\ResourceModel\GroupRepository" />
1719
<preference for="Magento\Customer\Api\Data\CustomerInterface" type="Magento\Customer\Model\Data\Customer" />

app/code/Magento/Customer/etc/webapi.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
<resource ref="Magento_Customer::group"/>
2727
</resources>
2828
</route>
29+
<route url="/V1/customerGroups/default/:id" method="PUT">
30+
<service class="Magento\Customer\Api\CustomerGroupConfigInterface" method="setDefaultCustomerGroup"/>
31+
<resources>
32+
<resource ref="Magento_Customer::group"/>
33+
</resources>
34+
</route>
2935
<route url="/V1/customerGroups/:id/permissions" method="GET">
3036
<service class="Magento\Customer\Api\GroupManagementInterface" method="isReadonly"/>
3137
<resources>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Api;
8+
9+
use Magento\TestFramework\TestCase\WebapiAbstract;
10+
11+
/**
12+
* Web API tests for CustomerGroupConfig model.
13+
*/
14+
class CustomerGroupConfigTest extends WebapiAbstract
15+
{
16+
const SERVICE_NAME = "customerCustomerGroupConfigV1";
17+
const SERVICE_VERSION = "V1";
18+
const RESOURCE_PATH = "/V1/customerGroups";
19+
20+
/**
21+
* @return void
22+
*/
23+
public function testSetDefaultGroup()
24+
{
25+
$customerGroupId = 1;
26+
$serviceInfo = [
27+
'rest' => [
28+
'resourcePath' => self::RESOURCE_PATH . "/default/$customerGroupId",
29+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
30+
],
31+
'soap' => [
32+
'service' => self::SERVICE_NAME,
33+
'serviceVersion' => self::SERVICE_VERSION,
34+
'operation' => 'customerCustomerGroupConfigV1SetDefaultCustomerGroup',
35+
],
36+
];
37+
$requestData = ['id' => $customerGroupId];
38+
$groupData = $this->_webApiCall($serviceInfo, $requestData);
39+
40+
$this->assertEquals($customerGroupId, $groupData, "The default group does not match.");
41+
}
42+
43+
/**
44+
* Web API test for setDefaultGroup() method when there is no customer group exists with provided ID.
45+
*
46+
* @return void
47+
*/
48+
public function testSetDefaultGroupNonExistingGroup()
49+
{
50+
$customerGroupId = 10000;
51+
$expectedMessage = 'No such entity with %fieldName = %fieldValue';
52+
$serviceInfo = [
53+
'rest' => [
54+
'resourcePath' => self::RESOURCE_PATH . "/default/$customerGroupId",
55+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
56+
],
57+
'soap' => [
58+
'service' => self::SERVICE_NAME,
59+
'serviceVersion' => self::SERVICE_VERSION,
60+
'operation' => 'customerCustomerGroupConfigV1SetDefaultCustomerGroup',
61+
],
62+
];
63+
$requestData = ['id' => $customerGroupId];
64+
try {
65+
$this->_webApiCall($serviceInfo, $requestData);
66+
$this->fail("Expected exception");
67+
} catch (\SoapFault $e) {
68+
$this->assertContains(
69+
$expectedMessage,
70+
$e->getMessage(),
71+
"SoapFault does not contain expected message."
72+
);
73+
} catch (\Exception $e) {
74+
$this->assertContains(
75+
$expectedMessage,
76+
$e->getMessage(),
77+
"Exception does not contain expected message."
78+
);
79+
$this->assertContains((string)$customerGroupId, $e->getMessage());
80+
}
81+
}
82+
}

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/PriceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ private function prepareBuyRequest(Product $product)
9898
/** @var $option \Magento\Catalog\Model\Product\Option */
9999
foreach ($product->getOptions() as $option) {
100100
switch ($option->getGroupByType()) {
101-
case \Magento\Catalog\Model\Product\Option::OPTION_GROUP_DATE:
101+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
102102
$value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
103103
break;
104-
case \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT:
104+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
105105
$value = key($option->getValues());
106106
break;
107107
default:

dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_and_custom_option.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
/** @var $option \Magento\Catalog\Model\Product\Option */
1616
foreach ($product->getOptions() as $option) {
1717
switch ($option->getGroupByType()) {
18-
case \Magento\Catalog\Model\Product\Option::OPTION_GROUP_DATE:
18+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
1919
$value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
2020
break;
21-
case \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT:
21+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
2222
$value = key($option->getValues());
2323
break;
2424
default:

0 commit comments

Comments
 (0)