|
40 | 40 | use Commercetools\Core\Request\ProductTypes\Command\ProductTypeAddAttributeDefinitionAction; |
41 | 41 | use Commercetools\Core\Request\ProductTypes\Command\ProductTypeAddLocalizedEnumValueAction; |
42 | 42 | use Commercetools\Core\Request\ProductTypes\Command\ProductTypeAddPlainEnumValueAction; |
| 43 | +use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeAttributeConstraintAction; |
43 | 44 | use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeDescriptionAction; |
44 | 45 | use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeInputHintAction; |
45 | 46 | use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeIsSearchableAction; |
@@ -647,4 +648,50 @@ public function testChangeInputHint() |
647 | 648 | $this->assertSame($inputHint, $result->getAttributes()->current()->getInputHint()); |
648 | 649 | $this->assertNotSame($productType->getVersion(), $result->getVersion()); |
649 | 650 | } |
| 651 | + |
| 652 | + public function testChangeConstraint() |
| 653 | + { |
| 654 | + $draft = $this->getDraft('change-constraint'); |
| 655 | + $productType = $this->createProductType($draft); |
| 656 | + |
| 657 | + $definition = AttributeDefinition::of() |
| 658 | + ->setName('testConstraintField') |
| 659 | + ->setLabel(LocalizedString::ofLangAndText('en', 'testConstraintField')) |
| 660 | + ->setIsRequired(false) |
| 661 | + ->setIsSearchable(false) |
| 662 | + ->setAttributeConstraint('SameForAll') |
| 663 | + ->setType(StringType::of()) |
| 664 | + ; |
| 665 | + $request = ProductTypeUpdateRequest::ofIdAndVersion($productType->getId(), $productType->getVersion()) |
| 666 | + ->addAction( |
| 667 | + ProductTypeAddAttributeDefinitionAction::ofAttribute($definition) |
| 668 | + ) |
| 669 | + ; |
| 670 | + $response = $request->executeWithClient($this->getClient()); |
| 671 | + $result = $request->mapResponse($response); |
| 672 | + $this->productTypeDeleteRequest->setVersion($result->getVersion()); |
| 673 | + |
| 674 | + $this->assertInstanceOf(ProductType::class, $result); |
| 675 | + $this->assertSame($definition->getName(), $result->getAttributes()->current()->getName()); |
| 676 | + $this->assertSame('SameForAll', $result->getAttributes()->current()->getAttributeConstraint()); |
| 677 | + $this->assertNotSame($productType->getVersion(), $result->getVersion()); |
| 678 | + $productType = $result; |
| 679 | + |
| 680 | + $constraint = 'None'; |
| 681 | + $request = ProductTypeUpdateRequest::ofIdAndVersion($productType->getId(), $productType->getVersion()) |
| 682 | + ->addAction( |
| 683 | + ProductTypeChangeAttributeConstraintAction::ofAttributeNameAndAttributeConstraint( |
| 684 | + 'testConstraintField', |
| 685 | + $constraint |
| 686 | + ) |
| 687 | + ) |
| 688 | + ; |
| 689 | + $response = $request->executeWithClient($this->getClient()); |
| 690 | + $result = $request->mapResponse($response); |
| 691 | + $this->productTypeDeleteRequest->setVersion($result->getVersion()); |
| 692 | + |
| 693 | + $this->assertInstanceOf(ProductType::class, $result); |
| 694 | + $this->assertSame($constraint, $result->getAttributes()->current()->getAttributeConstraint()); |
| 695 | + $this->assertNotSame($productType->getVersion(), $result->getVersion()); |
| 696 | + } |
650 | 697 | } |
0 commit comments