CommentsTest.php 2.1 KB

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