Skip to content

Commit

Permalink
Refactor Unit Tests too
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Aug 18, 2020
1 parent 4b0fdfc commit 6b01af9
Showing 1 changed file with 8 additions and 44 deletions.
52 changes: 8 additions & 44 deletions app/code/Magento/Quote/Test/Unit/Model/ChangeQuoteControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,36 @@

/**
* Unit test for \Magento\Quote\Model\ChangeQuoteControl
*
* Class \Magento\Quote\Test\Unit\Model\ChangeQuoteControlTest
*/
class ChangeQuoteControlTest extends TestCase
{
/**
* @var ObjectManager
*/
protected $objectManager;

/**
* @var ChangeQuoteControl
*/
protected $model;

/**
* @var MockObject
* @var MockObject|UserContextInterface
*/
protected $userContextMock;

/**
* @var MockObject
* @var MockObject|CartInterface
*/
protected $quoteMock;

protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
$this->userContextMock = $this->getMockForAbstractClass(UserContextInterface::class);

$this->model = $this->objectManager->getObject(
ChangeQuoteControl::class,
[
'userContext' => $this->userContextMock
]
);

$this->quoteMock = $this->getMockForAbstractClass(
CartInterface::class,
[],
'',
false,
true,
true,
['getCustomerId']
);
$this->model = new ChangeQuoteControl($this->userContextMock);

$this->quoteMock = $this->getMockBuilder(CartInterface::class)
->disableOriginalConstructor()
->addMethods(['getCustomerId'])
->getMockForAbstractClass();
}

/**
* Test if the quote is belonged to customer
*/
public function testIsAllowedIfTheQuoteIsBelongedToCustomer()
{
$quoteCustomerId = 1;
Expand All @@ -80,9 +59,6 @@ public function testIsAllowedIfTheQuoteIsBelongedToCustomer()
$this->assertTrue($this->model->isAllowed($this->quoteMock));
}

/**
* Test if the quote is not belonged to customer
*/
public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer()
{
$currentCustomerId = 1;
Expand All @@ -98,9 +74,6 @@ public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer()
$this->assertFalse($this->model->isAllowed($this->quoteMock));
}

/**
* Test if the quote is belonged to guest and the context is guest
*/
public function testIsAllowedIfQuoteIsBelongedToGuestAndContextIsGuest()
{
$quoteCustomerId = null;
Expand All @@ -111,9 +84,6 @@ public function testIsAllowedIfQuoteIsBelongedToGuestAndContextIsGuest()
$this->assertTrue($this->model->isAllowed($this->quoteMock));
}

/**
* Test if the quote is belonged to customer and the context is guest
*/
public function testIsAllowedIfQuoteIsBelongedToCustomerAndContextIsGuest()
{
$quoteCustomerId = 1;
Expand All @@ -124,19 +94,13 @@ public function testIsAllowedIfQuoteIsBelongedToCustomerAndContextIsGuest()
$this->assertFalse($this->model->isAllowed($this->quoteMock));
}

/**
* Test if the context is admin
*/
public function testIsAllowedIfContextIsAdmin()
{
$this->userContextMock->expects($this->any())->method('getUserType')
->willReturn(UserContextInterface::USER_TYPE_ADMIN);
$this->assertTrue($this->model->isAllowed($this->quoteMock));
}

/**
* Test if the context is integration
*/
public function testIsAllowedIfContextIsIntegration()
{
$this->userContextMock->expects($this->any())->method('getUserType')
Expand Down

0 comments on commit 6b01af9

Please sign in to comment.