@@ 1689-1720 (lines=32) @@ | ||
1686 | * @see \eZ\Publish\API\Repository\ContentTypeService::addFieldDefinition() |
|
1687 | * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testAddFieldDefinition |
|
1688 | */ |
|
1689 | public function testAddFieldDefinitionThrowsBadStateExceptionNonRepeatableField() |
|
1690 | { |
|
1691 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\BadStateException::class); |
|
1692 | $this->expectExceptionMessage('The Content Type already contains a Field definition of the singular Field Type \'ezuser\''); |
|
1693 | ||
1694 | $repository = $this->getRepository(); |
|
1695 | $contentTypeService = $repository->getContentTypeService(); |
|
1696 | ||
1697 | /* BEGIN: Use Case */ |
|
1698 | $userContentType = $contentTypeService->loadContentTypeByIdentifier('user'); |
|
1699 | $userContentTypeDraft = $contentTypeService->createContentTypeDraft($userContentType); |
|
1700 | ||
1701 | $fieldDefCreate = $contentTypeService->newFieldDefinitionCreateStruct('second_user_account', 'ezuser'); |
|
1702 | $fieldDefCreate->names = [ |
|
1703 | 'eng-GB' => 'Second user account', |
|
1704 | ]; |
|
1705 | $fieldDefCreate->descriptions = [ |
|
1706 | 'eng-GB' => 'Second user account for the ContentType', |
|
1707 | ]; |
|
1708 | $fieldDefCreate->fieldGroup = 'users'; |
|
1709 | $fieldDefCreate->position = 1; |
|
1710 | $fieldDefCreate->isTranslatable = false; |
|
1711 | $fieldDefCreate->isRequired = true; |
|
1712 | $fieldDefCreate->isInfoCollector = false; |
|
1713 | $fieldDefCreate->validatorConfiguration = []; |
|
1714 | $fieldDefCreate->fieldSettings = []; |
|
1715 | $fieldDefCreate->isSearchable = false; |
|
1716 | ||
1717 | // Throws an exception because $userContentTypeDraft already contains non-repeatable field type definition 'ezuser' |
|
1718 | $contentTypeService->addFieldDefinition($userContentTypeDraft, $fieldDefCreate); |
|
1719 | /* END: Use Case */ |
|
1720 | } |
|
1721 | ||
1722 | /** |
|
1723 | * Test for the ContentTypeService::createContentType() method. |
|
@@ 1784-1815 (lines=32) @@ | ||
1781 | * @see \eZ\Publish\API\Repository\ContentTypeService::addFieldDefinition() |
|
1782 | * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testAddFieldDefinition |
|
1783 | */ |
|
1784 | public function testAddFieldDefinitionThrowsBadStateExceptionContentInstances() |
|
1785 | { |
|
1786 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\BadStateException::class); |
|
1787 | $this->expectExceptionMessage('A Field definition of the \'ezuser\' Field Type cannot be added because the Content Type already has Content items'); |
|
1788 | ||
1789 | $repository = $this->getRepository(); |
|
1790 | $contentTypeService = $repository->getContentTypeService(); |
|
1791 | ||
1792 | /* BEGIN: Use Case */ |
|
1793 | $folderContentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
1794 | $folderContentTypeDraft = $contentTypeService->createContentTypeDraft($folderContentType); |
|
1795 | ||
1796 | $fieldDefCreate = $contentTypeService->newFieldDefinitionCreateStruct('user_account', 'ezuser'); |
|
1797 | $fieldDefCreate->names = [ |
|
1798 | 'eng-GB' => 'User account', |
|
1799 | ]; |
|
1800 | $fieldDefCreate->descriptions = [ |
|
1801 | 'eng-GB' => 'User account field definition for ContentType that has Content instances', |
|
1802 | ]; |
|
1803 | $fieldDefCreate->fieldGroup = 'users'; |
|
1804 | $fieldDefCreate->position = 1; |
|
1805 | $fieldDefCreate->isTranslatable = false; |
|
1806 | $fieldDefCreate->isRequired = true; |
|
1807 | $fieldDefCreate->isInfoCollector = false; |
|
1808 | $fieldDefCreate->validatorConfiguration = []; |
|
1809 | $fieldDefCreate->fieldSettings = []; |
|
1810 | $fieldDefCreate->isSearchable = false; |
|
1811 | ||
1812 | // Throws an exception because 'ezuser' type field definition can't be added to ContentType that already has Content instances |
|
1813 | $contentTypeService->addFieldDefinition($folderContentTypeDraft, $fieldDefCreate); |
|
1814 | /* END: Use Case */ |
|
1815 | } |
|
1816 | ||
1817 | /** |
|
1818 | * Test for the removeFieldDefinition() method. |