123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Service\V1;
- /**
- * API test for creation of Invoice for certain Order.
- */
- class OrderInvoiceCreateTest extends \Magento\TestFramework\TestCase\WebapiAbstract
- {
- const SERVICE_READ_NAME = 'salesInvoiceOrderV1';
- const SERVICE_VERSION = 'V1';
- /**
- * @var \Magento\Framework\ObjectManagerInterface
- */
- private $objectManager;
- /**
- * @var \Magento\Sales\Api\InvoiceRepositoryInterface
- */
- private $invoiceRepository;
- protected function setUp()
- {
- $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
- $this->invoiceRepository = $this->objectManager->get(
- \Magento\Sales\Api\InvoiceRepositoryInterface::class
- );
- }
- /**
- * @magentoApiDataFixture Magento/Sales/_files/order_new.php
- */
- public function testInvoiceCreate()
- {
- /** @var \Magento\Sales\Model\Order $existingOrder */
- $existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
- ->loadByIncrementId('100000001');
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/invoice',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
- ],
- 'soap' => [
- 'service' => self::SERVICE_READ_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_READ_NAME . 'execute',
- ],
- ];
- $requestData = [
- 'orderId' => $existingOrder->getId(),
- 'items' => [],
- 'comment' => [
- 'comment' => 'Test Comment',
- 'is_visible_on_front' => 1,
- ],
- ];
- /** @var \Magento\Sales\Api\Data\OrderItemInterface $item */
- foreach ($existingOrder->getAllItems() as $item) {
- $requestData['items'][] = [
- 'order_item_id' => $item->getItemId(),
- 'qty' => $item->getQtyOrdered(),
- ];
- }
- $result = $this->_webApiCall($serviceInfo, $requestData);
- $this->assertNotEmpty($result);
- try {
- $this->invoiceRepository->get($result);
- } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
- $this->fail('Failed asserting that Invoice was created');
- }
- /** @var \Magento\Sales\Model\Order $updatedOrder */
- $updatedOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
- ->loadByIncrementId('100000001');
- $this->assertNotEquals(
- $existingOrder->getStatus(),
- $updatedOrder->getStatus(),
- 'Failed asserting that Order status was changed'
- );
- }
- /**
- * Tests that MAGETWO-95346 was fixed for bundled products
- *
- * @expectedException \Exception
- * @codingStandardsIgnoreStart
- * @expectedExceptionMessageRegExp /Invoice Document Validation Error\(s\):(?:\n|\\n)The invoice can't be created without products. Add products and try again./
- * @codingStandardsIgnoreEnd
- * @magentoApiDataFixture Magento/Sales/_files/order_with_bundle.php
- */
- public function testOrderWithBundleInvoicedWithInvalidQuantitiesReturnsError()
- {
- /** @var \Magento\Sales\Model\Order $existingOrder */
- $existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
- ->loadByIncrementId('100000001');
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/invoice',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
- ],
- 'soap' => [
- 'service' => self::SERVICE_READ_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_READ_NAME . 'execute',
- ],
- ];
- $requestData = [
- 'orderId' => $existingOrder->getId(),
- 'notify' => true,
- 'appendComment' => true,
- 'items' => [
- [
- 'order_item_id' => -1,
- 'qty' => 1
- ]
- ],
- 'comment' => [
- 'comment' => 'Test offline',
- 'isVisibleOnFront' => 1,
- ],
- ];
- $this->_webApiCall($serviceInfo, $requestData);
- }
- /**
- * Tests that MAGETWO-95346 was fixed for configurable products
- *
- * @expectedException \Exception
- * @codingStandardsIgnoreStart
- * @expectedExceptionMessageRegExp /Invoice Document Validation Error\(s\):(?:\n|\\n)The invoice can't be created without products. Add products and try again./
- * @codingStandardsIgnoreEnd
- * @magentoApiDataFixture Magento/Sales/_files/order_configurable_product.php
- */
- public function testOrderWithConfigurableProductInvoicedWithInvalidQuantitiesReturnsError()
- {
- /** @var \Magento\Sales\Model\Order $existingOrder */
- $existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
- ->loadByIncrementId('100000001');
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/invoice',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
- ],
- 'soap' => [
- 'service' => self::SERVICE_READ_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_READ_NAME . 'execute',
- ],
- ];
- $requestData = [
- 'orderId' => $existingOrder->getId(),
- 'notify' => true,
- 'appendComment' => true,
- 'items' => [
- [
- 'order_item_id' => -1,
- 'qty' => 1
- ]
- ],
- 'comment' => [
- 'comment' => 'Test offline',
- 'isVisibleOnFront' => 1,
- ],
- ];
- $this->_webApiCall($serviceInfo, $requestData);
- }
- }
|