Skip to content

Commit

Permalink
#22856: Integration tests fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Dec 6, 2019
1 parent 4ac980b commit fbea751
Showing 1 changed file with 73 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Magento\TestFramework\Catalog\Model\Product\Option\DataProvider\Type;

use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
use Magento\TestFramework\Catalog\Model\Product\Option\DataProvider\Type\AbstractBase;
use Magento\Catalog\Model\Product\Option;

/**
* Data provider for options from file group with type "file".
Expand All @@ -20,41 +20,44 @@ class File extends AbstractBase
*/
public function getDataForCreateOptions(): array
{
return array_merge_recursive(
parent::getDataForCreateOptions(),
[
"type_{$this->getType()}_option_file_extension" => [
[
'record_id' => 0,
'sort_order' => 1,
'is_require' => 1,
'sku' => 'test-option-title-1',
'max_characters' => 30,
'title' => 'Test option title 1',
'type' => $this->getType(),
'price' => 10,
'price_type' => 'fixed',
'file_extension' => 'gif',
'image_size_x' => 10,
'image_size_y' => 20,
return $this->injectFileExtension(
array_merge_recursive(
parent::getDataForCreateOptions(),
[
"type_{$this->getType()}_option_file_extension" => [
[
'record_id' => 0,
'sort_order' => 1,
'is_require' => 1,
'sku' => 'test-option-title-1',
'max_characters' => 30,
'title' => 'Test option title 1',
'type' => $this->getType(),
'price' => 10,
'price_type' => 'fixed',
'file_extension' => 'gif',
'image_size_x' => 10,
'image_size_y' => 20,
],
],
],
"type_{$this->getType()}_option_maximum_file_size" => [
[
'record_id' => 0,
'sort_order' => 1,
'is_require' => 1,
'sku' => 'test-option-title-1',
'title' => 'Test option title 1',
'type' => $this->getType(),
'price' => 10,
'price_type' => 'fixed',
'file_extension' => 'gif',
'image_size_x' => 10,
'image_size_y' => 20,
"type_{$this->getType()}_option_maximum_file_size" => [
[
'record_id' => 0,
'sort_order' => 1,
'is_require' => 1,
'sku' => 'test-option-title-1',
'title' => 'Test option title 1',
'type' => $this->getType(),
'price' => 10,
'price_type' => 'fixed',
'file_extension' => 'gif',
'image_size_x' => 10,
'image_size_y' => 20,
],
],
],
]
]
),
'png'
);
}

Expand All @@ -63,21 +66,24 @@ public function getDataForCreateOptions(): array
*/
public function getDataForUpdateOptions(): array
{
return array_merge_recursive(
parent::getDataForUpdateOptions(),
[
"type_{$this->getType()}_option_file_extension" => [
[
'file_extension' => 'jpg',
return $this->injectFileExtension(
array_merge_recursive(
parent::getDataForUpdateOptions(),
[
"type_{$this->getType()}_option_file_extension" => [
[
'file_extension' => 'jpg',
],
],
],
"type_{$this->getType()}_option_maximum_file_size" => [
[
'image_size_x' => 300,
'image_size_y' => 815,
"type_{$this->getType()}_option_maximum_file_size" => [
[
'image_size_x' => 300,
'image_size_y' => 815,
],
],
],
]
]
),
''
);
}

Expand All @@ -88,4 +94,24 @@ protected function getType(): string
{
return ProductCustomOptionInterface::OPTION_TYPE_FILE;
}

/**
* Add 'file_extension' value to each option.
*
* @param array $data
* @param string $extension
* @return array
*/
private function injectFileExtension(array $data, string $extension): array
{
foreach ($data as &$caseData) {
foreach ($caseData as &$option) {
if (!isset($option[Option::KEY_FILE_EXTENSION])) {
$option[Option::KEY_FILE_EXTENSION] = $extension;
}
}
}

return $data;
}
}

0 comments on commit fbea751

Please sign in to comment.