|
21 | 21 | use Commercetools\Core\Request\Types\Command\TypeAddEnumValueAction; |
22 | 22 | use Commercetools\Core\Request\Types\Command\TypeAddFieldDefinitionAction; |
23 | 23 | use Commercetools\Core\Request\Types\Command\TypeAddLocalizedEnumValueAction; |
| 24 | +use Commercetools\Core\Request\Types\Command\TypeChangeEnumValueLabelAction; |
| 25 | +use Commercetools\Core\Request\Types\Command\TypeChangeInputHintAction; |
24 | 26 | use Commercetools\Core\Request\Types\Command\TypeChangeKeyAction; |
25 | 27 | use Commercetools\Core\Request\Types\Command\TypeChangeLabelAction; |
| 28 | +use Commercetools\Core\Request\Types\Command\TypeChangeLocalizedEnumValueLabelAction; |
26 | 29 | use Commercetools\Core\Request\Types\Command\TypeChangeNameAction; |
27 | 30 | use Commercetools\Core\Request\Types\Command\TypeRemoveFieldDefinitionAction; |
28 | 31 | use Commercetools\Core\Request\Types\Command\TypeSetDescriptionAction; |
@@ -51,6 +54,7 @@ protected function getDraft($name) |
51 | 54 | ->setName('testField') |
52 | 55 | ->setLabel(LocalizedString::ofLangAndText('en', 'testField')) |
53 | 56 | ->setRequired(false) |
| 57 | + ->setInputHint('SingleLine') |
54 | 58 | ->setType(StringType::of()) |
55 | 59 | ) |
56 | 60 | ); |
@@ -302,4 +306,114 @@ public function testAddLocalizedEnumValue() |
302 | 306 | $fieldType = $result->getFieldDefinitions()->getByName('newLEnumField')->getType(); |
303 | 307 | $this->assertSame($enum->getKey(), $fieldType->getValues()->current()->getKey()); |
304 | 308 | } |
| 309 | + |
| 310 | + public function testChangeEnumValueLabel() |
| 311 | + { |
| 312 | + $draft = $this->getDraft('change-enum-value-label'); |
| 313 | + $type = $this->createType($draft); |
| 314 | + |
| 315 | + $fieldDefinition = FieldDefinition::of() |
| 316 | + ->setName('newEnumField') |
| 317 | + ->setLabel(LocalizedString::ofLangAndText('en', 'newEnumField')) |
| 318 | + ->setRequired(false) |
| 319 | + ->setType( |
| 320 | + EnumType::of() |
| 321 | + ->setValues(EnumCollection::of()->add(Enum::of()->setKey('test')->setLabel('test'))) |
| 322 | + ) |
| 323 | + ; |
| 324 | + $request = TypeUpdateRequest::ofIdAndVersion($type->getId(), $type->getVersion()) |
| 325 | + ->addAction( |
| 326 | + TypeAddFieldDefinitionAction::ofFieldDefinition($fieldDefinition) |
| 327 | + ) |
| 328 | + ; |
| 329 | + $response = $request->executeWithClient($this->getClient()); |
| 330 | + $result = $request->mapResponse($response); |
| 331 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 332 | + $type = $result; |
| 333 | + |
| 334 | + $enum = Enum::of()->setKey('test')->setLabel('new-label'); |
| 335 | + $request = TypeUpdateRequest::ofIdAndVersion($type->getId(), $type->getVersion()) |
| 336 | + ->addAction( |
| 337 | + TypeChangeEnumValueLabelAction::ofNameAndEnum('newEnumField', $enum) |
| 338 | + ) |
| 339 | + ; |
| 340 | + $response = $request->executeWithClient($this->getClient()); |
| 341 | + $result = $request->mapResponse($response); |
| 342 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 343 | + |
| 344 | + $this->assertInstanceOf(Type::class, $result); |
| 345 | + /** |
| 346 | + * @var EnumType $fieldType |
| 347 | + */ |
| 348 | + $fieldType = $result->getFieldDefinitions()->getByName('newEnumField')->getType(); |
| 349 | + $this->assertSame($enum->getLabel(), $fieldType->getValues()->current()->getLabel()); |
| 350 | + } |
| 351 | + |
| 352 | + public function testChangeLocalizedEnumValueLabel() |
| 353 | + { |
| 354 | + $draft = $this->getDraft('change-localized-enum-value-label'); |
| 355 | + $type = $this->createType($draft); |
| 356 | + |
| 357 | + $fieldDefinition = FieldDefinition::of() |
| 358 | + ->setName('newEnumField') |
| 359 | + ->setLabel(LocalizedString::ofLangAndText('en', 'newEnumField')) |
| 360 | + ->setRequired(false) |
| 361 | + ->setType( |
| 362 | + LocalizedEnumType::of() |
| 363 | + ->setValues( |
| 364 | + LocalizedEnumCollection::of()->add( |
| 365 | + LocalizedEnum::of()->setKey('test') |
| 366 | + ->setLabel(LocalizedString::ofLangAndText('en', 'test')) |
| 367 | + ) |
| 368 | + ) |
| 369 | + ) |
| 370 | + ; |
| 371 | + $request = TypeUpdateRequest::ofIdAndVersion($type->getId(), $type->getVersion()) |
| 372 | + ->addAction( |
| 373 | + TypeAddFieldDefinitionAction::ofFieldDefinition($fieldDefinition) |
| 374 | + ) |
| 375 | + ; |
| 376 | + $response = $request->executeWithClient($this->getClient()); |
| 377 | + $result = $request->mapResponse($response); |
| 378 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 379 | + $type = $result; |
| 380 | + |
| 381 | + $enum = LocalizedEnum::of()->setKey('test') |
| 382 | + ->setLabel(LocalizedString::ofLangAndText('en', 'new-label')); |
| 383 | + $request = TypeUpdateRequest::ofIdAndVersion($type->getId(), $type->getVersion()) |
| 384 | + ->addAction( |
| 385 | + TypeChangeLocalizedEnumValueLabelAction::ofNameAndEnum('newEnumField', $enum) |
| 386 | + ) |
| 387 | + ; |
| 388 | + $response = $request->executeWithClient($this->getClient()); |
| 389 | + $result = $request->mapResponse($response); |
| 390 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 391 | + |
| 392 | + $this->assertInstanceOf(Type::class, $result); |
| 393 | + /** |
| 394 | + * @var LocalizedEnumType $fieldType |
| 395 | + */ |
| 396 | + $fieldType = $result->getFieldDefinitions()->getByName('newEnumField')->getType(); |
| 397 | + $this->assertSame($enum->getLabel()->en, $fieldType->getValues()->current()->getLabel()->en); |
| 398 | + } |
| 399 | + |
| 400 | + public function testChangeInputHint() |
| 401 | + { |
| 402 | + $draft = $this->getDraft('change-input-hint'); |
| 403 | + $type = $this->createType($draft); |
| 404 | + |
| 405 | + $inputHint = 'MultiLine'; |
| 406 | + $request = TypeUpdateRequest::ofIdAndVersion($type->getId(), $type->getVersion()) |
| 407 | + ->addAction( |
| 408 | + TypeChangeInputHintAction::ofNameAndInputHint('testField', $inputHint) |
| 409 | + ) |
| 410 | + ; |
| 411 | + $response = $request->executeWithClient($this->getClient()); |
| 412 | + $result = $request->mapResponse($response); |
| 413 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 414 | + |
| 415 | + $this->assertInstanceOf(Type::class, $result); |
| 416 | + $field = $result->getFieldDefinitions()->getByName('testField'); |
| 417 | + $this->assertSame($inputHint, $field->getInputHint()); |
| 418 | + } |
305 | 419 | } |
0 commit comments