Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MoveToWishlistTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class MoveToWishlistTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $model;
18 
21 
22  protected function setUp()
23  {
24  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
25 
26  $this->wishlistHelperMock = $this->getMockBuilder(\Magento\Wishlist\Helper\Data::class)
27  ->disableOriginalConstructor()
28  ->getMock();
29 
30  $this->model = $objectManagerHelper->getObject(
31  \Magento\Wishlist\Block\Cart\Item\Renderer\Actions\MoveToWishlist::class,
32  [
33  'wishlistHelper' => $this->wishlistHelperMock,
34  ]
35  );
36  }
37 
38  public function testIsAllowInCart()
39  {
40  $this->wishlistHelperMock->expects($this->once())
41  ->method('isAllowInCart')
42  ->willReturn(true);
43 
44  $this->assertTrue($this->model->isAllowInCart());
45  }
46 
47  public function testGetMoveFromCartParams()
48  {
49  $itemId = 45;
50  $json = '{json;}';
51 
55  $itemMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $itemMock->expects($this->once())
60  ->method('getId')
61  ->willReturn($itemId);
62 
63  $this->wishlistHelperMock->expects($this->once())
64  ->method('getMoveFromCartParams')
65  ->with($itemId)
66  ->willReturn($json);
67 
68  $this->model->setItem($itemMock);
69  $this->assertEquals($json, $this->model->getMoveFromCartParams());
70  }
71 }