1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2019 Adobe
4
+ * All rights reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \GraphQl \Catalog ;
9
9
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 ;
16
12
use 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 ;
17
16
18
17
/**
19
18
* Test for getting canonical_url for products
20
19
*/
21
20
class ProductCanonicalUrlTest extends GraphQlAbstract
22
21
{
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
+ ]
39
27
public function testProductWithCanonicalLinksMetaTagSettingsEnabled ()
40
28
{
41
- $ this ->reindex ();
42
- $ productSku = 'simple ' ;
29
+ $ product = DataFixtureStorageManager::getStorage ()->get ('product ' );
30
+ $ productSku = $ product ->getSku ();
31
+ $ productCanonicalUrl = $ product ->getUrlKey ();
43
32
$ query
44
33
= <<<QUERY
45
34
{
@@ -57,19 +46,21 @@ public function testProductWithCanonicalLinksMetaTagSettingsEnabled()
57
46
$ this ->assertNotEmpty ($ response ['products ' ]['items ' ]);
58
47
59
48
$ this ->assertEquals (
60
- ' simple-product .html ' ,
49
+ $ productCanonicalUrl . ' .html ' ,
61
50
$ response ['products ' ]['items ' ][0 ]['canonical_url ' ]
62
51
);
63
- $ this ->assertEquals (' simple ' , $ response ['products ' ]['items ' ][0 ]['sku ' ]);
52
+ $ this ->assertEquals ($ productSku , $ response ['products ' ]['items ' ][0 ]['sku ' ]);
64
53
}
65
54
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
+ ]
70
60
public function testProductWithCanonicalLinksMetaTagSettingsDisabled ()
71
61
{
72
- $ productSku = 'simple ' ;
62
+ $ product = DataFixtureStorageManager::getStorage ()->get ('product ' );
63
+ $ productSku = $ product ->getSku ();
73
64
$ query
74
65
= <<<QUERY
75
66
{
@@ -87,17 +78,6 @@ public function testProductWithCanonicalLinksMetaTagSettingsDisabled()
87
78
$ this ->assertNull (
88
79
$ response ['products ' ]['items ' ][0 ]['canonical_url ' ]
89
80
);
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 ' ]);
102
82
}
103
83
}
0 commit comments