Skip to content

Commit

Permalink
Adjusting the Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard13 committed Jan 8, 2020
1 parent 86ff8fa commit 5d0e12b
Showing 1 changed file with 86 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@
*/
class GroupActionsTest extends TestCase
{
/**
* @var int
*/
private const STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID = 0;

/**
* @var string
*/
private const STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME = 'Not Logged In';

/**
* @var int
*/
private const STUB_GENERAL_CUSTOMER_GROUP_ID = 1;

/**
* @var string
*/
private const STUB_GENERAL_CUSTOMER_GROUP_NAME = 'General';

/**
* @var string
*/
private const STUB_GROUP_EDIT_URL = 'http://magento.com/customer/group/edit';

/**
* @var string
*/
private const STUB_GROUP_DELETE_URL = 'http://magento.com/customer/group/delete';

/**
* @var GroupActions
*/
Expand Down Expand Up @@ -97,7 +127,6 @@ public function setUp()
*/
public function testPrepareDataSourceWithNonDefaultGroup(array $items, bool $isDefaultGroup, array $expected)
{
$customerGroup = 'General';
$dataSource = [
'data' => [
'items' => $items
Expand All @@ -111,18 +140,29 @@ public function testPrepareDataSourceWithNonDefaultGroup(array $items, bool $isD

$this->groupManagementMock->expects($this->any())
->method('isReadonly')
->with(1)
->with(static::STUB_GENERAL_CUSTOMER_GROUP_ID)
->willReturn($isDefaultGroup);
$this->escaperMock->expects($this->any())
->method('escapeHtml')
->with($customerGroup)
->willReturn($customerGroup);
->with(static::STUB_GENERAL_CUSTOMER_GROUP_NAME)
->willReturn(static::STUB_GENERAL_CUSTOMER_GROUP_NAME);
$this->urlBuilderMock->expects($this->any())
->method('getUrl')
->willReturnMap(
[
['customer/group/edit', ['id' => 1], 'http://magento.com/customer/group/edit'],
['customer/group/delete', ['id' => 1], 'http://magento.com/customer/group/delete']
[
'customer/group/edit',
[
'id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID
],
static::STUB_GROUP_EDIT_URL],
[
'customer/group/delete',
[
'id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID
],
static::STUB_GROUP_DELETE_URL
]
]
);

Expand All @@ -142,12 +182,12 @@ public function testPrepareDataSourceWithDefaultGroup()
'data' => [
'items' => [
[
'customer_group_id' => 1,
'customer_group_code' => 'General',
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID,
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME,
],
[
'customer_group_id' => 0,
'customer_group_code' => 'Not Logged In',
'customer_group_id' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID,
'customer_group_code' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME,
],
]
]
Expand All @@ -156,22 +196,22 @@ public function testPrepareDataSourceWithDefaultGroup()
'data' => [
'items' => [
[
'customer_group_id' => 1,
'customer_group_code' => 'General',
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID,
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME,
'name' => [
'edit' => [
'href' => 'http://magento.com/customer/group/edit',
'href' => static::STUB_GROUP_EDIT_URL,
'label' => __('Edit'),
'__disableTmpl' => true,
]
]
],
[
'customer_group_id' => 0,
'customer_group_code' => 'Not Logged In',
'customer_group_id' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID,
'customer_group_code' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME,
'name' => [
'edit' => [
'href' => 'http://magento.com/customer/group/edit',
'href' => static::STUB_GROUP_EDIT_URL,
'label' => __('Edit'),
'__disableTmpl' => true,
]
Expand All @@ -188,16 +228,36 @@ public function testPrepareDataSourceWithDefaultGroup()
->method('escapeHtml')
->willReturnMap(
[
['General', null, 'General'],
['Not Logged In', null, 'Not Logged In']
[
static::STUB_GENERAL_CUSTOMER_GROUP_NAME,
null,
static::STUB_GENERAL_CUSTOMER_GROUP_NAME
],
[
static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME,
null,
static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME
]
]
);
$this->urlBuilderMock->expects($this->any())
->method('getUrl')
->willReturnMap(
[
['customer/group/edit', ['id' => 1], 'http://magento.com/customer/group/edit'],
['customer/group/edit', ['id' => 0], 'http://magento.com/customer/group/edit']
[
'customer/group/edit',
[
'id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID
],
static::STUB_GROUP_EDIT_URL
],
[
'customer/group/edit',
[
'id' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID
],
static::STUB_GROUP_EDIT_URL
]
]
);

Expand All @@ -216,23 +276,23 @@ public function customerGroupsDataProvider(): array
[
[
[
'customer_group_id' => 1,
'customer_group_code' => 'General',
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID,
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME,
],
],
false,
[
[
'customer_group_id' => 1,
'customer_group_code' => 'General',
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID,
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME,
'name' => [
'edit' => [
'href' => 'http://magento.com/customer/group/edit',
'href' => static::STUB_GROUP_EDIT_URL,
'label' => __('Edit'),
'__disableTmpl' => true,
],
'delete' => [
'href' => 'http://magento.com/customer/group/delete',
'href' => static::STUB_GROUP_DELETE_URL,
'label' => __('Delete'),
'post' => true,
'__disableTmpl' => true,
Expand Down

0 comments on commit 5d0e12b

Please sign in to comment.