Skip to content

Commit 435c859

Browse files
committed
Merge branch 'MAGETWO-85687-Graphql-Declarative-schema' of github.com:magento-honey-badgers/magento2ce into MAGETWO-85687-Graphql-Declarative-schema
2 parents c4c583a + d9de3bd commit 435c859

File tree

6 files changed

+152
-28
lines changed

6 files changed

+152
-28
lines changed

app/code/Magento/CatalogGraphQl/Model/ConcreteTypeResolver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
1010
use Magento\Framework\Exception\InputException;
1111

12+
/**
13+
* {@inheritdoc}
14+
*/
1215
class ConcreteTypeResolver implements TypeResolverInterface
1316
{
1417
/**

app/code/Magento/CatalogGraphQl/Model/TypeResolverComposite.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
1010
use Magento\Framework\Exception\InputException;
1111

12+
/**
13+
* {@inheritdoc}
14+
*/
1215
class TypeResolverComposite implements TypeResolverInterface
1316
{
1417
/**

app/code/Magento/ConfigurableProductGraphQl/Model/ConcreteTypeResolver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
1010
use Magento\Framework\Exception\InputException;
1111

12+
/**
13+
* {@inheritdoc}
14+
*/
1215
class ConcreteTypeResolver implements TypeResolverInterface
1316
{
1417
/**

app/code/Magento/GraphQl/Test/Unit/Model/Config/_files/graphql_simple_configurable.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<argument xsi:type="ObjectArgument" name="sort" type="ProductSortInput"/>
1414
</field>
1515
</type>
16-
<!-- we need a way to grab currencies enum dynamically -->
1716
<type xsi:type="Enum" name="CurrencyEnum">
1817
<item name="usd">USD</item>
1918
<item name="eur">EUR</item>
@@ -119,7 +118,6 @@
119118
<field xsi:type="ScalarOutputField" name="small_image" type="String"/>
120119
<field xsi:type="ScalarOutputField" name="thumbnail" type="String"/>
121120
<field xsi:type="ScalarOutputField" name="color" type="Int"/>
122-
<!-- TODO: correct name NEW FROM DATE -->
123121
<field xsi:type="ScalarOutputField" name="news_from_date" type="String"/>
124122
<field xsi:type="ScalarOutputField" name="news_to_date" type="String"/>
125123
<field xsi:type="ScalarOutputField" name="tier_price" type="Float"/>

dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php

Lines changed: 133 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,15 @@ class UrlResolverTest extends GraphQlAbstract
1919

2020
/** @var ObjectManager */
2121
private $objectManager;
22-
/**
23-
* @var StoreManagerInterface
24-
*/
25-
// private $storeManager;
26-
27-
/**
28-
* @var \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator
29-
*/
30-
private $urlPathGenerator;
3122

3223
protected function setUp()
3324
{
3425
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
3526
}
3627

3728
/**
29+
* Tests if target_path(canonical_url) is resolved for Product entity
30+
*
3831
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
3932
*/
4033
public function testProductUrlResolver()
@@ -45,15 +38,50 @@ public function testProductUrlResolver()
4538
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
4639
$product = $productRepository->get($productSku, false, null, true);
4740
$storeId = $product->getStoreId();
48-
$product->getUrlKey();
4941

50-
/** @var UrlRewrite $productUrlRewrite */
51-
// $productUrlRewrite = $this->objectManager->get(UrlRewrite::class);
52-
/** @var ProductUrlRewriteGenerator $generator */
53-
// $generator = $this->objectManager->get(ProductUrlRewriteGenerator::class);
42+
/** @var UrlFinderInterface $urlFinder */
43+
$urlFinder = $this->objectManager->get(UrlFinderInterface::class);
44+
$actualUrls = $urlFinder->findOneByData(
45+
[
46+
'request_path' =>$urlPath,
47+
'store_id' => $storeId
48+
]
49+
);
50+
$targetPath = $actualUrls->getTargetPath();
51+
$expectedType = $actualUrls->getEntityType();
52+
$query
53+
= <<<QUERY
54+
{
55+
urlResolver(url:"{$urlPath}")
56+
{
57+
id
58+
canonical_url
59+
type
60+
}
61+
62+
}
63+
QUERY;
64+
$response = $this->graphQlQuery($query);
65+
$this->assertArrayHasKey('urlResolver', $response);
66+
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
67+
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
68+
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
69+
}
5470

55-
/** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $urls */
56-
// $urls = $generator->generate($product);
71+
/**
72+
* Tests the use case where canonical_url is provided as resolver input in the Query
73+
*
74+
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
75+
*/
76+
public function testProductUrlWithCanonicalUrlInput()
77+
{
78+
$productSku = 'p002';
79+
$urlPath = 'p002.html';
80+
/** @var ProductRepositoryInterface $productRepository */
81+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
82+
$product = $productRepository->get($productSku, false, null, true);
83+
$storeId = $product->getStoreId();
84+
$product->getUrlKey();
5785

5886
/** @var UrlFinderInterface $urlFinder */
5987
$urlFinder = $this->objectManager->get(UrlFinderInterface::class);
@@ -65,10 +93,11 @@ public function testProductUrlResolver()
6593
);
6694
$targetPath = $actualUrls->getTargetPath();
6795
$expectedType = $actualUrls->getEntityType();
96+
$canonicalPath = $actualUrls->getTargetPath();
6897
$query
6998
= <<<QUERY
7099
{
71-
urlResolver(url:"{$urlPath}")
100+
urlResolver(url:"{$canonicalPath}")
72101
{
73102
id
74103
canonical_url
@@ -85,7 +114,9 @@ public function testProductUrlResolver()
85114
}
86115

87116
/**
88-
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
117+
* Test for category entity
118+
*
119+
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
89120
*/
90121
public function testCategoryUrlResolver()
91122
{
@@ -96,14 +127,6 @@ public function testCategoryUrlResolver()
96127
$product = $productRepository->get($productSku, false, null, true);
97128
$storeId = $product->getStoreId();
98129

99-
/** @var UrlRewrite $productUrlRewrite */
100-
// $productUrlRewrite = $this->objectManager->get(UrlRewrite::class);
101-
/** @var ProductUrlRewriteGenerator $generator */
102-
// $generator = $this->objectManager->get(ProductUrlRewriteGenerator::class);
103-
104-
/** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $urls */
105-
// $urls = $generator->generate($product);
106-
107130
/** @var UrlFinderInterface $urlFinder */
108131
$urlFinder = $this->objectManager->get(UrlFinderInterface::class);
109132
$actualUrls = $urlFinder->findOneByData(
@@ -133,4 +156,88 @@ public function testCategoryUrlResolver()
133156
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
134157
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
135158
}
159+
160+
/**
161+
* Tests the use case where the url_key of the existing product is changed
162+
*
163+
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
164+
*/
165+
public function testProductUrlRewriteResolver()
166+
{
167+
$productSku = 'p002';
168+
/** @var ProductRepositoryInterface $productRepository */
169+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
170+
$product = $productRepository->get($productSku, false, null, true);
171+
$storeId = $product->getStoreId();
172+
$product->setUrlKey('p002-new')->save();
173+
$urlPath = $product->getUrlKey() .'.html';
174+
$this->assertEquals($urlPath, 'p002-new.html');
175+
176+
/** @var UrlFinderInterface $urlFinder */
177+
$urlFinder = $this->objectManager->get(UrlFinderInterface::class);
178+
$actualUrls = $urlFinder->findOneByData(
179+
[
180+
'request_path' =>$urlPath,
181+
'store_id' => $storeId
182+
]
183+
);
184+
$targetPath = $actualUrls->getTargetPath();
185+
$expectedType = $actualUrls->getEntityType();
186+
$query
187+
= <<<QUERY
188+
{
189+
urlResolver(url:"{$urlPath}")
190+
{
191+
id
192+
canonical_url
193+
type
194+
}
195+
196+
}
197+
QUERY;
198+
$response = $this->graphQlQuery($query);
199+
$this->assertArrayHasKey('urlResolver', $response);
200+
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
201+
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
202+
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
203+
}
204+
205+
/**
206+
* Tests if null is returned when an invalid request_path is provided as input to urlResolver
207+
*
208+
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
209+
*/
210+
public function testInvalidUrlResolverInput()
211+
{
212+
$productSku = 'p002';
213+
$urlPath = 'p002';
214+
/** @var ProductRepositoryInterface $productRepository */
215+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
216+
$product = $productRepository->get($productSku, false, null, true);
217+
$storeId = $product->getStoreId();
218+
219+
/** @var UrlFinderInterface $urlFinder */
220+
$urlFinder = $this->objectManager->get(UrlFinderInterface::class);
221+
$urlFinder->findOneByData(
222+
[
223+
'request_path' =>$urlPath,
224+
'store_id' => $storeId
225+
]
226+
);
227+
$query
228+
= <<<QUERY
229+
{
230+
urlResolver(url:"{$urlPath}")
231+
{
232+
id
233+
canonical_url
234+
type
235+
}
236+
237+
}
238+
QUERY;
239+
$response = $this->graphQlQuery($query);
240+
$this->assertArrayHasKey('urlResolver', $response);
241+
$this->assertNull($response['urlResolver']);
242+
}
136243
}

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_category.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@
6060
->setAttributeSetId(4)
6161
->setWebsiteIds([1])
6262
->setPrice(10)
63+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
64+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
65+
->setStockData(
66+
[
67+
'use_config_manage_stock' => 1,
68+
'qty' => 100,
69+
'is_qty_decimal' => 0,
70+
'is_in_stock' => 1,
71+
]
72+
)
6373
->setQty(100)
6474
->setWeight(1);
6575

0 commit comments

Comments
 (0)