diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php index ae6faae7650b9..e7401100b7860 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php @@ -7,6 +7,7 @@ namespace Magento\GraphQl\SendFriend; +use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\SendFriend\Model\SendFriend; use Magento\SendFriend\Model\SendFriendFactory; use Magento\TestFramework\Helper\Bootstrap; @@ -22,52 +23,32 @@ class SendFriendTest extends GraphQlAbstract * @var SendFriendFactory */ private $sendFriendFactory; + /** + * @var ProductRepositoryInterface + */ + private $productRepository; protected function setUp() { $this->sendFriendFactory = Bootstrap::getObjectManager()->get(SendFriendFactory::class); + $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); } /** - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php */ public function testSendFriend() { - $query = - <<productRepository->get('simple_product')->getId(); + $recipients = '{ name: "Recipient Name 1" email:"recipient1@mail.com" }, { name: "Recipient Name 2" email:"recipient2@mail.com" - } - ] - } - ) { - sender { - name - email - message - } - recipients { - name - email - } - } -} -QUERY; + }'; + $query = $this->getQuery($productId, $recipients); $response = $this->graphQlMutation($query); self::assertEquals('Name', $response['sendEmailToFriend']['sender']['name']); @@ -81,41 +62,17 @@ public function testSendFriend() public function testSendWithoutExistProduct() { - $query = - <<getQuery($productId, $recipients); + $this->expectException(\Exception::class); $this->expectExceptionMessage( 'The product that was requested doesn\'t exist. Verify the product and try again.' @@ -124,26 +81,15 @@ public function testSendWithoutExistProduct() } /** - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php */ public function testMaxSendEmailToFriend() { /** @var SendFriend $sendFriend */ $sendFriend = $this->sendFriendFactory->create(); - $query = - <<productRepository->get('simple_product')->getId(); + $recipients = '{ name: "Recipient Name 1" email:"recipient1@mail.com" }, @@ -166,22 +112,10 @@ public function testMaxSendEmailToFriend() { name: "Recipient Name 1" email:"recipient1@mail.com" - } - ] - } - ) { - sender { - name - email - message - } - recipients { - name - email - } - } -} -QUERY; + }'; + + $query = $this->getQuery($productId, $recipients); + $this->expectException(\Exception::class); $this->expectExceptionMessage("No more than {$sendFriend->getMaxRecipients()} emails can be sent at a time."); $this->graphQlMutation($query); @@ -221,7 +155,7 @@ public function testErrors(string $input, string $errorMessage) } /** - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * TODO: use magentoApiConfigFixture (to be merged https://github.com/magento/graphql-ce/pull/351) * @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php */ @@ -231,42 +165,17 @@ public function testLimitMessagesPerHour() /** @var SendFriend $sendFriend */ $sendFriend = $this->sendFriendFactory->create(); - $query = - <<productRepository->get('simple_product')->getId(); + $recipients = '{ name: "Recipient Name 1" email:"recipient1@mail.com" }, - { + { name: "Recipient Name 2" email:"recipient2@mail.com" - } + }'; + $query = $this->getQuery($productId, $recipients); - ] - } - ) { - sender { - name - email - message - } - recipients { - name - email - } - } -} -QUERY; $this->expectException(\Exception::class); $this->expectExceptionMessage( "You can't send messages more than {$sendFriend->getMaxSendsToFriend()} times an hour." @@ -278,6 +187,49 @@ public function testLimitMessagesPerHour() } } + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + */ + public function testSendProductWithoutSenderEmail() + { + $productId = (int)$this->productRepository->get('simple_product')->getId(); + $recipients = '{ + name: "Recipient Name 1" + email:"" + }'; + $query = $this->getQuery($productId, $recipients); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('GraphQL response contains errors: Please provide Email for all of recipients.'); + $this->graphQlMutation($query); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product_without_visibility.php + */ + public function testSendProductWithoutVisibility() + { + $productId = (int)$this->productRepository->get('simple_product_without_visibility')->getId(); + $recipients = '{ + name: "Recipient Name 1" + email:"recipient1@mail.com" + }, + { + name: "Recipient Name 2" + email:"recipient2@mail.com" + }'; + $query = $this->getQuery($productId, $recipients); + + $response = $this->graphQlMutation($query); + self::assertEquals('Name', $response['sendEmailToFriend']['sender']['name']); + self::assertEquals('e@mail.com', $response['sendEmailToFriend']['sender']['email']); + self::assertEquals('Lorem Ipsum', $response['sendEmailToFriend']['sender']['message']); + self::assertEquals('Recipient Name 1', $response['sendEmailToFriend']['recipients'][0]['name']); + self::assertEquals('recipient1@mail.com', $response['sendEmailToFriend']['recipients'][0]['email']); + self::assertEquals('Recipient Name 2', $response['sendEmailToFriend']['recipients'][1]['name']); + self::assertEquals('recipient2@mail.com', $response['sendEmailToFriend']['recipients'][1]['email']); + } + /** * @return array */ @@ -358,4 +310,38 @@ public function sendFriendsErrorsDataProvider() ] ]; } + + /** + * @param int $productId + * @param string $recipients + * @return string + */ + private function getQuery(int $productId, string $recipients): string + { + return <<get(ProductInterfaceFactory::class); +/** @var DataObjectHelper $dataObjectHelper */ +$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class); +/** @var ProductRepositoryInterface $productRepository */ +$productRepository = $objectManager->get(ProductRepositoryInterface::class); + +$product = $productFactory->create(); +$productData = [ + ProductInterface::TYPE_ID => Type::TYPE_SIMPLE, + ProductInterface::ATTRIBUTE_SET_ID => 4, + ProductInterface::SKU => 'simple_product_without_visibility', + ProductInterface::NAME => 'Simple Product Not Visible', + ProductInterface::PRICE => 10, + ProductInterface::VISIBILITY => Visibility::VISIBILITY_NOT_VISIBLE, + ProductInterface::STATUS => Status::STATUS_ENABLED, +]; +$dataObjectHelper->populateWithArray($product, $productData, ProductInterface::class); +/** Out of interface */ +$product + ->setWebsiteIds([1]) + ->setStockData([ + 'qty' => 85.5, + 'is_in_stock' => true, + 'manage_stock' => true, + 'is_qty_decimal' => true + ]); +$productRepository->save($product); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Catalog/_files/simple_product_without_visibility_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Catalog/_files/simple_product_without_visibility_rollback.php new file mode 100644 index 0000000000000..9fe98883053a1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Catalog/_files/simple_product_without_visibility_rollback.php @@ -0,0 +1,31 @@ +get(ProductRepositoryInterface::class); +/** @var Registry $registry */ +$registry = $objectManager->get(Registry::class); + +$currentArea = $registry->registry('isSecureArea'); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +try { + $productRepository->deleteById('simple_product_without_visibility'); +} catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + /** + * Tests which are wrapped with MySQL transaction clear all data by transaction rollback. + */ +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', $currentArea);