1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Block\Order;
class CommentsTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Sales\Block\Order\Comments
*/
protected $_block;
protected function setUp()
{
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Sales\Block\Order\Comments::class
);
}
/**
* @param string $commentedEntity
* @param string $expectedClass
* @dataProvider getCommentsDataProvider
*/
public function testGetComments($commentedEntity, $expectedClass)
{
$commentedEntity = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($commentedEntity);
$this->_block->setEntity($commentedEntity);
$comments = $this->_block->getComments();
$this->assertInstanceOf($expectedClass, $comments);
}
/**
* @return array
*/
public function getCommentsDataProvider()
{
return [
[
\Magento\Sales\Model\Order\Invoice::class,
\Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\Collection::class,
],
[
\Magento\Sales\Model\Order\Creditmemo::class,
\Magento\Sales\Model\ResourceModel\Order\Creditmemo\Comment\Collection::class
],
[
\Magento\Sales\Model\Order\Shipment::class,
\Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\Collection::class
]
];
}
/**
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testGetCommentsWrongEntityException()
{
$entity = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\Product::class
);
$this->_block->setEntity($entity);
$this->_block->getComments();
}
}