Skip to content

Commit c998b54

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-66077' into MAGETWO-66039
2 parents 1cbbb7b + 71181ca commit c998b54

File tree

27 files changed

+1180
-90
lines changed

27 files changed

+1180
-90
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Gallery.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public function createBatchBaseSelect($storeId, $attributeId)
177177
[
178178
$mainTableAlias . '.value_id = value.value_id',
179179
$this->getConnection()->quoteInto('value.store_id = ?', (int)$storeId),
180+
'value.' . $linkField . ' = entity.' . $linkField,
180181
]
181182
),
182183
['label', 'position', 'disabled']
@@ -187,6 +188,7 @@ public function createBatchBaseSelect($storeId, $attributeId)
187188
[
188189
$mainTableAlias . '.value_id = default_value.value_id',
189190
$this->getConnection()->quoteInto('default_value.store_id = ?', Store::DEFAULT_STORE_ID),
191+
'default_value.' . $linkField . ' = entity.' . $linkField,
190192
]
191193
),
192194
['label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled']

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/GalleryTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ public function testLoadGallery()
317317
$attributeId = 6;
318318
$getTableReturnValue = 'table';
319319
$quoteInfoReturnValue =
320-
'main.value_id = value.value_id AND value.store_id = ' . $storeId;
320+
'main.value_id = value.value_id AND value.store_id = ' . $storeId
321+
. ' AND value.entity_id = entity.entity_id';
322+
$quoteDefaultInfoReturnValue =
323+
'main.value_id = default_value.value_id AND default_value.store_id = 0'
324+
. ' AND default_value.entity_id = entity.entity_id';
325+
321326
$positionCheckSql = 'testchecksql';
322327
$resultRow = [
323328
[
@@ -373,7 +378,7 @@ public function testLoadGallery()
373378
)->willReturnSelf();
374379
$this->select->expects($this->at(3))->method('joinLeft')->with(
375380
['default_value' => $getTableReturnValue],
376-
'main.value_id = default_value.value_id AND default_value.store_id = 0',
381+
$quoteDefaultInfoReturnValue,
377382
['label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled']
378383
)->willReturnSelf();
379384
$this->select->expects($this->at(4))->method('where')->with(

app/code/Magento/Paypal/Model/Report/Settlement.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Settlement extends \Magento\Framework\Model\AbstractModel
165165

166166
/**
167167
* Columns with DateTime data type
168-
*
168+
*
169169
* @var array
170170
*/
171171
private $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date'];
@@ -178,15 +178,21 @@ class Settlement extends \Magento\Framework\Model\AbstractModel
178178
private $amountColumns = ['gross_transaction_amount', 'fee_amount'];
179179

180180
/**
181-
* @param \Magento\Framework\Model\Context $context
182-
* @param \Magento\Framework\Registry $registry
183-
* @param \Magento\Framework\Filesystem $filesystem
184-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
185-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
186-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
187-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
188-
* @param array $data
189-
*/
181+
* @var \Magento\Framework\Serialize\Serializer\Json
182+
*/
183+
private $serializer;
184+
185+
/**
186+
* @param \Magento\Framework\Model\Context $context
187+
* @param \Magento\Framework\Registry $registry
188+
* @param \Magento\Framework\Filesystem $filesystem
189+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
190+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
191+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
192+
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
193+
* @param array $data
194+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
195+
*/
190196
public function __construct(
191197
\Magento\Framework\Model\Context $context,
192198
\Magento\Framework\Registry $registry,
@@ -195,12 +201,15 @@ public function __construct(
195201
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
196202
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
197203
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
198-
array $data = []
204+
array $data = [],
205+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
199206
) {
200207
$this->_tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
201208
$this->_storeManager = $storeManager;
202209
$this->_scopeConfig = $scopeConfig;
203210
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
211+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
212+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
204213
}
205214

206215
/**
@@ -305,14 +314,14 @@ public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
305314
public static function createConnection(array $config)
306315
{
307316
if (!isset(
308-
$config['hostname']
309-
) || !isset(
310-
$config['username']
311-
) || !isset(
312-
$config['password']
313-
) || !isset(
314-
$config['path']
315-
)
317+
$config['hostname']
318+
) || !isset(
319+
$config['username']
320+
) || !isset(
321+
$config['password']
322+
) || !isset(
323+
$config['path']
324+
)
316325
) {
317326
throw new \InvalidArgumentException('Required config elements: hostname, username, password, path');
318327
}
@@ -424,7 +433,7 @@ private function getBodyItems(array $line, array $sectionColumns, array $rowMap)
424433

425434
/**
426435
* Format date columns in UTC
427-
*
436+
*
428437
* @param string $lineItem
429438
* @return string
430439
*/
@@ -574,10 +583,10 @@ public function getSftpCredentials($automaticMode = false)
574583
$cfg['path'] = self::REPORTS_PATH;
575584
}
576585
// avoid duplicates
577-
if (in_array(serialize($cfg), $uniques)) {
586+
if (in_array($this->serializer->serialize($cfg), $uniques)) {
578587
continue;
579588
}
580-
$uniques[] = serialize($cfg);
589+
$uniques[] = $this->serializer->serialize($cfg);
581590
$configs[] = $cfg;
582591
}
583592
return $configs;

dev/tests/integration/testsuite/Magento/Paypal/Model/Report/SettlementTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ public function testCreateConnectionException($config)
3333
\Magento\Paypal\Model\Report\Settlement::createConnection($config);
3434
}
3535

36+
/**
37+
* @param array $automaticMode
38+
* @param array $expectedResult
39+
*
40+
* @dataProvider createAutomaticModeDataProvider
41+
*
42+
* @magentoConfigFixture default_store paypal/fetch_reports/active 0
43+
* @magentoConfigFixture default_store paypal/fetch_reports/ftp_ip 192.168.0.1
44+
* @magentoConfigFixture current_store paypal/fetch_reports/active 1
45+
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_ip 127.0.0.1
46+
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_path /tmp
47+
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_login login
48+
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_password password
49+
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_sandbox 0
50+
* @magentoDbIsolation enabled
51+
*/
52+
public function testGetSftpCredentials($automaticMode, $expectedResult)
53+
{
54+
/** @var $model \Magento\Paypal\Model\Report\Settlement; */
55+
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
56+
\Magento\Paypal\Model\Report\Settlement::class
57+
);
58+
59+
$result = $model->getSftpCredentials($automaticMode);
60+
61+
$this->assertEquals($expectedResult, $result);
62+
}
63+
3664
/**
3765
* @return array
3866
*/
@@ -46,4 +74,37 @@ public function createConnectionExceptionDataProvider()
4674
[['hostname' => 'example.com', 'username' => 'test', 'password' => 'test']]
4775
];
4876
}
77+
78+
/**
79+
* @return array
80+
*/
81+
public function createAutomaticModeDataProvider()
82+
{
83+
return [
84+
[
85+
true,
86+
[
87+
[
88+
'hostname' => '127.0.0.1',
89+
'path' => '/tmp',
90+
'username' => 'login',
91+
'password' => 'password',
92+
'sandbox' => '0'
93+
]
94+
]
95+
],
96+
[
97+
false,
98+
[
99+
[
100+
'hostname' => '127.0.0.1',
101+
'path' => '/tmp',
102+
'username' => 'login',
103+
'password' => 'password',
104+
'sandbox' => '0'
105+
]
106+
]
107+
],
108+
];
109+
}
49110
}

dev/tests/integration/testsuite/Magento/Setup/Fixtures/FixtureModelTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected function setUp()
5555
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\SimpleProductsAssert::class);
5656
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\ConfigurableProductsAssert::class);
5757
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\BundleProductsAssert::class);
58+
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\ImagesAssert::class);
5859

5960
foreach ($this->objectManager->get(Config::class)->getIndexers() as $indexerId) {
6061
$indexer = $this->indexerRegistry->get($indexerId['indexer_id']);
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Fixtures\FixturesAsserts;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
11+
/**
12+
* Class ImagesAssert
13+
*
14+
* Class performs assertions to check that generated images are valid
15+
* after running setup:performance:generate-fixtures command
16+
*/
17+
class ImagesAssert
18+
{
19+
/**
20+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
21+
*/
22+
private $productRepository;
23+
24+
/**
25+
* @var \Magento\Framework\Api\SearchCriteriaBuilder
26+
*/
27+
private $searchCriteriaBuilder;
28+
29+
/**
30+
* @var \Magento\Catalog\Model\Product\Gallery\ReadHandler
31+
*/
32+
private $readHandler;
33+
34+
/**
35+
* @var \Magento\Framework\Filesystem
36+
*/
37+
private $filesystem;
38+
39+
/**
40+
* @var \Magento\Catalog\Model\Product\Media\Config
41+
*/
42+
private $mediaConfig;
43+
44+
/**
45+
* @var \Magento\Framework\Filesystem\Directory\ReadInterface
46+
*/
47+
private $mediaDirectory;
48+
49+
/**
50+
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
51+
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
52+
* @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $readHandler
53+
* @param \Magento\Framework\Filesystem $filesystem
54+
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
55+
*/
56+
public function __construct(
57+
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
58+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
59+
\Magento\Catalog\Model\Product\Gallery\ReadHandler $readHandler,
60+
\Magento\Framework\Filesystem $filesystem,
61+
\Magento\Catalog\Model\Product\Media\Config $mediaConfig
62+
) {
63+
$this->productRepository = $productRepository;
64+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
65+
$this->readHandler = $readHandler;
66+
$this->filesystem = $filesystem;
67+
$this->mediaConfig = $mediaConfig;
68+
}
69+
70+
/**
71+
* Performs assertions over images
72+
*
73+
* @throws \AssertionError
74+
*/
75+
public function assert()
76+
{
77+
$searchCriteria = $this->searchCriteriaBuilder->create();
78+
$products = $this->productRepository->getList($searchCriteria)->getItems();
79+
80+
foreach ($products as $product) {
81+
$this->assertProductMediaGallery($product);
82+
$this->assertProductMediaAttributes($product);
83+
$this->assertProductImageExistsInFS($product);
84+
}
85+
}
86+
87+
/**
88+
* Performs assertions over media_gallery product attribute
89+
*
90+
* @param \Magento\Catalog\Model\Product $product
91+
* @throws \AssertionError
92+
*/
93+
private function assertProductMediaGallery(\Magento\Catalog\Model\Product $product)
94+
{
95+
$extendedProduct = $this->readHandler->execute($product);
96+
$mediaGalleryImages = $extendedProduct->getMediaGalleryEntries();
97+
98+
if (count($mediaGalleryImages) !== 1) {
99+
throw new \AssertionError('Product supposed to contain one image');
100+
}
101+
102+
$image = reset($mediaGalleryImages);
103+
104+
if ($image->getFile() === null) {
105+
throw new \AssertionError('Image path should not be null');
106+
}
107+
}
108+
109+
/**
110+
* Performs assertions over product media attributes
111+
* e.g. image|small_image|swatch_image|thumbnail
112+
*
113+
* @param \Magento\Catalog\Model\Product $product
114+
* @throws \AssertionError
115+
*/
116+
private function assertProductMediaAttributes(\Magento\Catalog\Model\Product $product)
117+
{
118+
foreach ($product->getMediaAttributeValues() as $attributeCode => $attributeValue) {
119+
if (empty($attributeValue)) {
120+
throw new \AssertionError(
121+
sprintf('Attribute: %s should not be empty', $attributeCode)
122+
);
123+
}
124+
}
125+
}
126+
127+
/**
128+
* Performs assertions over image files in FS
129+
*
130+
* @param \Magento\Catalog\Model\Product $product
131+
* @throws \AssertionError
132+
*/
133+
private function assertProductImageExistsInFS(\Magento\Catalog\Model\Product $product)
134+
{
135+
$mediaDirectory = $this->getMediaDirectory();
136+
$mediaAttributes = $product->getMediaAttributeValues();
137+
138+
if (!$mediaDirectory->isExist($this->mediaConfig->getBaseMediaPath() . $mediaAttributes['image'])) {
139+
throw new \AssertionError('Image file for product supposed to exist');
140+
}
141+
}
142+
143+
/**
144+
* Local cache for $mediaDirectory
145+
*
146+
* @return \Magento\Framework\Filesystem\Directory\ReadInterface
147+
*/
148+
private function getMediaDirectory()
149+
{
150+
if ($this->mediaDirectory === null) {
151+
$this->mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
152+
}
153+
154+
return $this->mediaDirectory;
155+
}
156+
}

dev/tests/integration/testsuite/Magento/Setup/Fixtures/_files/small.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<bundle_products>2</bundle_products>
1616
<bundle_products_options>2</bundle_products_options>
1717
<bundle_products_variation>2</bundle_products_variation>
18+
<product-images>
19+
<images-count>3</images-count>
20+
<images-per-product>1</images-per-product>
21+
</product-images>
1822
<configurable_products>
1923
<config>
2024
<attributeSet>Default</attributeSet>

setup/performance-toolkit/README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ Details http://jmeter.apache.org/usermanual/component_reference.html#View_Result
8585

8686
About other types read on
8787
http://jmeter.apache.org/usermanual/component_reference.html
88+
89+
About fixtures generation
90+
http://devdocs.magento.com/guides/v2.2/config-guide/cli/config-cli-subcommands-perf-data.html

0 commit comments

Comments
 (0)