|
8 | 8 | namespace Magento\GraphQl\CustomerDownloadableProduct;
|
9 | 9 |
|
10 | 10 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
| 11 | +use Magento\TestFramework\ObjectManager; |
| 12 | +use Magento\Customer\Api\CustomerRepositoryInterface; |
| 13 | +use Magento\Sales\Api\OrderRepositoryInterface; |
| 14 | +use Magento\Framework\Api\SearchCriteriaBuilder; |
11 | 15 |
|
12 | 16 | class CustomerDownloadableProductTest extends GraphQlAbstract
|
13 | 17 | {
|
| 18 | + |
14 | 19 | /**
|
15 | 20 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
16 | 21 | * @magentoApiDataFixture Magento/Customer/_files/customer.php
|
17 | 22 | * @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
|
| 23 | + * @magentoApiDataFixture Magento/Downloadable/_files/order_with_downloadable_product.php |
18 | 24 | */
|
19 | 25 | public function testGetCustomerDownloadableProducts()
|
20 | 26 | {
|
@@ -46,7 +52,49 @@ public function testGetCustomerDownloadableProducts()
|
46 | 52 |
|
47 | 53 | }
|
48 | 54 | QUERY;
|
| 55 | + $objectManager = ObjectManager::getInstance(); |
| 56 | + |
| 57 | + $searchCriteria = $objectManager->get(SearchCriteriaBuilder::class)->create(); |
| 58 | + |
| 59 | + $orderRepository = $objectManager->create(OrderRepositoryInterface::class); |
| 60 | + $orders = $orderRepository->getList($searchCriteria)->getItems(); |
| 61 | + $order = array_pop($orders); |
| 62 | + |
| 63 | + $builder = $objectManager->create(\Magento\Framework\Api\FilterBuilder::class); |
| 64 | + $filter = $builder |
| 65 | + ->setField('email') |
| 66 | + ->setValue('customer@example.com'); |
| 67 | + |
| 68 | + $searchCriteria = $objectManager->get( |
| 69 | + SearchCriteriaBuilder::class |
| 70 | + )->addFilter( |
| 71 | + 'email', |
| 72 | + 'customer@example.com' |
| 73 | + )->create(); |
| 74 | + |
| 75 | + $customerRepository = $objectManager->create(CustomerRepositoryInterface::class); |
| 76 | + $customers = $customerRepository->getList($searchCriteria) |
| 77 | + ->getItems(); |
| 78 | + $customer = array_pop($customers); |
| 79 | + |
| 80 | + $order->setCustomerId($customer->getId())->setCustomerIsGuest(false)->save(); |
49 | 81 |
|
50 | 82 | $response = $this->graphQlQuery($query, [], '', $this->headers);
|
| 83 | + |
| 84 | + $expectedResponse = [ |
| 85 | + 'customerDownloadableProducts' => [ |
| 86 | + 'items' => [ |
| 87 | + [ |
| 88 | + 'order_increment_id' => $order->getIncrementId(), |
| 89 | + 'date' => '', |
| 90 | + 'status' => 'pending', |
| 91 | + 'download_url' => 'http://example.com/downloadable.txt', |
| 92 | + 'remaining_downloads' => '1' |
| 93 | + ] |
| 94 | + ] |
| 95 | + ] |
| 96 | + ]; |
| 97 | + |
| 98 | + $this->assertEquals($expectedResponse, $response); |
51 | 99 | }
|
52 | 100 | }
|
0 commit comments