Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
feat(ProductType): add change inputHint update action
Browse files Browse the repository at this point in the history
Closes #323
  • Loading branch information
Jens Schulze committed Jun 30, 2017
1 parent 20d5b5c commit af666f6
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Request\ProductTypes\Command;

use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Request\AbstractAction;

/**
* @package Commercetools\Core\Request\ProductTypes\Command
* @link https://dev.commercetools.com/http-api-projects-productTypes.html#change-attributedefinition-inputhint
* @method string getAction()
* @method ProductTypeChangeInputHintAction setAction(string $action = null)
* @method string getAttributeName()
* @method ProductTypeChangeInputHintAction setAttributeName(string $attributeName = null)
* @method string getNewValue()
* @method ProductTypeChangeInputHintAction setNewValue(string $newValue = null)
*/
class ProductTypeChangeInputHintAction extends AbstractAction
{
public function fieldDefinitions()
{
return [
'action' => [static::TYPE => 'string'],
'attributeName' => [static::TYPE => 'string'],
'newValue' => [static::TYPE => 'string']
];
}

/**
* @param array $data
* @param Context|callable $context
*/
public function __construct(array $data = [], $context = null)
{
parent::__construct($data, $context);
$this->setAction('changeInputHint');
}

/**
* @param string $attributeName
* @param string $inputHint
* @param Context|callable $context
* @return ProductTypeChangeInputHintAction
*/
public static function ofAttributeNameAndInputHint($attributeName, $inputHint, $context = null)
{
return static::of($context)->setAttributeName($attributeName)->setNewValue($inputHint);
}
}
46 changes: 46 additions & 0 deletions tests/integration/ProductType/ProductTypeUpdateRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeAddLocalizedEnumValueAction;
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeAddPlainEnumValueAction;
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeDescriptionAction;
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeInputHintAction;
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeIsSearchableAction;
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeLabelAction;
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeLocalizedEnumLabelAction;
Expand Down Expand Up @@ -601,4 +602,49 @@ public function testChangeSearchable()
$this->assertSame($searchable, $result->getAttributes()->current()->getIsSearchable());
$this->assertNotSame($productType->getVersion(), $result->getVersion());
}

public function testChangeInputHint()
{
$draft = $this->getDraft('change-inputHint');
$productType = $this->createProductType($draft);

$definition = AttributeDefinition::of()
->setName('testField')
->setLabel(LocalizedString::ofLangAndText('en', 'testField'))
->setIsRequired(false)
->setIsSearchable(false)
->setInputHint('SingleLine')
->setType(StringType::of())
;
$request = ProductTypeUpdateRequest::ofIdAndVersion($productType->getId(), $productType->getVersion())
->addAction(
ProductTypeAddAttributeDefinitionAction::ofAttribute($definition)
)
;
$response = $request->executeWithClient($this->getClient());
$result = $request->mapResponse($response);
$this->productTypeDeleteRequest->setVersion($result->getVersion());

$this->assertInstanceOf(ProductType::class, $result);
$this->assertSame($definition->getName(), $result->getAttributes()->current()->getName());
$this->assertNotSame($productType->getVersion(), $result->getVersion());
$productType = $result;

$inputHint = 'MultiLine';
$request = ProductTypeUpdateRequest::ofIdAndVersion($productType->getId(), $productType->getVersion())
->addAction(
ProductTypeChangeInputHintAction::ofAttributeNameAndInputHint(
'testField',
$inputHint
)
)
;
$response = $request->executeWithClient($this->getClient());
$result = $request->mapResponse($response);
$this->productTypeDeleteRequest->setVersion($result->getVersion());

$this->assertInstanceOf(ProductType::class, $result);
$this->assertSame($inputHint, $result->getAttributes()->current()->getInputHint());
$this->assertNotSame($productType->getVersion(), $result->getVersion());
}
}

0 comments on commit af666f6

Please # to comment.