@@ -34,13 +34,9 @@ protected function setUp(): void
34
34
}
35
35
36
36
/**
37
- * Originally this test belonged to \Magento\Downloadable\Api\SampleRepositoryTest
38
- * but it was moved to integration tests
39
- * because of error on CI builds that sample URL's domain is not in the list of downloadable_domains in env.php
40
- *
41
37
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php
42
38
*/
43
- public function testCreateSavesTitleInStoreViewScope (): void
39
+ public function testCreateSavesProvidedUrls ()
44
40
{
45
41
/** @var ProductRepositoryInterface $productRepository */
46
42
$ productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
@@ -51,7 +47,7 @@ public function testCreateSavesTitleInStoreViewScope(): void
51
47
$ samples = $ this ->model ->getSamples ($ product );
52
48
$ this ->assertEmpty ($ samples ->getData ());
53
49
$ downloadableSampleData = [
54
- 'title ' => 'Store View Title ' ,
50
+ 'title ' => 'Sample with URL resource ' ,
55
51
'sort_order ' => 1 ,
56
52
'sample_url ' => 'http://www.sample.example.com/ ' ,
57
53
'sample_type ' => 'url ' ,
@@ -70,13 +66,54 @@ public function testCreateSavesTitleInStoreViewScope(): void
70
66
$ product ->setExtensionAttributes ($ extension );
71
67
$ productRepository ->save ($ product );
72
68
73
- $ expectedSample = [
69
+ $ samples = $ this ->getTargetProduct (false )->getExtensionAttributes ()->getDownloadableProductSamples ();
70
+ $ sample = reset ($ samples );
71
+
72
+ $ this ->assertNotEmpty ($ sample ->getData ());
73
+ $ this ->assertCount (1 , $ samples );
74
+
75
+ /** @var \Magento\Downloadable\Model\Sample $sample */
76
+ $ sampleData = $ sample ->getData ();
77
+ /** @var \Magento\User\Api\Data\UserInterface $testAttribute */
78
+ foreach ($ downloadableSampleData as $ key => $ value ) {
79
+ $ this ->assertArrayHasKey ($ key , $ sampleData );
80
+ $ this ->assertEquals ($ value , $ sampleData [$ key ]);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php
86
+ */
87
+ public function testCreateSavesTitleInStoreViewScope (): void
88
+ {
89
+ /** @var ProductRepositoryInterface $productRepository */
90
+ $ productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
91
+ $ product = $ this ->getTargetProduct (false );
92
+
93
+ $ links = $ this ->model ->getLinks ($ product );
94
+ $ this ->assertNotEmpty ($ links );
95
+ $ samples = $ this ->model ->getSamples ($ product );
96
+ $ this ->assertEmpty ($ samples ->getData ());
97
+ $ downloadableSampleData = [
74
98
'title ' => 'Store View Title ' ,
75
99
'sort_order ' => 1 ,
76
100
'sample_url ' => 'http://www.sample.example.com/ ' ,
77
- 'sample_type ' => 'url ' ,
101
+ 'sample_type ' => 'url '
78
102
];
79
103
104
+ $ sampleFactory = $ this ->objectManager ->create (SampleInterfaceFactory::class);
105
+ $ extension = $ product ->getExtensionAttributes ();
106
+ $ sample = $ sampleFactory ->create (['data ' => $ downloadableSampleData ]);
107
+ $ sample ->setStoreId ($ product ->getStoreId ());
108
+ $ sample ->setSampleType ($ downloadableSampleData ['sample_type ' ]);
109
+ $ sample ->setSampleUrl ($ downloadableSampleData ['sample_url ' ]);
110
+ if (!$ sample ->getSortOrder ()) {
111
+ $ sample ->setSortOrder (1 );
112
+ }
113
+ $ extension ->setDownloadableProductSamples ([$ sample ]);
114
+ $ product ->setExtensionAttributes ($ extension );
115
+ $ productRepository ->save ($ product );
116
+
80
117
$ samples = $ this ->getTargetProduct (false )->getExtensionAttributes ()->getDownloadableProductSamples ();
81
118
$ sample = reset ($ samples );
82
119
@@ -86,7 +123,7 @@ public function testCreateSavesTitleInStoreViewScope(): void
86
123
/** @var \Magento\Downloadable\Model\Sample $sample */
87
124
$ sampleData = $ sample ->getData ();
88
125
/** @var \Magento\User\Api\Data\UserInterface $testAttribute */
89
- foreach ($ expectedSample as $ key => $ value ) {
126
+ foreach ($ downloadableSampleData as $ key => $ value ) {
90
127
$ this ->assertArrayHasKey ($ key , $ sampleData );
91
128
$ this ->assertEquals ($ value , $ sampleData [$ key ]);
92
129
}
0 commit comments