Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
StockTest Class Reference
Inheritance diagram for StockTest:

Public Member Functions

 testGetFilteredContent ($contentToFilter, $contentFiltered)
 
 getFilteredContentDataProvider ()
 
 testGetImage ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $_block
 
 $_filter
 
 $imageBuilder
 

Detailed Description

Test class for \Magento\ProductAlert\Block\Product\View\Stock

Definition at line 11 of file StockTest.php.

Member Function Documentation

◆ getFilteredContentDataProvider()

getFilteredContentDataProvider ( )
Returns
array

Definition at line 71 of file StockTest.php.

72  {
73  return [
74  'normal desc' => ['<b>Howdy!</b>', '<b>Howdy!</b>'],
75  'malicious desc 1' => ['<javascript>Howdy!</javascript>', 'Howdy!'],
76  ];
77  }

◆ setUp()

setUp ( )
protected

Definition at line 33 of file StockTest.php.

34  {
35  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36  $this->_filter = $this->createPartialMock(\Magento\Framework\Filter\Input\MaliciousCode::class, ['filter']);
37 
38  $this->imageBuilder = $this->getMockBuilder(\Magento\Catalog\Block\Product\ImageBuilder::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $this->imageProviderMock = $this->getMockBuilder(\Magento\ProductAlert\Block\Product\ImageProvider::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45 
46  $this->_block = $objectManager->getObject(
47  \Magento\ProductAlert\Block\Email\Stock::class,
48  [
49  'maliciousCode' => $this->_filter,
50  'imageBuilder' => $this->imageBuilder,
51  'imageProvider' => $this->imageProviderMock
52  ]
53  );
54  }
$objectManager
Definition: bootstrap.php:17

◆ testGetFilteredContent()

testGetFilteredContent (   $contentToFilter,
  $contentFiltered 
)

@dataProvider getFilteredContentDataProvider

Parameters
$contentToFilter
$contentFiltered

Definition at line 61 of file StockTest.php.

62  {
63  $this->_filter->expects($this->once())->method('filter')->with($contentToFilter)
64  ->will($this->returnValue($contentFiltered));
65  $this->assertEquals($contentFiltered, $this->_block->getFilteredContent($contentToFilter));
66  }

◆ testGetImage()

testGetImage ( )

Definition at line 79 of file StockTest.php.

80  {
81  $imageId = 'test_image_id';
82  $attributes = [];
83 
84  $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
85  ->disableOriginalConstructor()
86  ->getMock();
87  $productImageMock = $this->getMockBuilder(\Magento\Catalog\Block\Product\Image::class)
88  ->disableOriginalConstructor()
89  ->getMock();
90 
91  $this->imageProviderMock->expects($this->atLeastOnce())->method('getImage')->willReturn($productImageMock);
92 
93  $this->assertInstanceOf(
94  \Magento\Catalog\Block\Product\Image::class,
95  $this->_block->getImage($productMock, $imageId, $attributes)
96  );
97  }
$attributes
Definition: matrix.phtml:13

Field Documentation

◆ $_block

$_block
protected

Definition at line 16 of file StockTest.php.

◆ $_filter

$_filter
protected

Definition at line 21 of file StockTest.php.

◆ $imageBuilder

$imageBuilder
protected

Definition at line 26 of file StockTest.php.


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