This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-4257: 263 test coverage for pr 226 #347
- Loading branch information
Showing
5 changed files
with
451 additions
and
0 deletions.
There are no files selected for viewing
357 changes: 357 additions & 0 deletions
357
dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.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,357 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\SendFriend; | ||
|
||
use Magento\SendFriend\Model\SendFriend; | ||
use Magento\SendFriend\Model\SendFriendFactory; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
class SendFriendTest extends GraphQlAbstract | ||
{ | ||
|
||
/** | ||
* @var SendFriendFactory | ||
*/ | ||
private $sendFriendFactory; | ||
|
||
protected function setUp() | ||
{ | ||
$this->sendFriendFactory = Bootstrap::getObjectManager()->get(SendFriendFactory::class); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
*/ | ||
public function testSendFriend() | ||
{ | ||
$query = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "e@mail.com" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"recipient2@mail.com" | ||
} | ||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
QUERY; | ||
|
||
$response = $this->graphQlQuery($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']); | ||
} | ||
|
||
public function testSendWithoutExistProduct() | ||
{ | ||
$query = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 2018 | ||
sender: { | ||
name: "Name" | ||
email: "e@mail.com" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"recipient2@mail.com" | ||
} | ||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
QUERY; | ||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage( | ||
'The product that was requested doesn\'t exist. Verify the product and try again.' | ||
); | ||
$this->graphQlQuery($query); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
*/ | ||
public function testMaxSendEmailToFriend() | ||
{ | ||
/** @var SendFriend $sendFriend */ | ||
$sendFriend = $this->sendFriendFactory->create(); | ||
|
||
$query = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "e@mail.com" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
} | ||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
QUERY; | ||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage("No more than {$sendFriend->getMaxRecipients()} emails can be sent at a time."); | ||
$this->graphQlQuery($query); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
* @dataProvider sendFriendsErrorsDataProvider | ||
* @param string $input | ||
* @param string $errorMessage | ||
*/ | ||
public function testErrors(string $input, string $errorMessage) | ||
{ | ||
$query = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
$input | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
QUERY; | ||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage($errorMessage); | ||
$this->graphQlQuery($query); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
* TODO: use magentoApiConfigFixture (to be merged https://github.com/magento/graphql-ce/pull/351) | ||
* @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php | ||
*/ | ||
public function testLimitMessagesPerHour() | ||
{ | ||
|
||
/** @var SendFriend $sendFriend */ | ||
$sendFriend = $this->sendFriendFactory->create(); | ||
|
||
$query = | ||
<<<QUERY | ||
mutation { | ||
sendEmailToFriend( | ||
input: { | ||
product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "e@mail.com" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"recipient2@mail.com" | ||
} | ||
] | ||
} | ||
) { | ||
sender { | ||
name | ||
message | ||
} | ||
recipients { | ||
name | ||
} | ||
} | ||
} | ||
QUERY; | ||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage( | ||
"You can't send messages more than {$sendFriend->getMaxSendsToFriend()} times an hour." | ||
); | ||
|
||
for ($i = 0; $i <= $sendFriend->getMaxSendsToFriend() + 1; $i++) { | ||
$this->graphQlQuery($query); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function sendFriendsErrorsDataProvider() | ||
{ | ||
return [ | ||
[ | ||
'product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "e@mail.com" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
name: "" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "" | ||
email:"recipient2@mail.com" | ||
} | ||
]', 'Please provide Name for all of recipients.' | ||
], | ||
[ | ||
'product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "e@mail.com" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
name: "Recipient Name 1" | ||
email:"" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"" | ||
} | ||
]', 'Please provide Email for all of recipients.' | ||
], | ||
[ | ||
'product_id: 1 | ||
sender: { | ||
name: "" | ||
email: "e@mail.com" | ||
message: "Lorem Ipsum" | ||
} | ||
recipients: [ | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"recipient2@mail.com" | ||
} | ||
]', 'Please provide Name of sender.' | ||
], | ||
[ | ||
'product_id: 1 | ||
sender: { | ||
name: "Name" | ||
email: "e@mail.com" | ||
message: "" | ||
} | ||
recipients: [ | ||
{ | ||
name: "Recipient Name 1" | ||
email:"recipient1@mail.com" | ||
}, | ||
{ | ||
name: "Recipient Name 2" | ||
email:"recipient2@mail.com" | ||
} | ||
]', 'Please provide Message.' | ||
] | ||
]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
dev/tests/integration/testsuite/Magento/SendFriend/Fixtures/process_config_data.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,22 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Config\Model\Config; | ||
use Magento\Framework\App\Config\Storage\WriterInterface; | ||
|
||
$processConfigData = function (Config $config, array $data) { | ||
foreach ($data as $key => $value) { | ||
$config->setDataByPath($key, $value); | ||
$config->save(); | ||
} | ||
}; | ||
|
||
$deleteConfigData = function (WriterInterface $writer, array $configData, string $scope, int $scopeId) { | ||
foreach ($configData as $path) { | ||
$writer->delete($path, $scope, $scopeId); | ||
} | ||
}; |
Oops, something went wrong.