@@ -34,13 +34,9 @@ protected function setUp(): void
3434 }
3535
3636 /**
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- *
4137 * @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php
4238 */
43- public function testCreateSavesTitleInStoreViewScope (): void
39+ public function testCreateSavesProvidedUrls ()
4440 {
4541 /** @var ProductRepositoryInterface $productRepository */
4642 $ productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
@@ -51,7 +47,7 @@ public function testCreateSavesTitleInStoreViewScope(): void
5147 $ samples = $ this ->model ->getSamples ($ product );
5248 $ this ->assertEmpty ($ samples ->getData ());
5349 $ downloadableSampleData = [
54- 'title ' => 'Store View Title ' ,
50+ 'title ' => 'Sample with URL resource ' ,
5551 'sort_order ' => 1 ,
5652 'sample_url ' => 'http://www.sample.example.com/ ' ,
5753 'sample_type ' => 'url ' ,
@@ -70,13 +66,54 @@ public function testCreateSavesTitleInStoreViewScope(): void
7066 $ product ->setExtensionAttributes ($ extension );
7167 $ productRepository ->save ($ product );
7268
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 = [
7498 'title ' => 'Store View Title ' ,
7599 'sort_order ' => 1 ,
76100 'sample_url ' => 'http://www.sample.example.com/ ' ,
77- 'sample_type ' => 'url ' ,
101+ 'sample_type ' => 'url '
78102 ];
79103
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+
80117 $ samples = $ this ->getTargetProduct (false )->getExtensionAttributes ()->getDownloadableProductSamples ();
81118 $ sample = reset ($ samples );
82119
@@ -86,7 +123,7 @@ public function testCreateSavesTitleInStoreViewScope(): void
86123 /** @var \Magento\Downloadable\Model\Sample $sample */
87124 $ sampleData = $ sample ->getData ();
88125 /** @var \Magento\User\Api\Data\UserInterface $testAttribute */
89- foreach ($ expectedSample as $ key => $ value ) {
126+ foreach ($ downloadableSampleData as $ key => $ value ) {
90127 $ this ->assertArrayHasKey ($ key , $ sampleData );
91128 $ this ->assertEquals ($ value , $ sampleData [$ key ]);
92129 }
0 commit comments