forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-5097: 678 Add Tests Email Sender empty send product wich not v…
…isible in catalog magento#696
- Loading branch information
Showing
3 changed files
with
182 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "[email protected]" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
$productId = (int)$this->productRepository->get('simple_product')->getId(); | ||
$recipients = '{ | ||
name: "Recipient Name 1" | ||
email:"[email protected]" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"[email protected]" | ||
} | ||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
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 = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 2018 | ||
sender: { | ||
name: "Name" | ||
email: "[email protected]" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
$productId = 2018; | ||
$recipients = '{ | ||
name: "Recipient Name 1" | ||
email:"[email protected]" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"[email protected]" | ||
} | ||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
QUERY; | ||
}'; | ||
$query = $this->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 = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "[email protected]" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
$productId = (int)$this->productRepository->get('simple_product')->getId(); | ||
$recipients = '{ | ||
name: "Recipient Name 1" | ||
email:"[email protected]" | ||
}, | ||
|
@@ -166,22 +112,10 @@ public function testMaxSendEmailToFriend() | |
{ | ||
name: "Recipient Name 1" | ||
email:"[email protected]" | ||
} | ||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
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 = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "[email protected]" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
$productId = (int)$this->productRepository->get('simple_product')->getId(); | ||
$recipients = '{ | ||
name: "Recipient Name 1" | ||
email:"[email protected]" | ||
}, | ||
{ | ||
{ | ||
name: "Recipient Name 2" | ||
email:"[email protected]" | ||
} | ||
}'; | ||
$query = $this->getQuery($productId, $recipients); | ||
|
||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
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:"[email protected]" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"[email protected]" | ||
}'; | ||
$query = $this->getQuery($productId, $recipients); | ||
|
||
$response = $this->graphQlMutation($query); | ||
self::assertEquals('Name', $response['sendEmailToFriend']['sender']['name']); | ||
self::assertEquals('[email protected]', $response['sendEmailToFriend']['sender']['email']); | ||
self::assertEquals('Lorem Ipsum', $response['sendEmailToFriend']['sender']['message']); | ||
self::assertEquals('Recipient Name 1', $response['sendEmailToFriend']['recipients'][0]['name']); | ||
self::assertEquals('[email protected]', $response['sendEmailToFriend']['recipients'][0]['email']); | ||
self::assertEquals('Recipient Name 2', $response['sendEmailToFriend']['recipients'][1]['name']); | ||
self::assertEquals('[email protected]', $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 <<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: {$productId} | ||
sender: { | ||
name: "Name" | ||
email: "[email protected]" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [{$recipients}] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ntegration/testsuite/Magento/GraphQl/Catalog/_files/simple_product_without_visibility.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Catalog\Api\Data\ProductInterfaceFactory; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Catalog\Model\Product\Type; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\Framework\Api\DataObjectHelper; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var ProductInterfaceFactory $productFactory */ | ||
$productFactory = $objectManager->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); |
31 changes: 31 additions & 0 deletions
31
...n/testsuite/Magento/GraphQl/Catalog/_files/simple_product_without_visibility_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Framework\Registry; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->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); |