Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
ENGCOM-4257: 263 test coverage for pr 226 #347
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav authored Feb 14, 2019
2 parents b35ded1 + aff2d21 commit 6a63e3b
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 0 deletions.
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
email
message
}
recipients {
name
email
}
}
}
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
email
message
}
recipients {
name
email
}
}
}
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
email
message
}
recipients {
name
email
}
}
}
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
email
message
}
recipients {
name
email
}
}
}
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
email
message
}
recipients {
name
email
}
}
}
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.'
]
];
}
}
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);
}
};
Loading

0 comments on commit 6a63e3b

Please sign in to comment.