Skip to content

Commit 486d383

Browse files
committed
Moved old acceptance test
1 parent cc2872d commit 486d383

File tree

2 files changed

+75
-232
lines changed

2 files changed

+75
-232
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerDownloadableProduct/CustomerDownloadableProductTest.php

Lines changed: 75 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -7,139 +7,100 @@
77

88
namespace Magento\GraphQl\CustomerDownloadableProduct;
99

10+
use Magento\Integration\Api\CustomerTokenServiceInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
1012
use Magento\TestFramework\TestCase\GraphQlAbstract;
11-
use Magento\TestFramework\ObjectManager;
12-
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
13-
use Magento\Customer\Api\CustomerRepositoryInterface;
14-
use Magento\Sales\Api\OrderRepositoryInterface;
15-
use Magento\Framework\Api\SearchCriteriaBuilder;
1613

14+
/**
15+
* Test retrieving of customer downloadable products.
16+
*/
1717
class CustomerDownloadableProductTest extends GraphQlAbstract
1818
{
19-
2019
/**
21-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
20+
* @var CustomerTokenServiceInterface
21+
*/
22+
private $customerTokenService;
23+
/**
24+
* @inheritdoc
25+
*/
26+
protected function setUp()
27+
{
28+
$objectManager = Bootstrap::getObjectManager();
29+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
30+
}
31+
/**
2232
* @magentoApiDataFixture Magento/Customer/_files/customer.php
2333
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
24-
* @magentoApiDataFixture Magento/Downloadable/_files/order_with_downloadable_product.php
34+
* @magentoApiDataFixture Magento/Downloadable/_files/customer_order_with_downloadable_product.php
2535
*/
26-
public function testGetCustomerDownloadableProducts()
36+
public function testCustomerDownloadableProducts()
2737
{
28-
$query = <<<MUTATION
29-
mutation {
30-
generateCustomerToken(
31-
email: "customer@example.com"
32-
password: "password"
33-
) {
34-
token
35-
}
36-
}
37-
MUTATION;
38-
$response = $this->graphQlMutation($query);
39-
$token = $response['generateCustomerToken']['token'];
40-
$this->headers = ['Authorization' => 'Bearer ' . $token];
41-
42-
$query = <<<QUERY
43-
{
44-
customerDownloadableProducts{
45-
items{
46-
order_increment_id
47-
date
48-
status
49-
download_url
50-
remaining_downloads
51-
}
38+
$query = $this->getQuery();
39+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
40+
41+
self::assertArrayHasKey('items', $response['customerDownloadableProducts']);
42+
self::assertCount(1, $response['customerDownloadableProducts']['items']);
43+
self::assertArrayHasKey('date', $response['customerDownloadableProducts']['items'][0]);
44+
self::assertNotEmpty($response['customerDownloadableProducts']['items'][0]['date']);
45+
self::assertArrayHasKey('download_url', $response['customerDownloadableProducts']['items'][0]);
46+
self::assertNotEmpty($response['customerDownloadableProducts']['items'][0]['download_url']);
47+
self::assertArrayHasKey('order_increment_id', $response['customerDownloadableProducts']['items'][0]);
48+
self::assertNotEmpty($response['customerDownloadableProducts']['items'][0]['order_increment_id']);
49+
self::assertArrayHasKey('remaining_downloads', $response['customerDownloadableProducts']['items'][0]);
50+
self::assertNotEmpty($response['customerDownloadableProducts']['items'][0]['remaining_downloads']);
51+
self::assertArrayHasKey('status', $response['customerDownloadableProducts']['items'][0]);
52+
self::assertNotEmpty($response['customerDownloadableProducts']['items'][0]['status']);
5253
}
53-
54-
}
55-
QUERY;
56-
$objectManager = ObjectManager::getInstance();
57-
58-
$searchCriteria = $objectManager->get(SearchCriteriaBuilder::class)->create();
59-
60-
$orderRepository = $objectManager->create(OrderRepositoryInterface::class);
61-
$orders = $orderRepository->getList($searchCriteria)->getItems();
62-
$order = array_pop($orders);
63-
64-
$searchCriteria = $objectManager->get(
65-
SearchCriteriaBuilder::class
66-
)->addFilter(
67-
'email',
68-
'customer@example.com'
69-
)->create();
70-
71-
$customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
72-
$customers = $customerRepository->getList($searchCriteria)
73-
->getItems();
74-
$customer = array_pop($customers);
75-
76-
$order->setCustomerId($customer->getId())->setCustomerIsGuest(false)->save();
77-
$response = $this->graphQlQuery($query, [], '', $this->headers);
78-
79-
$this->assertEquals(
80-
$order->getIncrementId(),
81-
$response['customerDownloadableProducts']['items'][0]['order_increment_id']
82-
);
83-
}
84-
8554
/**
86-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
8755
* @magentoApiDataFixture Magento/Customer/_files/customer.php
56+
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
57+
* @magentoApiDataFixture Magento/Downloadable/_files/customer_order_with_downloadable_product.php
58+
*
59+
* @expectedException \Exception
60+
* @expectedExceptionMessage The current customer isn't authorized.
8861
*/
89-
public function testGetCustomerDownloadableProductsIfProductsDoNotExist()
62+
public function testGuestCannotAccessDownloadableProducts()
9063
{
91-
$query = <<<MUTATION
92-
mutation {
93-
generateCustomerToken(
94-
email: "customer@example.com"
95-
password: "password"
96-
) {
97-
token
98-
}
99-
}
100-
MUTATION;
101-
$response = $this->graphQlMutation($query);
102-
$token = $response['generateCustomerToken']['token'];
103-
$this->headers = ['Authorization' => 'Bearer ' . $token];
104-
105-
$query = <<<QUERY
106-
{
107-
customerDownloadableProducts{
108-
items{
109-
order_increment_id
110-
date
111-
status
112-
download_url
113-
remaining_downloads
114-
}
64+
$this->graphQlQuery($this->getQuery());
11565
}
116-
117-
}
118-
QUERY;
119-
120-
$response = $this->graphQlQuery($query, [], '', $this->headers);
121-
$this->assertEmpty($response['customerDownloadableProducts']['items']);
66+
/**
67+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
68+
*/
69+
public function testCustomerHasNoOrders()
70+
{
71+
$query = $this->getQuery();
72+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
73+
self::assertArrayHasKey('items', $response['customerDownloadableProducts']);
74+
self::assertCount(0, $response['customerDownloadableProducts']['items']);
12275
}
123-
124-
public function testGuestCannotAccessDownloadableProducts()
76+
/**
77+
* @return string
78+
*/
79+
private function getQuery(): string
12580
{
126-
$query = <<<QUERY
127-
{
128-
customerDownloadableProducts{
129-
items{
130-
order_increment_id
131-
date
132-
status
133-
download_url
134-
remaining_downloads
135-
}
81+
return <<<QUERY
82+
{
83+
customerDownloadableProducts {
84+
items {
85+
date
86+
download_url
87+
order_increment_id
88+
remaining_downloads
89+
status
13690
}
137-
91+
}
13892
}
13993
QUERY;
140-
141-
$this->expectException(ResponseContainsErrorsException::class);
142-
$this->expectExceptionMessage('GraphQL response contains errors: The current customer isn\'t authorized');
143-
$this->graphQlQuery($query);
94+
}
95+
/**
96+
* @param string $username
97+
* @param string $password
98+
* @return array
99+
* @throws \Magento\Framework\Exception\AuthenticationException
100+
*/
101+
private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array
102+
{
103+
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password);
104+
return ['Authorization' => 'Bearer ' . $customerToken];
144105
}
145106
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Downloadable/CustomerDownloadableProductsTest.php

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)