Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
GroupManagementTest Class Reference
Inheritance diagram for GroupManagementTest:
WebapiAbstract

Public Member Functions

 setUp ()
 
 testGetDefaultGroup ($storeId, $defaultGroupData)
 
 getDefaultGroupDataProvider ()
 
 testGetDefaultGroupNonExistentStore ()
 
 testIsReadonly ($groupId, $isDeleteable)
 
 isReadonlyDataProvider ()
 
 testIsReadonlyNoSuchGroup ()
 
- Public Member Functions inherited from WebapiAbstract
 addModelToDelete ($model, $secure=false)
 
 processRestExceptionResult (\Exception $e)
 

Data Fields

const SERVICE_NAME = "customerGroupManagementV1"
 
const SERVICE_VERSION = "V1"
 
const RESOURCE_PATH = "/V1/customerGroups"
 
- Data Fields inherited from WebapiAbstract
const AUTO_TEAR_DOWN_DISABLED = 0
 
const AUTO_TEAR_DOWN_AFTER_METHOD = 1
 
const AUTO_TEAR_DOWN_AFTER_CLASS = 2
 
const ADAPTER_SOAP = 'soap'
 
const ADAPTER_REST = 'rest'
 

Additional Inherited Members

- Static Public Member Functions inherited from WebapiAbstract
static setUpBeforeClass ()
 
static tearDownAfterClass ()
 
static setFixture ($key, $fixture, $tearDown=self::AUTO_TEAR_DOWN_AFTER_METHOD)
 
static getFixture ($key)
 
static callModelDelete ($model, $secure=false)
 
static deleteFixture ($key, $secure=false)
 
- Protected Member Functions inherited from WebapiAbstract
 tearDown ()
 
 _webApiCall ( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
 
 _markTestAsSoapOnly ($message=null)
 
 _markTestAsRestOnly ($message=null)
 
 _getWebApiAdapter ($webApiAdapterCode)
 
 _assertMessagesEqual ($expectedMessages, $receivedMessages)
 
 _cleanAppConfigCache ()
 
 _restoreAppConfig ()
 
 checkSoapFault ( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
 
 _checkFaultParams ($expectedErrorParams, $errorDetails)
 
 _checkWrappedErrors ($expectedWrappedErrors, $errorDetails)
 
- Static Protected Member Functions inherited from WebapiAbstract
static _setFixtureNamespace ()
 
static _unsetFixtureNamespace ()
 
static _getFixtureNamespace ()
 
static _deleteFixtures ($fixtures)
 
- Protected Attributes inherited from WebapiAbstract
 $_appCache
 
 $_modelsToDelete = []
 
 $_origConfigValues = []
 
 $_webApiAdapters
 
 $_webApiAdaptersMap
 
- Static Protected Attributes inherited from WebapiAbstract
static $_fixturesNamespace
 
static $_fixtures = []
 
static $_methodLevelFixtures = []
 
static $_classLevelFixtures = []
 

Detailed Description

Class GroupManagementTest

Definition at line 18 of file GroupManagementTest.php.

Member Function Documentation

◆ getDefaultGroupDataProvider()

getDefaultGroupDataProvider ( )

The testGetDefaultGroup data provider.

Returns
array
array

Definition at line 76 of file GroupManagementTest.php.

77  {
78  return [
79  'admin' => [
80  0,
81  [
82  CustomerGroup::ID => 1,
83  CustomerGroup::CODE => 'General',
84  CustomerGroup::TAX_CLASS_ID => 3,
85  CustomerGroup::TAX_CLASS_NAME => 'Retail Customer'
86  ],
87  ],
88  'base' => [
89  1,
90  [
91  CustomerGroup::ID => 1,
92  CustomerGroup::CODE => 'General',
93  CustomerGroup::TAX_CLASS_ID => 3,
94  CustomerGroup::TAX_CLASS_NAME => 'Retail Customer'
95  ],
96  ]
97  ];
98  }

◆ isReadonlyDataProvider()

isReadonlyDataProvider ( )

The testIsReadonly data provider.

Returns
array

Definition at line 177 of file GroupManagementTest.php.

178  {
179  return [
180  'NOT LOGGED IN' => [0, false],
181  'General' => [1, false],
182  'Wholesale' => [2, true],
183  'Retailer' => [3, true]
184  ];
185  }

◆ setUp()

setUp ( )

Execute per test initialization.

Definition at line 37 of file GroupManagementTest.php.

38  {
40  $this->groupRegistry = $objectManager->get(\Magento\Customer\Model\GroupRegistry::class);
41  $this->groupRepository = $objectManager->get(\Magento\Customer\Model\ResourceModel\GroupRepository::class);
42  }
$objectManager
Definition: bootstrap.php:17

◆ testGetDefaultGroup()

testGetDefaultGroup (   $storeId,
  $defaultGroupData 
)

Verify the retrieval of the default group for storeId equal to 1.

Parameters
int$storeIdThe store Id
array$defaultGroupDataThe default group data for the store with the specified Id.

@dataProvider getDefaultGroupDataProvider

Definition at line 52 of file GroupManagementTest.php.

53  {
54  $serviceInfo = [
55  'rest' => [
56  'resourcePath' => self::RESOURCE_PATH . "/default/$storeId",
58  ],
59  'soap' => [
60  'service' => self::SERVICE_NAME,
61  'serviceVersion' => self::SERVICE_VERSION,
62  'operation' => 'customerGroupManagementV1GetDefaultGroup',
63  ],
64  ];
65  $requestData = ['storeId' => $storeId];
66  $groupData = $this->_webApiCall($serviceInfo, $requestData);
67 
68  $this->assertEquals($defaultGroupData, $groupData, "The default group does not match.");
69  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testGetDefaultGroupNonExistentStore()

testGetDefaultGroupNonExistentStore ( )

Verify the retrieval of a non-existent storeId will return an expected fault.

Definition at line 103 of file GroupManagementTest.php.

104  {
105  /* Store id should not exist */
106  $nonExistentStoreId = 9876;
107 
108  $serviceInfo = [
109  'rest' => [
110  'resourcePath' => self::RESOURCE_PATH . "/default/$nonExistentStoreId",
112  ],
113  'soap' => [
114  'service' => self::SERVICE_NAME,
115  'serviceVersion' => self::SERVICE_VERSION,
116  'operation' => 'customerGroupManagementV1GetDefaultGroup',
117  ],
118  ];
119  $requestData = ['storeId' => $nonExistentStoreId];
120  $expectedMessage = 'No such entity with %fieldName = %fieldValue';
121 
122  try {
123  $this->_webApiCall($serviceInfo, $requestData);
124  $this->fail("Expected exception");
125  } catch (\SoapFault $e) {
126  $this->assertContains(
127  $expectedMessage,
128  $e->getMessage(),
129  "SoapFault does not contain expected message."
130  );
131  } catch (\Exception $e) {
132  $this->assertContains(
133  $expectedMessage,
134  $e->getMessage(),
135  "Exception does not contain expected message."
136  );
137  $this->assertContains((string)$nonExistentStoreId, $e->getMessage());
138  }
139  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testIsReadonly()

testIsReadonly (   $groupId,
  $isDeleteable 
)

Verify that the group with the specified Id can or cannot be deleted.

Parameters
int$groupIdThe group Id
bool$isDeleteableWhether the group can or cannot be deleted.

@dataProvider isReadonlyDataProvider

Definition at line 149 of file GroupManagementTest.php.

150  {
151  $serviceInfo = [
152  'rest' => [
153  'resourcePath' => self::RESOURCE_PATH . "/$groupId/permissions",
155  ],
156  'soap' => [
157  'service' => self::SERVICE_NAME,
158  'serviceVersion' => self::SERVICE_VERSION,
159  'operation' => 'customerGroupManagementV1IsReadonly',
160  ],
161  ];
162 
163  $requestData = [CustomerGroup::ID => $groupId];
164 
165  $isReadonly = $this->_webApiCall($serviceInfo, $requestData);
166 
167  $failureMessage = $isDeleteable
168  ? 'The group should be deleteable.' : 'The group should not be deleteable.';
169  $this->assertEquals($isDeleteable, !$isReadonly, $failureMessage);
170  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testIsReadonlyNoSuchGroup()

testIsReadonlyNoSuchGroup ( )

Verify that the group with the specified Id can or cannot be deleted.

Definition at line 190 of file GroupManagementTest.php.

191  {
192  /* This group ID should not exist in the store. */
193  $groupId = 9999;
194 
195  $serviceInfo = [
196  'rest' => [
197  'resourcePath' => self::RESOURCE_PATH . "/$groupId/permissions",
199  ],
200  'soap' => [
201  'service' => self::SERVICE_NAME,
202  'serviceVersion' => self::SERVICE_VERSION,
203  'operation' => 'customerGroupManagementV1IsReadonly',
204  ],
205  ];
206 
207  $requestData = [CustomerGroup::ID => $groupId];
208 
209  $expectedMessage = 'No such entity with %fieldName = %fieldValue';
210 
211  try {
212  $this->_webApiCall($serviceInfo, $requestData);
213  $this->fail("Expected exception.");
214  } catch (\SoapFault $e) {
215  $this->assertContains(
216  $expectedMessage,
217  $e->getMessage(),
218  "SoapFault does not contain expected message."
219  );
220  } catch (\Exception $e) {
221  $this->assertContains(
222  $expectedMessage,
223  $e->getMessage(),
224  "Exception does not contain expected message."
225  );
226  $this->assertContains((string)$groupId, $e->getMessage());
227  }
228  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

Field Documentation

◆ RESOURCE_PATH

const RESOURCE_PATH = "/V1/customerGroups"

Definition at line 22 of file GroupManagementTest.php.

◆ SERVICE_NAME

const SERVICE_NAME = "customerGroupManagementV1"

Definition at line 20 of file GroupManagementTest.php.

◆ SERVICE_VERSION

const SERVICE_VERSION = "V1"

Definition at line 21 of file GroupManagementTest.php.


The documentation for this class was generated from the following file: