11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2019 Adobe
4+ * All rights reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \GraphQl \Catalog ;
99
10- use Magento \Catalog \Model \Indexer \Category \Product ;
11- use Magento \Catalog \Model \Indexer \Product \Category ;
12- use Magento \CatalogSearch \Model \Indexer \Fulltext as IndexerSearch ;
13- use Magento \Indexer \Model \Indexer ;
14- use Magento \TestFramework \Helper \Bootstrap ;
15- use Magento \TestFramework \ObjectManager ;
10+ use Magento \Indexer \Test \Fixture \Indexer as IndexerFixture ;
11+ use Magento \TestFramework \Fixture \Config ;
1612use Magento \TestFramework \TestCase \GraphQlAbstract ;
13+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
14+ use Magento \TestFramework \Fixture \DataFixture ;
15+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
1716
1817/**
1918 * Test for getting canonical_url for products
2019 */
2120class ProductCanonicalUrlTest extends GraphQlAbstract
2221{
23- /** @var ObjectManager */
24- private $ objectManager ;
25-
26- /**
27- * @inheritdoc
28- */
29- protected function setUp (): void
30- {
31- $ this ->objectManager = Bootstrap::getObjectManager ();
32- }
33-
34- /**
35- * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
36- * @magentoConfigFixture default_store catalog/seo/product_canonical_tag 1
37- *
38- */
22+ #[
23+ Config('catalog/seo/product_canonical_tag ' , 1 ),
24+ DataFixture(ProductFixture::class, as: 'product ' ),
25+ DataFixture(IndexerFixture::class)
26+ ]
3927 public function testProductWithCanonicalLinksMetaTagSettingsEnabled ()
4028 {
41- $ this ->reindex ();
42- $ productSku = 'simple ' ;
29+ $ product = DataFixtureStorageManager::getStorage ()->get ('product ' );
30+ $ productSku = $ product ->getSku ();
31+ $ productCanonicalUrl = $ product ->getUrlKey ();
4332 $ query
4433 = <<<QUERY
4534{
@@ -57,19 +46,21 @@ public function testProductWithCanonicalLinksMetaTagSettingsEnabled()
5746 $ this ->assertNotEmpty ($ response ['products ' ]['items ' ]);
5847
5948 $ this ->assertEquals (
60- ' simple-product .html ' ,
49+ $ productCanonicalUrl . ' .html ' ,
6150 $ response ['products ' ]['items ' ][0 ]['canonical_url ' ]
6251 );
63- $ this ->assertEquals (' simple ' , $ response ['products ' ]['items ' ][0 ]['sku ' ]);
52+ $ this ->assertEquals ($ productSku , $ response ['products ' ]['items ' ][0 ]['sku ' ]);
6453 }
6554
66- /**
67- * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
68- * @magentoConfigFixture default_store catalog/seo/product_canonical_tag 0
69- */
55+ #[
56+ Config('catalog/seo/product_canonical_tag ' , 0 ),
57+ DataFixture(ProductFixture::class, as: 'product ' ),
58+ DataFixture(IndexerFixture::class)
59+ ]
7060 public function testProductWithCanonicalLinksMetaTagSettingsDisabled ()
7161 {
72- $ productSku = 'simple ' ;
62+ $ product = DataFixtureStorageManager::getStorage ()->get ('product ' );
63+ $ productSku = $ product ->getSku ();
7364 $ query
7465 = <<<QUERY
7566{
@@ -87,17 +78,6 @@ public function testProductWithCanonicalLinksMetaTagSettingsDisabled()
8778 $ this ->assertNull (
8879 $ response ['products ' ]['items ' ][0 ]['canonical_url ' ]
8980 );
90- $ this ->assertEquals ('simple ' , $ response ['products ' ]['items ' ][0 ]['sku ' ]);
91- }
92-
93- private function reindex ()
94- {
95- $ indexer = $ this ->objectManager ->create (Indexer::class);
96- $ indexer ->load (Product::INDEXER_ID );
97- $ indexer ->reindexAll ();
98- $ indexer ->load (Category::INDEXER_ID );
99- $ indexer ->reindexAll ();
100- $ indexer ->load (IndexerSearch::INDEXER_ID );
101- $ indexer ->reindexAll ();
81+ $ this ->assertEquals ($ productSku , $ response ['products ' ]['items ' ][0 ]['sku ' ]);
10282 }
10383}
0 commit comments