Skip to content

Commit 56408d2

Browse files
author
Ievgen Shakhsuvarov
committed
MAGETWO-39372: Build stabilization
- unit tests
1 parent 24a1c9b commit 56408d2

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

app/code/Magento/Captcha/Test/Unit/Model/Customer/Plugin/AjaxLoginTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class AjaxLoginTest extends \PHPUnit_Framework_TestCase
4242
*/
4343
protected $loginControllerMock;
4444

45+
/**
46+
* @var array
47+
*/
48+
protected $formIds;
49+
4550
/**
4651
* @var \Magento\Captcha\Model\Customer\Plugin\AjaxLogin
4752
*/
@@ -67,19 +72,25 @@ protected function setUp()
6772
->will($this->returnValue($this->requestMock));
6873
$this->captchaHelperMock->expects($this->once())->method('getCaptcha')
6974
->with('user_login')->will($this->returnValue($this->captchaMock));
75+
$this->formIds = ['user_login'];
7076

7177
$this->model = new \Magento\Captcha\Model\Customer\Plugin\AjaxLogin(
7278
$this->captchaHelperMock,
7379
$this->sessionManagerMock,
74-
$this->jsonFactoryMock
80+
$this->jsonFactoryMock,
81+
$this->formIds
7582
);
7683
}
7784

7885
public function testAroundExecute()
7986
{
8087
$username = 'name';
8188
$captchaString = 'string';
82-
$requestContent = json_encode(['username' => $username, 'captcha_string' => $captchaString]);
89+
$requestContent = json_encode([
90+
'username' => $username,
91+
'captcha_string' => $captchaString,
92+
'captcha_form_id' => $this->formIds[0]
93+
]);
8394

8495
$this->requestMock->expects($this->once())->method('getContent')->will($this->returnValue($requestContent));
8596
$this->captchaMock->expects($this->once())->method('isRequired')->with($username)
@@ -98,7 +109,11 @@ public function testAroundExecuteIncorrectCaptcha()
98109
{
99110
$username = 'name';
100111
$captchaString = 'string';
101-
$requestContent = json_encode(['username' => $username, 'captcha_string' => $captchaString]);
112+
$requestContent = json_encode([
113+
'username' => $username,
114+
'captcha_string' => $captchaString,
115+
'captcha_form_id' => $this->formIds[0]
116+
]);
102117

103118
$this->requestMock->expects($this->once())->method('getContent')->will($this->returnValue($requestContent));
104119
$this->captchaMock->expects($this->once())->method('isRequired')->with($username)

app/code/Magento/Checkout/Test/Unit/Model/Cart/ImageProviderTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,44 @@
88

99
class ImageProviderTest extends \PHPUnit_Framework_TestCase
1010
{
11+
/**
12+
* @var \Magento\Checkout\Model\Cart\ImageProvider
13+
*/
14+
public $model;
15+
16+
/**
17+
* @var \PHPUnit_Framework_Mockobject_Mockobject | \Magento\Quote\Api\CartItemRepositoryInterface
18+
*/
19+
protected $itemRepositoryMock;
20+
21+
/**
22+
* @var \PHPUnit_Framework_Mockobject_Mockobject | \Magento\Checkout\CustomerData\ItemPoolInterface
23+
*/
24+
protected $itemPoolMock;
25+
1126
protected function setUp()
1227
{
13-
//@TODO implement test
28+
$this->itemRepositoryMock = $this->getMock('Magento\Quote\Api\CartItemRepositoryInterface', [], [], '', false);
29+
$this->itemPoolMock = $this->getMock('Magento\Checkout\CustomerData\ItemPoolInterface', [], [], '', false);
30+
$this->model = new \Magento\Checkout\Model\Cart\ImageProvider (
31+
$this->itemRepositoryMock,
32+
$this->itemPoolMock
33+
);
1434
}
1535

1636
public function testGetImages()
1737
{
18-
$this->fail('to be implemented');
38+
$cartId = 42;
39+
$itemId = 74;
40+
$itemData = ['product_image' => 'Magento.png', 'random' => '3.1415926535'];
41+
$itemMock = $this->getMock('Magento\Quote\Model\Quote\Item', [], [], '', false);
42+
$itemMock->expects($this->once())->method('getItemId')->willReturn($itemId);
43+
44+
$expectedResult = [$itemId => $itemData['product_image']];
45+
46+
$this->itemRepositoryMock->expects($this->once())->method('getList')->with($cartId)->willReturn([$itemMock]);
47+
$this->itemPoolMock->expects($this->once())->method('getItemData')->with($itemMock)->willReturn($itemData);
48+
49+
$this->assertEquals($expectedResult, $this->model->getImages($cartId));
1950
}
2051
}

0 commit comments

Comments
 (0)