ViewTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Controller\Adminhtml\Shipment;
  6. use Magento\TestFramework\Helper\Bootstrap;
  7. use Magento\TestFramework\TestCase\AbstractBackendController;
  8. use Temando\Shipping\Model\ResourceModel\Shipment\ShipmentReferenceRepository;
  9. use Temando\Shipping\Test\Integration\Fixture\ShippedOrderFixture;
  10. /**
  11. * @magentoAppArea adminhtml
  12. */
  13. class ViewTest extends AbstractBackendController
  14. {
  15. /**
  16. * The resource used to authorize action
  17. *
  18. * @var string
  19. */
  20. protected $resource = 'Temando_Shipping::shipping';
  21. /**
  22. * The uri at which to access the controller
  23. *
  24. * @var string
  25. */
  26. protected $uri = 'backend/temando/shipment/view';
  27. /**
  28. * @var ShipmentReferenceRepository
  29. */
  30. private $shipmentReferenceRepository;
  31. /**
  32. * delegate fixtures creation to separate class.
  33. */
  34. public static function createOrderAndShipmentFixture()
  35. {
  36. ShippedOrderFixture::createOrderAndShipmentFixture();
  37. }
  38. /**
  39. * delegate fixtures rollback to separate class.
  40. */
  41. public static function createOrderAndShipmentFixtureRollback()
  42. {
  43. ShippedOrderFixture::createOrderAndShipmentFixtureRollback();
  44. }
  45. protected function setUp()
  46. {
  47. parent::setUp();
  48. $this->shipmentReferenceRepository = Bootstrap::getObjectManager()->get(ShipmentReferenceRepository::class);
  49. }
  50. /**
  51. * @test
  52. * @magentoDataFixture createOrderAndShipmentFixture
  53. */
  54. public function shipmentNotFound()
  55. {
  56. $shipmentReferenceData = ShippedOrderFixture::getShipmentReferenceData();
  57. $extShipmentId = $shipmentReferenceData['id'];
  58. // not existing external shipment id
  59. $extShipmentId.= '123';
  60. $this->getRequest()->setParam('shipment_id', $extShipmentId);
  61. $this->dispatch($this->uri);
  62. $this->assertEquals('noroute', $this->getRequest()->getControllerName());
  63. $this->assertEquals(404, $this->getResponse()->getHttpResponseCode());
  64. }
  65. /**
  66. * @test
  67. * @magentoDataFixture createOrderAndShipmentFixture
  68. */
  69. public function redirectSuccess()
  70. {
  71. $shipmentReferenceData = ShippedOrderFixture::getShipmentReferenceData();
  72. $extShipmentId = $shipmentReferenceData['id'];
  73. $shipmentReference = $this->shipmentReferenceRepository->getByExtShipmentId($extShipmentId);
  74. $shipmentId = $shipmentReference->getShipmentId();
  75. // existing external shipment id
  76. $this->getRequest()->setParam('shipment_id', $extShipmentId);
  77. $this->dispatch($this->uri);
  78. $this->assertRedirect($this->stringContains('sales/shipment/view/shipment_id/' . $shipmentId));
  79. }
  80. /**
  81. * @test
  82. * @magentoDataFixture createOrderAndShipmentFixture
  83. */
  84. public function testAclHasAccess()
  85. {
  86. $shipmentReferenceData = ShippedOrderFixture::getShipmentReferenceData();
  87. $extShipmentId = $shipmentReferenceData['id'];
  88. // existing external shipment id
  89. $this->getRequest()->setParam('shipment_id', $extShipmentId);
  90. parent::testAclHasAccess();
  91. }
  92. }