Skip to content

Commit

Permalink
Merge pull request #1096 from magento-okapis/okapis-mainline-2.2-pr
Browse files Browse the repository at this point in the history
- MAGETWO-53431 [GITHUB] SOAP API Encoding Object has no 'label' property #4630
- MAGETWO-58652 [GitHub] REST API multiselect attribute values are sent in an incompatible format and cannot be cleared #6120
- MAGETWO-62567 Make static file versioning number not based on timestamp
- MAGETWO-63741 [FT] Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityTest fails on CI
  • Loading branch information
buskamuza authored May 12, 2017
2 parents 34b0747 + 6551b0b commit 7201bc0
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 33 deletions.
14 changes: 13 additions & 1 deletion app/code/Magento/Deploy/Console/DeployStaticOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class DeployStaticOptions
*/
const LANGUAGES_ARGUMENT = 'languages';

/**
* Static content version
*/
const CONTENT_VERSION = 'content-version';

/**
* Deploy static command options list
*
Expand Down Expand Up @@ -211,7 +216,14 @@ private function getBasicOptions()
null,
InputOption::VALUE_NONE,
'Create symlinks for the files of those locales, which are passed for deployment, '
. 'but have no customizations'
. 'but have no customizations.'
),
new InputOption(
self::CONTENT_VERSION,
null,
InputArgument::OPTIONAL,
'Custom version of static content can be used if running deployment on multiple nodes '
. 'to ensure that static content version is identical and caching works properly.'
),
new InputArgument(
self::LANGUAGES_ARGUMENT,
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Deploy/Service/DeployStaticContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public function deploy(array $options)
]
);

$version = (new \DateTime())->getTimestamp();
$version = !empty($options[Options::CONTENT_VERSION]) && is_string($options[Options::CONTENT_VERSION])
? $options[Options::CONTENT_VERSION]
: (new \DateTime())->getTimestamp();
$this->versionStorage->save($version);

$packages = $deployStrategy->deploy($options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ protected function setUp()
'',
false
);
$this->versionStorage->expects($this->once())->method('save');

$this->service = new DeployStaticContent(
$this->objectManager,
Expand All @@ -107,14 +106,13 @@ protected function setUp()
);
}

public function testDeploy()
/**
* @param array $options
* @param string $expectedContentVersion
* @dataProvider deployDataProvider
*/
public function testDeploy($options, $expectedContentVersion)
{
$options = [
'strategy' => 'compact',
'no-javascript' => false,
'no-html-minify' => false
];

$package = $this->getMock(Package::class, [], [], '', false);
$package->expects($this->exactly(1))->method('isVirtual')->willReturn(false);
$package->expects($this->exactly(3))->method('getArea')->willReturn('area');
Expand All @@ -125,7 +123,11 @@ public function testDeploy()
'package' => $package
];

$this->versionStorage->expects($this->once())->method('save');
if ($expectedContentVersion) {
$this->versionStorage->expects($this->once())->method('save')->with($expectedContentVersion);
} else {
$this->versionStorage->expects($this->once())->method('save');
}

$queue = $this->getMockBuilder(Queue::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -193,4 +195,27 @@ public function testDeploy()
$this->service->deploy($options)
);
}

public function deployDataProvider()
{
return [
[
[
'strategy' => 'compact',
'no-javascript' => false,
'no-html-minify' => false
],
null // content version value should not be asserted in this case
],
[
[
'strategy' => 'compact',
'no-javascript' => false,
'no-html-minify' => false,
'content-version' => '123456',
],
'123456'
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ class SimpleType
*/
public function getType($attribute)
{
if (in_array($attribute->getAttributeCode(), $this->anyTypeAttributes)) {
$arrayFrontendInputs = ['multiselect'];
$frontendInput = $attribute->getFrontendInput();
if (in_array($attribute->getAttributeCode(), $this->anyTypeAttributes)
|| in_array($frontendInput, $arrayFrontendInputs)
) {
return TypeProcessor::NORMALIZED_ANY_TYPE;
}
$frontendInput = $attribute->getFrontendInput();

$backendType = $attribute->getBackendType();
$backendTypeMap = [
'static' => TypeProcessor::NORMALIZED_ANY_TYPE,
Expand All @@ -41,11 +45,6 @@ public function getType($attribute)
'datetime' => TypeProcessor::NORMALIZED_STRING_TYPE,
'decimal' => TypeProcessor::NORMALIZED_DOUBLE_TYPE,
];
$arrayFrontendInputs = ['multiselect'];
$type = $backendTypeMap[$backendType];
if (in_array($frontendInput, $arrayFrontendInputs)) {
$type .= '[]';
}
return $type;
return $backendTypeMap[$backendType];
}
}
6 changes: 5 additions & 1 deletion app/code/Magento/Webapi/Controller/Soap/Request/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ protected function _prepareResponseData($data, $serviceClassName, $serviceMethod
} elseif (is_array($data)) {
$dataType = substr($dataType, 0, -2);
foreach ($data as $key => $value) {
if ($value instanceof ExtensibleDataInterface || $value instanceof MetadataObjectInterface) {
if ($value instanceof $dataType
// the following two options are supported for backward compatibility
|| $value instanceof ExtensibleDataInterface
|| $value instanceof MetadataObjectInterface
) {
$result[] = $this->_dataObjectConverter
->convertKeysToCamelCase($this->_dataObjectProcessor->buildOutputDataArray($value, $dataType));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function testCall()
$this->_dataObjectConverter->expects($this->once())
->method('convertStdObjectToArray')
->will($this->returnValue(['field' => 1]));
$this->_methodsMapProcessorMock->method('getMethodReturnType')->willReturn('string');
$operationName = 'soapOperation';
$className = \Magento\Framework\DataObject::class;
$methodName = 'testMethod';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract

public function testGetItems()
{
$this->_markTestAsRestOnly('Fix inconsistencies in WSDL and Data interfaces');
$testAttributeCode = 'quantity_and_stock_status';
$expectedOptions = [
[
Expand Down Expand Up @@ -54,7 +53,6 @@ public function testGetItems()
*/
public function testAdd($optionData)
{
$this->_markTestAsRestOnly('Fix inconsistencies in WSDL and Data interfaces');
$testAttributeCode = 'select_attribute';
$serviceInfo = [
'rest' => [
Expand Down Expand Up @@ -100,6 +98,7 @@ public function addDataProvider()
AttributeOptionLabelInterface::STORE_ID => 1,
],
],
AttributeOptionInterface::VALUE => ''
];

return [
Expand All @@ -121,7 +120,6 @@ public function addDataProvider()
*/
public function testDelete()
{
$this->_markTestAsRestOnly('Fix inconsistencies in WSDL and Data interfaces');
$attributeCode = 'select_attribute';
//get option Id
$optionList = $this->getAttributeOptions($attributeCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1296,4 +1296,86 @@ public function testUpdateStatus()
// Price should be updated
$this->assertEquals(200, $response['price']);
}

/**
* Test saving product with custom attribute of multiselect type
*
* 1. Create multi-select attribute
* 2. Create product and set 2 options out of 3 to multi-select attribute
* 3. Verify that 2 options are selected
* 4. Unselect all options
* 5. Verify that non options are selected
*
* @magentoApiDataFixture Magento/Catalog/_files/multiselect_attribute.php
*/
public function testUpdateMultiselectAttributes()
{
$multiselectAttributeCode = 'multiselect_attribute';
$multiselectOptions = $this->getAttributeOptions($multiselectAttributeCode);
$option1 = $multiselectOptions[1]['value'];
$option2 = $multiselectOptions[2]['value'];

$productData = $this->getSimpleProductData();
$productData['custom_attributes'] = [
['attribute_code' => $multiselectAttributeCode, 'value' => "{$option1},{$option2}"]
];
$this->saveProduct($productData, 'all');

$this->assertMultiselectValue(
$productData[ProductInterface::SKU],
$multiselectAttributeCode,
"{$option1},{$option2}"
);

$productData['custom_attributes'] = [
['attribute_code' => $multiselectAttributeCode, 'value' => ""]
];
$this->saveProduct($productData, 'all');
$this->assertMultiselectValue(
$productData[ProductInterface::SKU],
$multiselectAttributeCode,
""
);
}

/**
* @param string $attributeCode
* @return array|bool|float|int|string
*/
private function getAttributeOptions($attributeCode)
{
$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/products/attributes/' . $attributeCode . '/options',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => 'catalogProductAttributeOptionManagementV1',
'serviceVersion' => 'V1',
'operation' => 'catalogProductAttributeOptionManagementV1getItems',
],
];

return $this->_webApiCall($serviceInfo, ['attributeCode' => $attributeCode]);
}

/**
* @param string $productSku
* @param string $multiselectAttributeCode
* @param string $expectedMultiselectValue
*/
private function assertMultiselectValue($productSku, $multiselectAttributeCode, $expectedMultiselectValue)
{
$response = $this->getProduct($productSku, 'all');
$customAttributes = $response['custom_attributes'];
$this->assertNotEmpty($customAttributes);
$multiselectValue = null;
foreach ($customAttributes as $customAttribute) {
if ($customAttribute['attribute_code'] == $multiselectAttributeCode) {
$multiselectValue = $customAttribute['value'];
break;
}
}
$this->assertEquals($expectedMultiselectValue, $multiselectValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class BlockGallery extends Section
*/
private $imageLoader = '.image.image-placeholder .file-row';

/**
* Selector for first uploaded image.
*
* @var string
*/
private $baseImage = '.image.item.base-image';

/**
* Selector for image upload input.
*
Expand All @@ -43,6 +50,7 @@ public function setFieldsData(array $data, SimpleElement $element = null)
$uploadElement = $element->find($this->imageUploadInput, Locator::SELECTOR_CSS, 'upload');
$uploadElement->setValue($imageData['file']);
$this->waitForElementNotVisible($this->imageLoader);
$this->waitForElementVisible($this->baseImage);
}
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@
<data name="product/data/sku" xsi:type="string">simple_sku_%isolation%</data>
<data name="product/data/price/value" xsi:type="string">10</data>
<data name="product/data/weight" xsi:type="string">50</data>
<data name="tag" xsi:type="string">severity:S1</data>
<data name="product/data/quantity_and_stock_status/qty" xsi:type="string">100</data>
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
<constraint name="Magento\Catalog\Test\Constraint\AssertProductHasImageInGrid" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ protected function tearDown()
*/
public function testDeploy()
{
//$this->markTestSkipped('Test blocked since it must be run in isolated Filesystem');
$this->deployService->deploy($this->options);

$this->assertFileExists($this->staticDir->getAbsolutePath('frontend/Magento/zoom1/default/css/root.css'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ class DeployStaticContentCommandTest extends \PHPUnit_Framework_TestCase
*/
private $deployService;

/**
* @var DeployStaticOptions|Mock
*/
private $options;

/**
* Object manager to create various objects
*
Expand All @@ -75,7 +70,6 @@ protected function setUp()
$this->inputValidator = $this->getMock(InputValidator::class, [], [], '', false);
$this->consoleLoggerFactory = $this->getMock(ConsoleLoggerFactory::class, [], [], '', false);
$this->logger = $this->getMock(ConsoleLogger::class, [], [], '', false);
$this->options = $this->getMock(DeployStaticOptions::class, [], [], '', false);
$this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class);
$this->appState = $this->getMock(State::class, [], [], '', false);
$this->deployService = $this->getMock(DeployStaticContent::class, [], [], '', false);
Expand All @@ -99,9 +93,11 @@ protected function setUp()
}

/**
* @param array $input
* @see DeployStaticContentCommand::execute()
* @dataProvider executeDataProvider
*/
public function testExecute()
public function testExecute($input)
{
$this->appState->expects($this->once())
->method('getMode')
Expand All @@ -118,7 +114,19 @@ public function testExecute()
$this->deployService->expects($this->once())->method('deploy');

$tester = new CommandTester($this->command);
$tester->execute([]);
$tester->execute($input);
}

public function executeDataProvider()
{
return [
'No options' => [
[]
],
'With static content version option' => [
['--content-version' => '123456']
]
];
}

/**
Expand Down

0 comments on commit 7201bc0

Please sign in to comment.