diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Base.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Base.php deleted file mode 100644 index ddf13317b7d..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Base.php +++ /dev/null @@ -1,211 +0,0 @@ -repository = static::getRepository(); - $this->repository->setCurrentUser($this->getStubbedUser(14)); - } - - /** - * Returns User stub with $id as User/Content id. - * - * @param int $id - * - * @return \eZ\Publish\API\Repository\Values\User\User - */ - protected function getStubbedUser($id) - { - return new User( - array( - 'content' => new Content( - array( - 'versionInfo' => new VersionInfo( - array( - 'contentInfo' => new ContentInfo(array('id' => $id)), - ) - ), - 'internalFields' => array(), - ) - ), - ) - ); - } - - /** - * @return \eZ\Publish\Core\Repository\Values\User\User - */ - protected function createUserVersion1() - { - $repository = $this->repository; - - /* BEGIN: Inline */ - // ID of the "Editors" user group in an eZ Publish demo installation - $editorsGroupId = 13; - - $userService = $repository->getUserService(); - - // Instantiate a create struct with mandatory properties - $userCreate = $userService->newUserCreateStruct( - 'user', - 'user@example.com', - 'secret', - 'eng-US' - ); - $userCreate->enabled = true; - - // Set some fields required by the user ContentType - $userCreate->setField('first_name', 'Example'); - $userCreate->setField('last_name', 'User'); - - // Load parent group for the user - $group = $userService->loadUserGroup($editorsGroupId); - - // Create a new user instance. - $user = $userService->createUser($userCreate, array($group)); - /* END: Inline */ - - return $user; - } - - /** - * Tear down test (properties). - */ - protected function tearDown() - { - unset($this->repository); - parent::tearDown(); - } - - /** - * Generate \eZ\Publish\API\Repository\Repository. - * - * Makes it possible to inject different Io / Persistence handlers - * - * @return \eZ\Publish\API\Repository\Repository - */ - abstract protected function getRepository(); - - /** - * Asserts that properties given in $expectedValues are correctly set in - * $actualObject. - * - * @param mixed[] $expectedValues - * @param \eZ\Publish\API\Repository\Values\ValueObject $actualObject - * @param array $skipProperties - */ - protected function assertPropertiesCorrect(array $expectedValues, ValueObject $actualObject, array $skipProperties = array()) - { - foreach ($expectedValues as $propertyName => $propertyValue) { - if (in_array($propertyName, $skipProperties)) { - continue; - } - - $this->assertProperty($propertyName, $propertyValue, $actualObject->$propertyName); - } - } - - protected function assertSameClassPropertiesCorrect( - array $propertiesNames, - ValueObject $expectedValues, - ValueObject $actualObject, - array $skipProperties = array(), - $equal = true - ) { - foreach ($propertiesNames as $propertyName) { - if (in_array($propertyName, $skipProperties)) { - continue; - } - - $this->assertProperty($propertyName, $expectedValues->$propertyName, $actualObject->$propertyName, $equal); - } - } - - /** - * Asserts all properties from $expectedValues are correctly set in - * $actualObject. - * - * @param \eZ\Publish\API\Repository\Values\ValueObject $expectedValues - * @param \eZ\Publish\API\Repository\Values\ValueObject $actualObject - * @param array $skipProperties - */ - protected function assertStructPropertiesCorrect(ValueObject $expectedValues, ValueObject $actualObject, array $skipProperties = array()) - { - foreach ($expectedValues as $propertyName => $propertyValue) { - if (in_array($propertyName, $skipProperties)) { - continue; - } - - $this->assertProperty($propertyName, $propertyValue, $actualObject->$propertyName); - } - } - - private function assertProperty($propertyName, $expectedValue, $actualValue, $equal = true) - { - if ($expectedValue instanceof \ArrayObject) { - $expectedValue = $expectedValue->getArrayCopy(); - } - if ($actualValue instanceof \ArrayObject) { - $actualValue = $actualValue->getArrayCopy(); - } - - // For PHP 7.1 make sure we just compare the timestamp and not the offset value - if ($expectedValue instanceof \DateTimeInterface) { - $expectedValue = $expectedValue->getTimestamp(); - } - if ($actualValue instanceof \DateTimeInterface) { - $actualValue = $actualValue->getTimestamp(); - } - - if ($equal) { - $this->assertEquals( - $expectedValue, - $actualValue, - sprintf('Object property "%s" incorrect.', $propertyName) - ); - } else { - $this->assertNotEquals( - $expectedValue, - $actualValue, - sprintf('Object property "%s" incorrect.', $propertyName) - ); - } - } - - protected function getDateTime($timestamp) - { - $dateTime = new \DateTime(); - $dateTime->setTimestamp($timestamp); - - return $dateTime; - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/ContentBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/ContentBase.php deleted file mode 100644 index b02510a651e..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/ContentBase.php +++ /dev/null @@ -1,2673 +0,0 @@ - 4, - 'name' => 'Users', - 'sectionId' => 2, - 'currentVersionNo' => 1, - 'published' => true, - 'ownerId' => 14, - 'modificationDate' => $this->getDateTime(1033917596), - 'publishedDate' => $this->getDateTime(1033917596), - 'alwaysAvailable' => true, - 'remoteId' => 'f5c88a2209584891056f987fd965b0ba', - 'mainLanguageCode' => 'eng-US', - 'mainLocationId' => 5, - ); - } - - /** - * @param bool $draft - * - * @return array - */ - protected function getVersionInfoExpectedValues($draft = false) - { - // Legacy fixture content 4 current version (1) values - $values = array( - //"id" => 4, - 'versionNo' => 1, - 'modificationDate' => $this->getDateTime(0), - 'creatorId' => 14, - 'creationDate' => $this->getDateTime(0), - 'status' => VersionInfo::STATUS_PUBLISHED, - 'initialLanguageCode' => 'eng-US', - 'languageCodes' => array('eng-US'), - // Implementation properties - 'names' => array('eng-US' => 'Users'), - ); - - if ($draft) { - //$values["id"] = 675; - $values['creatorId'] = $this->repository->getCurrentUserReference()->getUserId(); - $values['versionNo'] = 2; - $values['status'] = VersionInfo::STATUS_DRAFT; - unset($values['modificationDate']); - unset($values['creationDate']); - } - - return $values; - } - - /** - * @param array $languages - * - * @return mixed - */ - protected function getFieldValuesExpectedValues(array $languages = null) - { - // Legacy fixture content ID=4 field values - $fieldValues = array( - 'eng-US' => array( - 'name' => array('eng-US' => 'Users'), - 'description' => array('eng-US' => 'Main group'), - ), - ); - - $returnArray = array(); - foreach ($fieldValues as $languageCode => $languageFieldValues) { - if (!empty($languages) && !in_array($languageCode, $languages)) { - continue; - } - $returnArray = array_merge_recursive($returnArray, $languageFieldValues); - } - - return $returnArray; - } - - protected function getExpectedContentType() - { - } - - /** - * Test for the loadContentInfo() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo - * - * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo - */ - public function testLoadContentInfo() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', - $contentInfo - ); - - return $contentInfo; - } - - /** - * Test for the loadContentInfo() method. - * - * @depends testLoadContentInfo - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo - * - * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo - */ - public function testLoadContentInfoValues($contentInfo) - { - $this->assertPropertiesCorrect( - $this->getContentInfoExpectedValues(), - $contentInfo - ); - } - - /** - * Test for the loadContentInfo() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadContentInfoThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Throws an exception because given contentId does not exist - $contentInfo = $contentService->loadContentInfo(APIBaseTest::DB_INT_MAX); - /* END: Use Case */ - } - - /** - * Test for the loadContentInfo() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadContentInfoThrowsUnauthorizedException() - { - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->loadContentInfo(4); - } - - /** - * Test for the loadContentInfoByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId - * - * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo - */ - public function testLoadContentInfoByRemoteId() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfoByRemoteId('f5c88a2209584891056f987fd965b0ba'); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', - $contentInfo - ); - - return $contentInfo; - } - - /** - * Test for the loadContentInfoByRemoteId() method. - * - * @depends testLoadContentInfoByRemoteId - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId - * - * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo - */ - public function testLoadContentInfoByRemoteIdValues($contentInfo) - { - $this->assertPropertiesCorrect( - $this->getContentInfoExpectedValues(), - $contentInfo - ); - } - - /** - * Test for the loadContentInfoByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadContentInfoByRemoteIdThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Throws an exception because remoteId does not exist - $contentInfo = $contentService->loadContentInfoByRemoteId('this-remote-id-does-not-exist'); - /* END: Use Case */ - } - - /** - * Test for the loadContentInfoByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadContentInfoByRemoteIdThrowsUnauthorizedException() - { - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->loadContentInfoByRemoteId('f5c88a2209584891056f987fd965b0ba'); - } - - /** - * Test for the loadVersionInfoById() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById - * - * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo - */ - public function testLoadVersionInfoById() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById(4); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', - $versionInfo - ); - - return $versionInfo; - } - - /** - * Test for the loadVersionInfoById() method. - * - * @depends testLoadVersionInfoById - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById - * - * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo - */ - public function testLoadVersionInfoByIdValues($versionInfo) - { - $this->assertPropertiesCorrect( - $this->getVersionInfoExpectedValues(), - $versionInfo - ); - } - - /** - * Test for the loadVersionInfoById() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById - * - * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo - */ - public function testLoadVersionInfoByIdWithSecondParameter() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById(4, 1); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', - $versionInfo - ); - - return $versionInfo; - } - - /** - * Test for the loadVersionInfoById() method. - * - * @depends testLoadVersionInfoByIdWithSecondParameter - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById - * - * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo - */ - public function testLoadVersionInfoByIdWithSecondParameterValues($versionInfo) - { - $this->assertPropertiesCorrect( - $this->getVersionInfoExpectedValues(), - $versionInfo - ); - } - - /** - * Test for the loadVersionInfoById() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadVersionInfoByIdThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Throws an exception because version with given number does not exists - $versionInfo = $contentService->loadVersionInfoById(4, APIBaseTest::DB_INT_MAX); - /* END: Use Case */ - } - - /** - * Test for the loadVersionInfoById() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadVersionInfoByIdThrowsUnauthorizedException() - { - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->loadVersionInfoById(4); - } - - /** - * Data provider for testLoadContent(). - * - * @return array - */ - public function testLoadContentArgumentsProvider() - { - return array( - array(4, null, null), - array(4, array('eng-US'), null), - array(4, array('eng-US', 'fre-FR'), null), - array(4, null, 1), - array(4, array('eng-US', 'fre-FR', 'nor-NO', 'eng-DE'), 1), - array(4, array('eng-US'), 1), - ); - } - - /** - * Test for the loadContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContent - * @dataProvider testLoadContentArgumentsProvider - * - * @param int $contentId - * @param array $languages - * @param int $versionNo - * - * @return \eZ\Publish\API\Repository\Values\Content\Content - */ - public function testLoadContent($contentId, array $languages = null, $versionNo = null) - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $content = $contentService->loadContent($contentId, $languages, $versionNo); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', - $content - ); - - $this->assertContentValues($content, $languages); - } - - /** - * @param \eZ\Publish\API\Repository\Values\Content\Content $content - * @param array $languages - * @param bool $draft - */ - protected function assertContentValues(APIContent $content, array $languages = null, $draft = false) - { - $versionInfoValues = $this->getVersionInfoExpectedValues($draft); - $contentInfoValues = $this->getContentInfoExpectedValues(); - $fieldValuesValues = $this->getFieldValuesExpectedValues($languages); - - $this->assertPropertiesCorrect( - $versionInfoValues, - $content->getVersionInfo() - ); - - $this->assertPropertiesCorrect( - $contentInfoValues, - $content->contentInfo - ); - - $this->assertEquals( - $fieldValuesValues, - $content->fields - ); - - // @todo assert relations - - $this->assertEquals($content->id, $content->contentInfo->id); - } - - /** - * Test for the loadContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadContentThrowsUnauthorizedException() - { - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->loadContent(4); - } - - /** - * Test for the loadContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadContentWithVersionThrowsUnauthorizedException() - { - list($draft) = $this->createTestContent(); - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->loadContent( - $draft->id, - null, - $draft->versionInfo->versionNo - ); - } - - /** - * Test for the loadContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadContentThrowsNotFoundExceptionContentNotFound() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Throws an exception because content with id APIBaseTest::DB_INT_MAX does not exist - $content = $contentService->loadContent(APIBaseTest::DB_INT_MAX); - /* END: Use Case */ - } - - /** - * Test for the loadContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadContentThrowsNotFoundExceptionVersionNotFound() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Throws an exception because version number APIBaseTest::DB_INT_MAX for content with id 4 does not exist - $content = $contentService->loadContent(4, null, APIBaseTest::DB_INT_MAX); - /* END: Use Case */ - } - - /** - * Test for the loadContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadContentThrowsNotFoundExceptionLanguageNotFound() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Throws an exception because content does not exists in "fre-FR" language - $content = $contentService->loadContent(4, array('fre-FR'), null, false); - /* END: Use Case */ - } - - /** - * Test for the loadContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContent - */ - public function testLoadContentThrowsNotFoundExceptionLanguageNotFoundVariation() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Content only exists in eng-US, so we should only have it in eng-US. - $content = $contentService->loadContent(4, array('eng-US', 'eng-GB')); - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', - $content - ); - $this->assertContentValues($content, array('eng-US')); - /* END: Use Case */ - } - - /** - * Data provider for testLoadContentByRemoteId(). - * - * @return array - */ - public function testLoadContentByRemoteIdArgumentsProvider() - { - return array( - array('f5c88a2209584891056f987fd965b0ba', null, null), - array('f5c88a2209584891056f987fd965b0ba', array('eng-US'), null), - array('f5c88a2209584891056f987fd965b0ba', null, 1), - array('f5c88a2209584891056f987fd965b0ba', array('eng-US'), 1), - ); - } - - /** - * Test for the loadContentByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId - * @dataProvider testLoadContentByRemoteIdArgumentsProvider - * - * @param string $remoteId - * @param array|null $languages - * @param int $versionNo - * - * @return \eZ\Publish\API\Repository\Values\Content\Content - */ - public function testLoadContentByRemoteId($remoteId, $languages, $versionNo) - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $content = $contentService->loadContentByRemoteId($remoteId, $languages, $versionNo); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', - $content - ); - - $this->assertContentValues($content, $languages); - } - - /** - * Test for the loadContentByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadContentByRemoteIdThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - // Throws an exception because given remoteId does not exist - $content = $contentService->loadContentByRemoteId('non-existent-remote-id'); - /* END: Use Case */ - } - - /** - * Test for the loadContentByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadContentByRemoteIdThrowsUnauthorizedException() - { - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->loadContentByRemoteId('f5c88a2209584891056f987fd965b0ba'); - } - - /** - * Test for the loadContentByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadContentByRemoteIdWithVersionThrowsUnauthorizedException() - { - $contentService = $this->repository->getContentService(); - - $content = $contentService->loadContent(4); - $draft = $contentService->createContentDraft($content->contentInfo); - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->loadContentByRemoteId( - $draft->contentInfo->remoteId, - null, - $draft->versionInfo->versionNo - ); - } - - /** - * Test for the newContentCreateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::newContentCreateStruct - * - * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct - */ - public function testNewContentCreateStruct() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - $contentTypeService = $this->repository->getContentTypeService(); - - $folderContentType = $contentTypeService->loadContentType(1); - - $contentCreateStruct = $contentService->newContentCreateStruct( - $folderContentType, - 'eng-GB' - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct', - $contentCreateStruct - ); - - return array( - 'contentType' => $folderContentType, - 'contentCreateStruct' => $contentCreateStruct, - ); - } - - /** - * Test for the newContentCreateStruct() method. - * - * @depends testNewContentCreateStruct - * @covers \eZ\Publish\Core\Repository\ContentService::newContentCreateStruct - * - * @param array $data - */ - public function testNewContentCreateStructValues(array $data) - { - $contentType = $data['contentType']; - $contentCreateStruct = $data['contentCreateStruct']; - - $expectedValues = array( - 'fields' => array(), - 'contentType' => $contentType, - 'sectionId' => null, - 'ownerId' => null, - 'alwaysAvailable' => $contentType->defaultAlwaysAvailable, - 'remoteId' => null, - 'mainLanguageCode' => 'eng-GB', - 'modificationDate' => null, - ); - - $this->assertPropertiesCorrect( - $expectedValues, - $contentCreateStruct - ); - } - - /** - * Test for the createContent() method. - * - * @depends testNewContentCreateStruct - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * - * @return array - */ - public function testCreateContent() - { - $time = time(); - $testContentType = $this->createTestContentType(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); - $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - $locationCreates = array( - new LocationCreateStruct( - array( - //priority = 0 - //hidden = false - 'remoteId' => 'db787a9143f57828dd4331573466a013', - //sortField = Location::SORT_FIELD_NAME - //sortOrder = Location::SORT_ORDER_ASC - 'parentLocationId' => 2, - ) - ), - new LocationCreateStruct( - array( - //priority = 0 - //hidden = false - 'remoteId' => 'a3dd7c1c9e04c89e446a70f647286e6b', - //sortField = Location::SORT_FIELD_NAME - //sortOrder = Location::SORT_ORDER_ASC - 'parentLocationId' => 5, - ) - ), - ); - - $contentDraft = $contentService->createContent($contentCreate, $locationCreates); - /* END: Use Case */ - - $this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $contentDraft); - - return array( - 'expected' => $contentCreate, - 'actual' => $contentDraft, - 'loadedActual' => $contentService->loadContent($contentDraft->id, null, 1), - 'contentType' => $testContentType, - 'time' => $time, - ); - } - - /** - * Test for the createContent() method. - * - * @depends testCreateContent - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * - * @param array $data - */ - public function testCreateContentStructValues(array $data) - { - $this->assertCreateContentStructValues($data); - } - - /** - * Test for the createContent() method. - * - * Because of the way ContentHandler::create() is implemented and tested in legacy storage it is also necessary to - * test loaded content object, not only the one returned by ContentService::createContent - * - * @depends testCreateContent - * @depends testLoadContent - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * - * @param array $data - */ - public function testCreateContentStructValuesLoaded(array $data) - { - $data['actual'] = $data['loadedActual']; - - $this->assertCreateContentStructValues($data); - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * - * @param array $data - */ - protected function assertCreateContentStructValues(array $data) - { - $this->assertCreateContentStructValuesContentInfo($data); - $this->assertCreateContentStructValuesVersionInfo($data); - $this->assertCreateContentStructValuesRelations($data); - $this->assertCreateContentStructValuesFields($data); - } - - /** - * Asserts that ContentInfo is valid after Content creation. - * - * @param array $data - */ - protected function assertCreateContentStructValuesContentInfo(array $data) - { - /** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ - $contentDraft = $data['actual']; - /** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ - $contentCreate = $data['expected']; - - $this->assertPropertiesCorrect( - array( - 'id' => $contentDraft->id, - 'name' => $contentCreate->fields[0]->value, - 'sectionId' => $contentCreate->sectionId, - 'currentVersionNo' => 1, - 'published' => false, - 'ownerId' => $contentCreate->ownerId, - 'modificationDate' => null, - 'publishedDate' => null, - 'alwaysAvailable' => $contentCreate->alwaysAvailable, - 'remoteId' => $contentCreate->remoteId, - 'mainLanguageCode' => $contentCreate->mainLanguageCode, - // @todo: should be null, InMemory skips creating node assignments and creates locations right away - //"mainLocationId" => null, - //"contentType" - ), - $contentDraft->versionInfo->contentInfo - ); - $this->assertNotNull($contentDraft->id); - $this->assertEquals( - $contentCreate->contentType->id, - $contentDraft->versionInfo->contentInfo->contentTypeId - ); - } - - /** - * Asserts that VersionInfo is valid after Content creation. - * - * @param array $data - */ - protected function assertCreateContentStructValuesVersionInfo(array $data) - { - /** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ - $contentDraft = $data['actual']; - /** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ - $contentCreate = $data['expected']; - $time = $data['time']; - - $this->assertPropertiesCorrect( - array( - //"id" - 'versionNo' => 1, - //"creationDate" - //"modificationDate" - 'creatorId' => $contentCreate->ownerId, - 'status' => VersionInfo::STATUS_DRAFT, - 'initialLanguageCode' => $contentCreate->mainLanguageCode, - //"languageCodes" - 'names' => array( - 'eng-GB' => 'value for field definition with empty default value', - 'eng-US' => 'value for field definition with empty default value', - ), - ), - $contentDraft->versionInfo - ); - - $languageCodes = $this->getLanguageCodesFromFields($contentCreate->fields, $contentCreate->mainLanguageCode); - - $this->assertCount(count($languageCodes), $contentDraft->versionInfo->languageCodes); - foreach ($contentDraft->versionInfo->languageCodes as $languageCode) { - $this->assertTrue(in_array($languageCode, $languageCodes)); - } - $this->assertNotNull($contentDraft->versionInfo->id); - $this->assertGreaterThanOrEqual($this->getDateTime($time), $contentDraft->versionInfo->creationDate); - $this->assertGreaterThanOrEqual($this->getDateTime($time), $contentDraft->versionInfo->modificationDate); - } - - /** - * @param array $data - */ - protected function assertCreateContentStructValuesRelations(array $data) - { - // @todo: relations not implemented yet - } - - /** - * Asserts that fields are valid after Content creation. - * - * @param array $data - */ - protected function assertCreateContentStructValuesFields(array $data) - { - /** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ - $contentDraft = $data['actual']; - /** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ - $contentCreate = $data['expected']; - /** @var $contentType \eZ\Publish\API\Repository\Values\ContentType\ContentType */ - $contentType = $data['contentType']; - - $createdFields = $contentDraft->getFields(); - $createdInLanguageCodes = $this->getLanguageCodesFromFields( - $contentCreate->fields, - $contentCreate->mainLanguageCode - ); - - $this->assertCount( - count($contentType->fieldDefinitions) * count($createdInLanguageCodes), - $createdFields, - 'Number of created fields does not match number of content type field definitions multiplied by number of languages the content is created in' - ); - - // Check field values - $structFields = array(); - foreach ($contentCreate->fields as $field) { - $structFields[$field->fieldDefIdentifier][$field->languageCode] = $field; - } - foreach ($contentType->fieldDefinitions as $fieldDefinition) { - $this->assertArrayHasKey( - $fieldDefinition->identifier, - $contentDraft->fields, - "Field values are missing for field definition '{$fieldDefinition->identifier}'" - ); - - foreach ($createdInLanguageCodes as $languageCode) { - $this->assertArrayHasKey( - $languageCode, - $contentDraft->fields[$fieldDefinition->identifier], - "Field value is missing for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}'" - ); - - // If field is not set in create struct, it should have default value - $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreate->mainLanguageCode; - if (isset($structFields[$fieldDefinition->identifier][$valueLanguageCode])) { - $this->assertEquals( - $structFields[$fieldDefinition->identifier][$valueLanguageCode]->value, - $contentDraft->fields[$fieldDefinition->identifier][$languageCode], - "Field value for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}' is not equal to given struct field value" - ); - } else { - $this->assertEquals( - $fieldDefinition->defaultValue, - $contentDraft->fields[$fieldDefinition->identifier][$languageCode], - "Field value for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}' is not equal to default value" - ); - } - } - } - } - - /** - * Gathers language codes from an array of fields. - * - * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields - * @param string $mainLanguageCode - * - * @return array an array of language code strings - */ - protected function getLanguageCodesFromFields(array $fields, $mainLanguageCode) - { - $languageCodes = array($mainLanguageCode); - foreach ($fields as $field) { - $languageCodes[] = $field->languageCode; - } - - return array_unique($languageCodes); - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testCreateContentThrowsUnauthorizedException() - { - $testContentType = $this->createTestContentType(); - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); - $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - $locationCreates = array( - new LocationCreateStruct( - array( - 'remoteId' => 'db787a9143f57828dd4331573466a013', - 'parentLocationId' => 2, - ) - ), - ); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->createContent($contentCreate, $locationCreates); - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testCreateContentWithoutLocationsThrowsUnauthorizedException() - { - $testContentType = $this->createTestContentType(); - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); - $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->createContent($contentCreate, array()); - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - */ - public function testCreateContentThrowsInvalidArgumentException() - { - $testContentType = $this->createTestContentType(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = 'f5c88a2209584891056f987fd965b0ba'; - $contentCreate->alwaysAvailable = true; - - // Throws an exception because remoteId "f5c88a2209584891056f987fd965b0ba" already exists - $contentService->createContent($contentCreate); - /* END: Use Case */ - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException - * - * @return array - */ - public function testCreateContentThrowsContentValidationExceptionFieldDefinitionUnexisting() - { - $testContentType = $this->createTestContentType(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); - $contentCreate->setField('humpty_dumpty', 'no such field definition'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - // Throws an exception because field definition with identifier "humpty_dumpty" does not exist - $contentService->createContent($contentCreate); - /* END: Use Case */ - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException - * - * @return array - */ - public function testCreateContentThrowsContentValidationExceptionUntranslatableField() - { - $testContentType = $this->createTestContentType(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); - $contentCreate->setField('test_untranslatable', 'Bandersnatch', 'eng-US'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - // Throws an exception because translation was given for a untranslatable field - // Note that it is still permissible to set untranslatable field with main language - $contentService->createContent($contentCreate); - /* END: Use Case */ - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - * - * @return array - */ - public function testCreateContentRequiredFieldDefaultValueEmpty() - { - $testContentType = $this->createTestContentType(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_translatable', 'Jabberwock'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - // Throws an exception because required field is not set and its default value is empty - $contentService->createContent($contentCreate); - /* END: Use Case */ - } - - /** - * Test for the createContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - */ - public function testCreateContentThrowsContentFieldValidationException() - { - $testContentType = $this->createTestContentType(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField( - 'test_required_empty', - 'a string that is too long and will not validate 12345678901234567890123456789012345678901234567890' - ); - $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - // Throws an exception because "test_required_empty" field value is too long and fails - // field definition's string length validator - $contentService->createContent($contentCreate); - /* END: Use Case */ - } - - /** - * Test for the newContentMetadataUpdateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::newContentMetadataUpdateStruct - */ - public function testNewContentMetadataUpdateStruct() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentMetadataUpdateStruct', - $contentMetadataUpdateStruct - ); - - foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) { - $this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); - } - } - - /** - * Test for the updateContentMetadata() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata - * @depends testNewContentMetadataUpdateStruct - * - * @return array - */ - public function testUpdateContentMetadata() - { - // Create one additional location for content to be set as main location - $locationService = $this->repository->getLocationService(); - $contentInfo = $this->repository->getContentService()->loadContentInfo(12); - $locationCreateStruct = $locationService->newLocationCreateStruct(44); - $locationCreateStruct->remoteId = 'test-location-remote-id-1234'; - $newLocation = $locationService->createLocation( - $contentInfo, - $locationCreateStruct - ); - $newSectionId = $this->repository->getContentService()->loadContentInfo( - $locationService->loadLocation($newLocation->parentLocationId)->contentId - )->sectionId; - // Change content section to be different from new main location parent location content - $sectionService = $this->repository->getSectionService(); - $sectionService->assignSection( - $contentInfo, - $sectionService->loadSection($newSectionId === 1 ? $newSectionId + 1 : $newSectionId - 1) - ); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(12); - - $newMainLocationId = $newLocation->id; - $time = time(); - $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); - $contentMetadataUpdateStruct->ownerId = 10; - $contentMetadataUpdateStruct->publishedDate = $this->getDateTime($time); - $contentMetadataUpdateStruct->modificationDate = $this->getDateTime($time); - $contentMetadataUpdateStruct->mainLanguageCode = 'eng-GB'; - $contentMetadataUpdateStruct->alwaysAvailable = false; - $contentMetadataUpdateStruct->remoteId = 'the-all-new-remoteid'; - $contentMetadataUpdateStruct->mainLocationId = $newMainLocationId; - - $content = $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); - /* END: Use Case */ - - $this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $content); - - return array( - 'expected' => $contentMetadataUpdateStruct, - 'actual' => $content, - 'newSectionId' => $newSectionId, - ); - } - - /** - * Test for the updateContentMetadata() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata - * @depends testUpdateContentMetadata - * - * @param array $data - */ - public function testUpdateContentMetadataStructValues(array $data) - { - /** @var $updateStruct \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct */ - $updateStruct = $data['expected']; - /** @var $content \eZ\Publish\API\Repository\Values\Content\Content */ - $content = $data['actual']; - - $this->assertPropertiesCorrect( - array( - 'ownerId' => $updateStruct->ownerId, - // not changeable through MetadataUpdateStruct - //"name" - 'publishedDate' => $updateStruct->publishedDate, - 'modificationDate' => $updateStruct->modificationDate, - 'mainLanguageCode' => $updateStruct->mainLanguageCode, - 'alwaysAvailable' => $updateStruct->alwaysAvailable, - 'remoteId' => $updateStruct->remoteId, - 'mainLocationId' => $updateStruct->mainLocationId, - 'sectionId' => $data['newSectionId'], - ), - $content->contentInfo - ); - } - - /** - * Test for the updateContentMetadata() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testUpdateContentMetadataThrowsUnauthorizedException() - { - $contentInfo = $this->repository->getContentService()->loadContentInfo(12); - $contentMetadataUpdateStruct = $this->repository->getContentService()->newContentMetadataUpdateStruct(); - $contentMetadataUpdateStruct->remoteId = 'the-all-new-remoteid'; - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); - } - - /** - * Test for the updateContentMetadata() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @depends testNewContentMetadataUpdateStruct - */ - public function testUpdateContentMetadataThrowsInvalidArgumentExceptionDuplicateRemoteId() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - $contentInfo = $contentService->loadContentInfo(4); - $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); - $contentMetadataUpdateStruct->remoteId = '9b47a45624b023b1a76c73b74d704acf'; - - // Throws an exception because remoteId "9b47a45624b023b1a76c73b74d704acf" is already in use - $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); - /* END: Use Case */ - } - - /** - * Test for the updateContentMetadata() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @depends testNewContentMetadataUpdateStruct - */ - public function testUpdateContentMetadataThrowsInvalidArgumentExceptionNoMetadataPropertiesSet() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - $contentInfo = $contentService->loadContentInfo(4); - $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); - - // Throws an exception because no properties are set in $contentMetadataUpdateStruct - $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); - /* END: Use Case */ - } - - /** - * Test for the newContentUpdateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::newContentUpdateStruct - */ - public function testNewContentUpdateStruct() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentUpdateStruct', - $contentUpdateStruct - ); - - $this->assertPropertiesCorrect( - array( - 'initialLanguageCode' => null, - 'fields' => array(), - ), - $contentUpdateStruct - ); - } - - /** - * Test for the updateContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testUpdateContentThrowsUnauthorizedException() - { - list($content, $contentType) = $this->createTestContent(); - - $contentUpdateStruct = $this->repository->getContentService()->newContentUpdateStruct(); - $contentUpdateStruct->initialLanguageCode = 'eng-US'; - $contentUpdateStruct->setField('test_required_empty', 'new value for test_required_empty'); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->updateContent( - $content->versionInfo, - $contentUpdateStruct - ); - } - - /** - * Test for the updateContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - */ - public function testUpdateContentThrowsBadStateException() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById(4); - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - - // Throws an exception because version is not a draft - $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); - /* END: Use Case */ - } - - /** - * Test for the updateContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - */ - public function testUpdateContentThrowsContentFieldValidationException() - { - list($content, $contentType) = $this->createTestContent(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById( - $content->id, - $content->getVersionInfo()->versionNo - ); - - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - $contentUpdateStruct->initialLanguageCode = 'eng-US'; - $contentUpdateStruct->setField( - 'test_required_empty', - 'a string that is too long and will not validate 12345678901234567890123456789012345678901234567890' - ); - - // Throws an exception because "test_required_empty" field value is too long and fails - // field definition's string length validator - $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); - /* END: Use Case */ - } - - /** - * Test for the updateContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - */ - public function testUpdateContentRequiredFieldEmpty() - { - list($content, $contentType) = $this->createTestContent(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById( - $content->id, - $content->getVersionInfo()->versionNo - ); - - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - $contentUpdateStruct->initialLanguageCode = 'eng-GB'; - $contentUpdateStruct->setField('test_required_empty', ''); - - // Throws an exception because required field is being updated with empty value - $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); - /* END: Use Case */ - } - - /** - * Test for the updateContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException - */ - public function testUpdateContentThrowsContentValidationExceptionFieldDefinitionNonexistent() - { - list($content, $contentType) = $this->createTestContent(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById( - $content->id, - $content->getVersionInfo()->versionNo - ); - - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - $contentUpdateStruct->initialLanguageCode = 'eng-GB'; - $contentUpdateStruct->setField('nonexistent_field_definition_identifier', 'eng-GB'); - - // Throws an exception because field definition with identifier "nonexistent_field_definition_identifier" - // does not exist in content draft content type - $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); - /* END: Use Case */ - } - - /** - * Test for the updateContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::updateContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException - * - * @return array - */ - public function testUpdateContentThrowsContentValidationExceptionUntranslatableField() - { - list($content, $contentType) = $this->createTestContent(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById( - $content->id, - $content->getVersionInfo()->versionNo - ); - - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - $contentUpdateStruct->initialLanguageCode = 'eng-GB'; - $contentUpdateStruct->setField('test_untranslatable', 'Jabberwock', 'eng-US'); - - // Throws an exception because translation was given for a untranslatable field - // Note that it is still permissible to set untranslatable field with main language - $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); - /* END: Use Case */ - } - - /** - * Test for the publishVersion() method. - * - * @depends testCreateContent - * @covers \eZ\Publish\Core\Repository\ContentService::publishVersion - */ - public function testPublishVersion() - { - $time = time(); - list($draftContent, $contentType) = $this->createTestContent(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById( - $draftContent->id, - $draftContent->getVersionInfo()->versionNo - ); - - $publishedContent = $contentService->publishVersion($versionInfo); - /* END: Use Case */ - - $this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $publishedContent); - $this->assertTrue($publishedContent->contentInfo->published); - $this->assertEquals(VersionInfo::STATUS_PUBLISHED, $publishedContent->versionInfo->status); - $this->assertGreaterThanOrEqual($time, $publishedContent->contentInfo->publishedDate->getTimestamp()); - $this->assertGreaterThanOrEqual($time, $publishedContent->contentInfo->modificationDate->getTimestamp()); - } - - public function testPublishVersionDoesNotChangePublishedDate() - { - list($draftContent, $contentType) = $this->createTestContent(); - - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById( - $draftContent->id, - $draftContent->getVersionInfo()->versionNo - ); - - $publishedContent = $contentService->publishVersion($versionInfo); - - sleep(1); - - /* BEGIN: Use Case */ - $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo); - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - $contentUpdateStruct->initialLanguageCode = 'eng-GB'; - $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct); - $republishedContent = $contentService->publishVersion($contentDraft->versionInfo); - /* END: Use Case */ - - $this->assertEquals( - $publishedContent->contentInfo->publishedDate->getTimestamp(), - $republishedContent->contentInfo->publishedDate->getTimestamp() - ); - $this->assertGreaterThan( - $publishedContent->contentInfo->modificationDate->getTimestamp(), - $republishedContent->contentInfo->modificationDate->getTimestamp() - ); - } - - /** - * Test for the publishVersion() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::publishVersion - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - */ - public function testPublishVersionThrowsBadStateException() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById(4); - - // Throws an exception because version is already published - $publishedContent = $contentService->publishVersion($versionInfo); - /* END: Use Case */ - } - - /** - * Test for the publishVersion() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::publishVersion - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testPublishVersionThrowsUnauthorizedException() - { - list($draftContent, $contentType) = $this->createTestContent(); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentService()->publishVersion($draftContent->versionInfo); - } - - /** - * Test for the createContentDraft() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * - * @return array - */ - public function testCreateContentDraft() - { - $time = time(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - - $draftContent = $contentService->createContentDraft($contentInfo); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', - $draftContent - ); - - return array( - 'draftContent' => $draftContent, - 'time' => $time, - ); - } - - /** - * @param array $data - */ - protected function assertDraftContentValues(array $data) - { - /** @var $draftContent \eZ\Publish\API\Repository\Values\Content\Content */ - $draftContent = $data['draftContent']; - $time = $data['time']; - - $this->assertContentValues($data['draftContent'], null, true); - $this->assertGreaterThanOrEqual( - $this->getDateTime($time), - $draftContent->getVersionInfo()->creationDate - ); - $this->assertGreaterThanOrEqual( - $this->getDateTime($time), - $draftContent->getVersionInfo()->modificationDate - ); - } - - /** - * Test for the createContentDraft() method. - * - * @depends testCreateContentDraft - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * - * @param array $data - */ - public function testCreateContentDraftValues(array $data) - { - $this->assertDraftContentValues($data); - } - - /** - * Test for the createContentDraft() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * - * @return array - */ - public function testCreateContentDraftWithSecondArgument() - { - $time = time(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - $content = $contentService->loadContent(4); - - $draftContent = $contentService->createContentDraft( - $content->contentInfo, - $content->getVersionInfo() - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', - $draftContent - ); - - return array( - 'draftContent' => $draftContent, - 'time' => $time, - ); - } - - /** - * Test for the createContentDraft() method. - * - * @depends testCreateContentDraftWithSecondArgument - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * - * @param array $data - */ - public function testCreateContentDraftWithSecondArgumentValues(array $data) - { - $this->assertDraftContentValues($data); - } - - /** - * Test for the createContentDraft() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * - * @return array - */ - public function testCreateContentDraftWithThirdArgument() - { - $time = time(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - $content = $contentService->loadContent(4); - - $draftContent = $contentService->createContentDraft( - $content->contentInfo, - $content->getVersionInfo(), - $this->repository->getCurrentUser() - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', - $draftContent - ); - - return array( - 'draftContent' => $draftContent, - 'time' => $time, - ); - } - - /** - * Test for the createContentDraft() method. - * - * @depends testCreateContentDraftWithThirdArgument - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * - * @param array $data - */ - public function testCreateContentDraftWithThirdArgumentValues(array $data) - { - $this->assertDraftContentValues($data); - } - - /** - * Test for the createContentDraft() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - */ - public function testCreateContentDraftThrowsBadStateException() - { - $contentService = $this->repository->getContentService(); - $contentInfo = $contentService->loadContentInfo(4); - $draftContent = $contentService->createContentDraft($contentInfo); - - // Throws an exception because version status is not - // VersionInfo::STATUS_PUBLISHED nor VersionInfo::STATUS_ARCHIVED - $draftContent = $contentService->createContentDraft( - $draftContent->contentInfo, - $draftContent->getVersionInfo() - ); - } - - /** - * Test for the createContentDraft() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testCreateContentDraftThrowsUnauthorizedException() - { - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->createContentDraft($contentInfo); - } - - /** - * Test for the loadContentDrafts() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts - */ - public function testLoadContentDrafts() - { - $contentService = $this->repository->getContentService(); - - // delete existing drafts before we begin - $draftedVersions = $contentService->loadContentDrafts(); - foreach ($draftedVersions as $draftedVersion) { - $contentService->deleteVersion($draftedVersion); - } - - /* BEGIN: Use Case */ - // Remote ids of the "Users" user group of a eZ Publish demo installation. - $usersUserGroupRemoteId = 'f5c88a2209584891056f987fd965b0ba'; - $membersUserGroupRemoteId = '5f7f0bdb3381d6a461d8c29ff53d908f'; - - // "Users" user group content object - $usersUserGroupContentInfo = $contentService->loadContentInfoByRemoteId($usersUserGroupRemoteId); - $membersUserGroupContentInfo = $contentService->loadContentInfoByRemoteId($membersUserGroupRemoteId); - - // Create some drafts - $contentService->createContentDraft($usersUserGroupContentInfo); - $contentService->createContentDraft($membersUserGroupContentInfo); - - // Now $contentDrafts should contain two drafted versions - $draftedVersions = $contentService->loadContentDrafts(); - /* END: Use Case */ - - $actual = array( - $draftedVersions[0]->status, - $draftedVersions[1]->status, - count($draftedVersions), - $draftedVersions[0]->getContentInfo()->remoteId, - $draftedVersions[1]->getContentInfo()->remoteId, - ); - - $this->assertEquals( - array( - VersionInfo::STATUS_DRAFT, - VersionInfo::STATUS_DRAFT, - 2, - $usersUserGroupRemoteId, - $membersUserGroupRemoteId, - ), - $actual - ); - } - - /** - * Test for the loadContentDrafts() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts - */ - public function testLoadContentDraftsWithFirstArgument() - { - } - - /** - * Test for the loadContentDrafts() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadContentDraftsThrowsUnauthorizedException() - { - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - // Now $contentDrafts should contain two drafted versions - $this->repository->getContentService()->loadContentDrafts(); - } - - /** - * Test for the loadVersions() method. - * - * @depends testLoadContentInfo - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions - * - * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] - */ - public function testLoadVersions() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - $versions = $contentService->loadVersions($contentInfo); - /* END: Use Case */ - - return $versions; - } - - /** - * Test for the loadVersions() method. - * - * @depends testLoadVersions - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions - * - * @param array $versions - */ - public function testLoadVersionsValues(array $versions) - { - $versionInfoValues = $this->getVersionInfoExpectedValues(); - - $this->assertPropertiesCorrect( - $versionInfoValues, - $versions[0] - ); - } - - /** - * Test for the loadVersions() method. - * - * @depends testLoadContentInfo - * @depends testCreateContentDraft - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions - * - * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] - */ - public function testLoadVersionsMultiple() - { - $time = time(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - // Create one additional version - $draftContent = $contentService->createContentDraft($contentInfo); - $versions = $contentService->loadVersions($contentInfo); - /* END: Use Case */ - - return array( - 'versions' => $versions, - 'time' => $time, - ); - } - - /** - * Test for the loadVersions() method. - * - * @depends testLoadVersionsMultiple - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions - * - * @param array $data - */ - public function testLoadVersionsMultipleValues(array $data) - { - $versions = $data['versions']; - $time = $data['time']; - - $versionInfoValues = $this->getVersionInfoExpectedValues(); - $this->assertPropertiesCorrect( - $versionInfoValues, - $versions[0] - ); - - $versionInfoValues = $this->getVersionInfoExpectedValues(true); - $this->assertPropertiesCorrect( - $versionInfoValues, - $versions[1] - ); - $this->assertGreaterThanOrEqual( - $this->getDateTime($time), - $versions[1]->creationDate - ); - $this->assertGreaterThanOrEqual( - $this->getDateTime($time), - $versions[1]->modificationDate - ); - } - - /** - * Test for the loadVersions() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadVersionsThrowsUnauthorizedException() - { - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->loadVersions($contentInfo); - } - - /** - * Test for the deleteVersion() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion - */ - public function testDeleteVersion() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - - // Create a version to delete - $draftContent = $contentService->createContentDraft($contentInfo); - - $contentService->deleteVersion($draftContent->versionInfo); - /* END: Use Case */ - - try { - $contentService->loadVersionInfo( - $draftContent->contentInfo, - $draftContent->versionInfo->versionNo - ); - - $this->fail('Version was not successfully deleted!'); - } catch (NotFoundException $e) { - // Do nothing - } - } - - /** - * Test for the deleteVersion() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - */ - public function testDeleteVersionThrowsBadStateException() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $versionInfo = $contentService->loadVersionInfoById(4); - - // Throws an exception because version is published - $contentService->deleteVersion($versionInfo); - /* END: Use Case */ - } - - /** - * Test for the deleteVersion() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testDeleteVersionThrowsUnauthorizedException() - { - $contentService = $this->repository->getContentService(); - - $contentInfo = $contentService->loadContentInfo(4); - - // Create a version to delete - $draftContent = $contentService->createContentDraft($contentInfo); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->deleteVersion($draftContent->versionInfo); - } - - /** - * Test for the copyContent() method. - * - * @dep_ends testCreate - * @dep_ends testLoadContentInfo - * @dep_ends testLoadVersionInfoById - * @covers \eZ\Publish\Core\Repository\ContentService::copyContent - */ - public function testCopyContentSingleVersion() - { - $time = time(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - $locationService = $this->repository->getLocationService(); - - $contentInfo = $contentService->loadContentInfo(11); - $versionInfo = $contentService->loadVersionInfoById(11, 1); - $destinationLocationCreateStruct = $locationService->newLocationCreateStruct(5); - - $copiedContent = $contentService->copyContent( - $contentInfo, - $destinationLocationCreateStruct, - $versionInfo - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\Core\\Repository\\Values\\Content\\Content', - $copiedContent - ); - - $this->assertEquals(1, $copiedContent->contentInfo->currentVersionNo); - $this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->modificationDate->getTimestamp()); - $this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->publishedDate->getTimestamp()); - $this->assertCopyContentValues( - $contentService->loadContent(11, null, 1), - $copiedContent - ); - } - - /** - * Test for the copyContent() method. - * - * @dep_ends testLoadVersions - * @covers \eZ\Publish\Core\Repository\ContentService::copyContent - */ - public function testCopyContentAllVersions() - { - $time = time(); - - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - $locationService = $this->repository->getLocationService(); - - $contentInfo = $contentService->loadContentInfo(11); - $destinationLocationCreateStruct = $locationService->newLocationCreateStruct(5); - - $copiedContent = $contentService->copyContent( - $contentInfo, - $destinationLocationCreateStruct - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\Core\\Repository\\Values\\Content\\Content', - $copiedContent - ); - - $this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->modificationDate->getTimestamp()); - $this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->publishedDate->getTimestamp()); - - $originalVersionInfos = $contentService->loadVersions($contentInfo); - $copiedVersionInfos = $contentService->loadVersions($copiedContent->contentInfo); - $sorter = - function (VersionInfo $a, VersionInfo $b) { - return strcmp($a->versionNo, $b->versionNo); - }; - usort($originalVersionInfos, $sorter); - usort($copiedVersionInfos, $sorter); - $this->assertCount( - count($originalVersionInfos), - $copiedVersionInfos, - 'Count of versions copied does not match the count of original versions' - ); - $this->assertEquals($contentInfo->currentVersionNo, $copiedContent->contentInfo->currentVersionNo); - foreach ($originalVersionInfos as $index => $versionInfo) { - $this->assertEquals($versionInfo->versionNo, $copiedVersionInfos[$index]->versionNo); - $this->assertCopyContentValues( - $contentService->loadContent( - $contentInfo->id, - null, - $versionInfo->versionNo - ), - $contentService->loadContent( - $copiedContent->id, - null, - $copiedVersionInfos[$index]->versionNo - ) - ); - } - } - - /** - * Asserts that $copiedContent is valid copy of $originalContent. - * - * @param \eZ\Publish\API\Repository\Values\Content\Content $originalContent - * @param \eZ\Publish\API\Repository\Values\Content\Content $copiedContent - */ - protected function assertCopyContentValues(APIContent $originalContent, APIContent $copiedContent) - { - $this->assertNotEquals( - $originalContent->id, - $copiedContent->id, - 'Id of content copy is equal to id od original content' - ); - - $this->assertSameClassPropertiesCorrect( - array( - //"name", - 'contentTypeId', - 'sectionId', - //"currentVersionNo", - 'published', - 'ownerId', - 'alwaysAvailable', - 'mainLanguageCode', - //"mainLocationId" - ), - $originalContent->contentInfo, - $copiedContent->contentInfo - ); - $this->assertNotEquals($originalContent->contentInfo->id, $copiedContent->contentInfo->id); - $this->assertNotEquals($originalContent->contentInfo->remoteId, $copiedContent->contentInfo->remoteId); - - $this->assertSameClassPropertiesCorrect( - array( - 'versionNo', - //"contentId", - 'names', - //"creationDate", - //"modificationDate", - 'creatorId', - //"status", - 'initialLanguageCode', - 'languageCodes', - ), - $originalContent->versionInfo, - $copiedContent->versionInfo - ); - $this->assertNotEquals($originalContent->versionInfo->id, $copiedContent->versionInfo->id); - - $originalFields = $originalContent->getFields(); - $copiedFields = $copiedContent->getFields(); - $this->assertCount( - count($originalFields), - $copiedFields, - 'Count of fields copied does not match the count of original fields' - ); - foreach ($originalFields as $fieldIndex => $originalField) { - $this->assertSameClassPropertiesCorrect( - array( - 'fieldDefIdentifier', - 'value', - 'languageCode', - ), - $originalField, - $copiedFields[$fieldIndex] - ); - $this->assertNotEquals( - $originalField->id, - $copiedFields[$fieldIndex]->id - ); - } - } - - /** - * Test for the copyContent() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::copyContent - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testCopyContentThrowsUnauthorizedException() - { - $contentService = $this->repository->getContentService(); - $locationService = $this->repository->getLocationService(); - - $contentInfo = $contentService->loadContentInfo(11); - $destinationLocationCreateStruct = $locationService->newLocationCreateStruct(5); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->copyContent($contentInfo, $destinationLocationCreateStruct); - } - - /** - * Test for the newTranslationInfo() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::newTranslationInfo - */ - public function testNewTranslationInfo() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $translationInfo = $contentService->newTranslationInfo(); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\TranslationInfo', - $translationInfo - ); - - foreach ($translationInfo as $propertyName => $propertyValue) { - $this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); - } - } - - /** - * Test for the newTranslationValues() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::newTranslationValues - */ - public function testNewTranslationValues() - { - /* BEGIN: Use Case */ - $contentService = $this->repository->getContentService(); - - $translationValues = $contentService->newTranslationValues(); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\TranslationValues', - $translationValues - ); - - foreach ($translationValues as $propertyName => $propertyValue) { - $this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); - } - } - - /** - * Test for the loadRelations() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadRelations - * @covers \eZ\Publish\Core\Repository\ContentService::addRelation - */ - public function testLoadRelations() - { - list($contentDraft, $contentType) = $this->createTestContent(); - $contentService = $this->repository->getContentService(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->addRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - - $relations = $contentService->loadRelations($contentDraft->versionInfo); - - $this->assertRelations($relations, $contentDraft->contentInfo, $mediaContentInfo); - } - - protected function assertRelations($relations, $sourceContentInfo, $destinationContentInfo) - { - self::assertInternalType('array', $relations); - self::assertCount(1, $relations); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Relation', $relations[0]); - self::assertNotNull($relations[0]->id); - self::assertEquals(Relation::COMMON, $relations[0]->type); - self::assertNull($relations[0]->sourceFieldDefinitionIdentifier); - self::assertEquals($sourceContentInfo, $relations[0]->sourceContentInfo); - self::assertEquals($destinationContentInfo, $relations[0]->destinationContentInfo); - } - - /** - * Test for the loadRelations() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadRelations - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadRelationsThrowsUnauthorizedException() - { - list($contentDraft, $contentType) = $this->createTestContent(); - $contentService = $this->repository->getContentService(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->addRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->loadRelations($contentDraft->versionInfo); - } - - /** - * Test for the loadReverseRelations() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::loadReverseRelations - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testLoadReverseRelationsThrowsUnauthorizedException() - { - list($contentDraft, $contentType) = $this->createTestContent(); - $contentService = $this->repository->getContentService(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->addRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->loadReverseRelations($mediaContentInfo); - } - - /** - * Test for the addRelation() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::addRelation - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testAddRelationThrowsUnauthorizedException() - { - list($contentDraft, $contentType) = $this->createTestContent(); - $contentService = $this->repository->getContentService(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->addRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - } - - /** - * Test for the addRelation() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::addRelation - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - */ - public function testAddRelationThrowsBadStateException() - { - $contentService = $this->repository->getContentService(); - list($contentDraft, $contentType) = $this->createTestContent(); - $publishedContent = $contentService->publishVersion($contentDraft->versionInfo); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->addRelation( - $publishedContent->getVersionInfo(), - $mediaContentInfo - ); - } - - /** - * Test for the deleteRelation() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation - */ - public function testDeleteRelation() - { - list($contentDraft, $contentType) = $this->createTestContent(); - $contentService = $this->repository->getContentService(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->addRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - - $contentService->deleteRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - - $relations = $contentService->loadRelations($contentDraft->versionInfo); - - self::assertCount(0, $relations); - } - - /** - * Test for the deleteRelation() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testDeleteRelationThrowsUnauthorizedException() - { - list($contentDraft, $contentType) = $this->createTestContent(); - $contentService = $this->repository->getContentService(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->addRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentService->deleteRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - } - - /** - * Test for the deleteRelation() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - */ - public function testDeleteRelationThrowsBadStateException() - { - $contentService = $this->repository->getContentService(); - list($contentDraft, $contentType) = $this->createTestContent(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->addRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - - $publishedContent = $contentService->publishVersion($contentDraft->versionInfo); - - $contentService->deleteRelation( - $publishedContent->getVersionInfo(), - $mediaContentInfo - ); - } - - /** - * Test for the deleteRelation() method. - * - * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - */ - public function testDeleteRelationThrowsInvalidArgumentException() - { - list($contentDraft, $contentType) = $this->createTestContent(); - $contentService = $this->repository->getContentService(); - - $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); - - $contentService->deleteRelation( - $contentDraft->getVersionInfo(), - $mediaContentInfo - ); - } - - /** - * Creates and returns content draft used in testing. - * - * @return \eZ\Publish\API\Repository\Values\Content\Content - */ - protected function createTestContent() - { - $contentService = $this->repository->getContentService(); - $testContentType = $this->createTestContentType(); - - $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); - $contentCreate->setField('test_required_empty', 'val-11'); - $contentCreate->setField('test_required_not_empty', 'val-12'); - $contentCreate->setField('test_translatable', 'val-13'); - $contentCreate->setField('test_untranslatable', 'val-14'); - $contentCreate->setField('test_translatable', 'val-23', 'eng-US'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; - $contentCreate->alwaysAvailable = true; - - $locationCreates = array( - new LocationCreateStruct( - array( - //priority = 0 - //hidden = false - 'remoteId' => 'db787a9143f57828dd4331573466a013', - //sortField = Location::SORT_FIELD_NAME - //sortOrder = Location::SORT_ORDER_ASC - 'parentLocationId' => 2, - ) - ), - new LocationCreateStruct( - array( - //priority = 0 - //hidden = false - 'remoteId' => 'a3dd7c1c9e04c89e446a70f647286e6b', - //sortField = Location::SORT_FIELD_NAME - //sortOrder = Location::SORT_ORDER_ASC - 'parentLocationId' => 5, - ) - ), - ); - - return array($contentService->createContent($contentCreate, $locationCreates), $testContentType); - } - - /** - * Returns ContentType used in testing. - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType - */ - protected function createTestContentType() - { - $contentTypeService = $this->repository->getContentTypeService(); - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'test-type' - ); - $typeCreateStruct->names = array('eng-GB' => 'Test type name'); - $typeCreateStruct->descriptions = array('eng-GB' => 'Test type description'); - $typeCreateStruct->remoteId = 'test-type-remoteid'; - $typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $typeCreateStruct->creationDate = $this->getDateTime(0); - $typeCreateStruct->mainLanguageCode = 'eng-GB'; - $typeCreateStruct->nameSchema = ''; - $typeCreateStruct->urlAliasSchema = ''; - - $fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_required_empty', 'ezstring'); - $fieldCreate->names = array('eng-GB' => 'Test required empty'); - $fieldCreate->descriptions = array('eng-GB' => 'Required field with empty default value'); - $fieldCreate->fieldGroup = 'test-field-group'; - $fieldCreate->position = 1; - $fieldCreate->isTranslatable = false; - $fieldCreate->isRequired = true; - $fieldCreate->isInfoCollector = false; - $fieldCreate->isSearchable = true; - $fieldCreate->defaultValue = ''; - //$validator = new StringLengthValidator(); - //$validator->maxStringLength = 64; - //$fieldCreate->validatorConfiguration = array( $validator ); - $fieldCreate->validatorConfiguration = array( - 'StringLengthValidator' => array( - 'maxStringLength' => 64, - ), - ); - //$fieldCreate->fieldSettings - $typeCreateStruct->addFieldDefinition($fieldCreate); - - $fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_required_not_empty', 'ezstring'); - $fieldCreate->names = array('eng-GB' => 'Test required not empty'); - $fieldCreate->descriptions = array('eng-GB' => 'Required field with default value not empty'); - $fieldCreate->fieldGroup = 'test-field-group'; - $fieldCreate->position = 2; - $fieldCreate->isTranslatable = false; - $fieldCreate->isRequired = true; - $fieldCreate->isInfoCollector = false; - $fieldCreate->isSearchable = true; - $fieldCreate->defaultValue = 'dummy default data'; - //$fieldCreate->validators - //$fieldCreate->fieldSettings - $typeCreateStruct->addFieldDefinition($fieldCreate); - - $fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_translatable', 'ezstring'); - $fieldCreate->names = array('eng-GB' => 'Test translatable'); - $fieldCreate->descriptions = array('eng-GB' => 'Translatable field'); - $fieldCreate->fieldGroup = 'test-field-group'; - $fieldCreate->position = 3; - $fieldCreate->isTranslatable = true; - $fieldCreate->isRequired = false; - $fieldCreate->isInfoCollector = false; - $fieldCreate->isSearchable = true; - $fieldCreate->defaultValue = ''; - //$fieldCreate->validators - //$fieldCreate->fieldSettings - $typeCreateStruct->addFieldDefinition($fieldCreate); - - $fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_untranslatable', 'ezstring'); - $fieldCreate->names = array('eng-GB' => 'Test not translatable'); - $fieldCreate->descriptions = array('eng-GB' => 'Untranslatable field'); - $fieldCreate->fieldGroup = 'test-field-group'; - $fieldCreate->position = 4; - $fieldCreate->isTranslatable = false; - $fieldCreate->isRequired = false; - $fieldCreate->isInfoCollector = false; - $fieldCreate->isSearchable = true; - $fieldCreate->defaultValue = ''; - //$fieldCreate->validators - //$fieldCreate->fieldSettings - $typeCreateStruct->addFieldDefinition($fieldCreate); - - $contentTypeDraft = $contentTypeService->createContentType( - $typeCreateStruct, - array($contentTypeService->loadContentTypeGroup(1)) - ); - $contentTypeId = $contentTypeDraft->id; - - $contentTypeService->publishContentTypeDraft($contentTypeDraft); - - return $contentTypeService->loadContentType($contentTypeId); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/ContentTypeBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/ContentTypeBase.php deleted file mode 100644 index dafb14cfcf2..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/ContentTypeBase.php +++ /dev/null @@ -1,3447 +0,0 @@ -repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'new-group' - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeGroupCreateStruct', - $groupCreate - ); - - return $groupCreate; - } - - /** - * Test for the newContentTypeGroupCreateStruct() method. - * - * @depends testNewContentTypeGroupCreateStruct - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeGroupCreateStruct - * - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroupCreateStruct $createStruct - */ - public function testNewContentTypeGroupCreateStructValues($createStruct) - { - $this->assertPropertiesCorrect( - array( - 'identifier' => 'new-group', - 'creatorId' => null, - 'creationDate' => null, - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //'mainLanguageCode' => null, - //'names' => null, - //'descriptions' => null - ), - $createStruct - ); - } - - /** - * Test for the createContentTypeGroup() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - * - * @return array - */ - public function testCreateContentTypeGroup() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'new-group' - ); - $groupCreate->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $groupCreate->creationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupCreate->mainLanguageCode = 'eng-GB'; - //$groupCreate->names = array( 'eng-US' => 'A name.' ); - //$groupCreate->descriptions = array( 'eng-US' => 'A description.' ); - - $group = $contentTypeService->createContentTypeGroup($groupCreate); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeGroup', - $group - ); - - return array( - 'expected' => $groupCreate, - 'actual' => $group, - ); - } - - /** - * Test for the newContentTypeGroupCreateStruct() method. - * - * @depends testCreateContentTypeGroup - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeGroupCreateStruct - * - * @param array $data - * - * @todo remove $notImplemented when implemented - */ - public function testCreateContentTypeGroupStructValues(array $data) - { - $notImplemented = array( - 'names', - 'descriptions', - 'mainLanguageCode', - ); - - $this->assertStructPropertiesCorrect( - $data['expected'], - $data['actual'], - $notImplemented - ); - - $this->assertNotNull( - $data['actual']->id - ); - } - - /** - * Test for the createContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - */ - public function testCreateContentTypeGroupThrowsUnauthorizedException() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'new-group' - ); - $groupCreate->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $groupCreate->creationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // $groupCreate->mainLanguageCode = 'eng-GB'; - // $groupCreate->names = array( 'eng-US' => 'A name.' ); - // $groupCreate->descriptions = array( 'eng-US' => 'A description.' ); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->createContentTypeGroup($groupCreate); - } - - /** - * Test for the createContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - */ - public function testCreateContentTypeGroupThrowsInvalidArgumentException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'new-group' - ); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupCreate->names = array( 'eng-GB'=> 'NewGroup' ); - //$groupCreate->descriptions = array(); - $contentTypeService->createContentTypeGroup($groupCreate); - - $secondGroupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'new-group' - ); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$secondGroupCreate->names = array( 'eng-GB'=> 'NewGroup' ); - //$secondGroupCreate->descriptions = array(); - - // Throws an exception because group with identifier "new-group" already exists - $contentTypeService->createContentTypeGroup($secondGroupCreate); - /* END: Use Case */ - } - - /** - * Test for the loadContentTypeGroup() method. - * - * @depends testCreateContentTypeGroup - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroup - * - * @return array - */ - public function testLoadContentTypeGroup() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'new-group' - ); - $groupCreate->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $groupCreate->creationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupCreate->mainLanguageCode = 'eng-GB'; - //$groupCreate->names = array( 'eng-US' => 'A name.' ); - //$groupCreate->descriptions = array( 'eng-US' => 'A description.' ); - - $storedGroup = $contentTypeService->createContentTypeGroup($groupCreate); - - /* BEGIN: Use Case */ - $loadedGroup = $contentTypeService->loadContentTypeGroup( - $storedGroup->id - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeGroup', - $loadedGroup - ); - - return array( - 'expected' => $storedGroup, - 'actual' => $loadedGroup, - ); - } - - /** - * Test for the loadContentTypeGroup() method. - * - * @depends testLoadContentTypeGroup - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroup - * - * @param array $data - */ - public function testLoadContentTypeGroupValues(array $data) - { - $this->assertContentTypeGroupsEqual($data); - } - - /** - * Test for the loadContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroup - */ - public function testLoadContentTypeGroupThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - // Throws exception - $loadedGroup = $contentTypeService->loadContentTypeGroup(APIBaseTest::DB_INT_MAX); - /* END: Use Case */ - } - - /** - * Test for the loadContentTypeGroupByIdentifier() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroupByIdentifier - * - * @return array - */ - public function testLoadContentTypeGroupByIdentifier() - { - /* BEGIN: Use Case */ - $storedGroup = $this->createContentTypeGroup(); - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedGroup = $contentTypeService->loadContentTypeGroupByIdentifier( - $storedGroup->identifier - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeGroup', - $loadedGroup - ); - - return array( - 'expected' => $storedGroup, - 'actual' => $loadedGroup, - ); - } - - /** - * Test for the loadContentTypeGroupByIdentifier() method. - * - * @depends testLoadContentTypeGroupByIdentifier - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroupByIdentifier - * - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $data - */ - public function testLoadContentTypeGroupByIdentifierValues(array $data) - { - $this->assertContentTypeGroupsEqual($data); - } - - /** - * Asserts that two given ContentTypeGroup objects contain the same group data. - * - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $data - * - * @todo remove $notImplemented when implemented - */ - protected function assertContentTypeGroupsEqual(array $data) - { - $storedGroup = $data['expected']; - $loadedGroup = $data['actual']; - $notImplemented = array( - 'mainLanguageCode', - 'names', - 'descriptions', - ); - - $this->assertSameClassPropertiesCorrect( - array( - 'id', - 'identifier', - 'creationDate', - 'modificationDate', - 'creatorId', - 'modifierId', - 'mainLanguageCode', - 'names', - 'descriptions', - ), - $storedGroup, - $loadedGroup, - $notImplemented - ); - } - - /** - * Test for the loadContentTypeGroupByIdentifier() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroupByIdentifier - */ - public function testLoadContentTypeGroupByIdentifierThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - // Throws an exception - $loadedGroup = $contentTypeService->loadContentTypeGroupByIdentifier( - 'the-no-identifier-like-this' - ); - /* END: Use Case */ - } - - /** - * Test for the loadContentTypeGroups() method. - * - * @depends testLoadContentTypeGroup - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroups - * - * @return array - */ - public function testLoadContentTypeGroups() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedGroups = $contentTypeService->loadContentTypeGroups(); - /* END: Use Case */ - - $this->assertInternalType( - 'array', - $loadedGroups - ); - - foreach ($loadedGroups as $loadedGroup) { - $this->assertContentTypeGroupsEqual( - array( - 'expected' => $contentTypeService->loadContentTypeGroup($loadedGroup->id), - 'actual' => $loadedGroup, - ) - ); - } - - return $loadedGroups; - } - - /** - * Test for the loadContentTypeGroups() method. - * - * @depends testLoadContentTypeGroups - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeGroups - * - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $groups - */ - public function testLoadContentTypeGroupsIdentifiers(array $groups) - { - $expectedIdentifiers = array( - 'Content' => true, - 'Users' => true, - 'Media' => true, - 'Setup' => true, - ); - - $this->assertEquals( - count($expectedIdentifiers), - count($groups) - ); - - $actualIdentifiers = array( - 'Content' => false, - 'Users' => false, - 'Media' => false, - 'Setup' => false, - ); - - foreach ($groups as $group) { - $actualIdentifiers[$group->identifier] = true; - } - - $this->assertEquals( - $expectedIdentifiers, - $actualIdentifiers, - 'Identifier mismatch in loaded and actual groups.' - ); - } - - /** - * Test for the newContentTypeGroupUpdateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeGroupUpdateStruct - */ - public function testNewContentTypeGroupUpdateStruct() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $groupUpdate = $contentTypeService->newContentTypeGroupUpdateStruct(); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeGroupUpdateStruct', - $groupUpdate - ); - } - - /** - * Test for the updateContentTypeGroup() method. - * - * @depends testLoadContentTypeGroup - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeGroup - * - * @return array - */ - public function testUpdateContentTypeGroup() - { - $this->createContentTypeGroup(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $group = $contentTypeService->loadContentTypeGroupByIdentifier('new-group'); - - $groupUpdate = $contentTypeService->newContentTypeGroupUpdateStruct(); - $groupUpdate->identifier = 'updated-group'; - $groupUpdate->modifierId = 42; - $groupUpdate->modificationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupUpdate->mainLanguageCode = 'en_US'; - //$groupUpdate->names = array( - // 'en_US' => 'A name', - // 'en_GB' => 'A name', - //); - //$groupUpdate->descriptions = array( - // 'en_US' => 'A description', - // 'en_GB' => 'A description', - //); - - $contentTypeService->updateContentTypeGroup($group, $groupUpdate); - /* END: Use Case */ - - $updatedGroup = $contentTypeService->loadContentTypeGroup($group->id); - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeGroupUpdateStruct', - $groupUpdate - ); - - return array( - 'originalGroup' => $group, - 'updateStruct' => $groupUpdate, - 'updatedGroup' => $updatedGroup, - ); - } - - /** - * Test for the updateContentTypeGroup() method. - * - * @depends testUpdateContentTypeGroup - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeGroup - * - * @param array $data - * - * @todo remove $notImplemented when implemented - */ - public function testUpdateContentTypeGroupStructValues(array $data) - { - $originalGroup = $data['originalGroup']; - $updateStruct = $data['updateStruct']; - $updatedGroup = $data['updatedGroup']; - - $notImplemented = array( - 'mainLanguageCode', - 'names', - 'descriptions', - ); - - $expectedValues = array( - 'identifier' => $updateStruct->identifier, - 'creationDate' => $originalGroup->creationDate, - 'modificationDate' => $updateStruct->modificationDate, - 'creatorId' => $originalGroup->creatorId, - 'modifierId' => $updateStruct->modifierId, - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //'mainLanguageCode' => $updateStruct->mainLanguageCode, - //'names' => $updateStruct->names, - //'descriptions' => $updateStruct->descriptions, - ); - - $this->assertPropertiesCorrect( - $expectedValues, - $updatedGroup, - $notImplemented - ); - } - - /** - * Creates a group with identifier "new-group". - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup - */ - protected function createContentTypeGroup() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'new-group' - ); - $groupCreate->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $groupCreate->creationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupCreate->mainLanguageCode = 'eng-US'; - //$groupCreate->names = array( 'eng-US' => 'Name' ); - //$groupCreate->descriptions = array( 'eng-US' => 'Description' ); - - return $contentTypeService->createContentTypeGroup($groupCreate); - } - - /** - * Test for the updateContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeGroup - */ - public function testUpdateContentTypeGroupThrowsUnauthorizedException() - { - $this->createContentTypeGroup(); - $contentTypeService = $this->repository->getContentTypeService(); - - $group = $contentTypeService->loadContentTypeGroupByIdentifier('new-group'); - - $groupUpdate = $contentTypeService->newContentTypeGroupUpdateStruct(); - $groupUpdate->identifier = 'updated-group'; - $groupUpdate->modifierId = 42; - $groupUpdate->modificationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - /* - $groupUpdate->mainLanguageCode = 'en_US'; - $groupUpdate->names = array( - 'en_US' => 'A name', - 'en_GB' => 'A name', - ); - $groupUpdate->descriptions = array( - 'en_US' => 'A description', - 'en_GB' => 'A description', - ); - */ - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->updateContentTypeGroup($group, $groupUpdate); - } - - /** - * Test for the updateContentTypeGroup() method. - * - * @depends testUpdateContentTypeGroup - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeGroup - */ - public function testUpdateContentTypeGroupThrowsInvalidArgumentException() - { - // Creates ContentTypeGroup with identifier "new-group" - $this->createContentTypeGroup(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'updated-group' - ); - $groupCreate->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupCreate->names = array( 'eng-US' => 'Name' ); - //$groupCreate->descriptions = array( 'eng-US' => 'Description' ); - $groupToOverwrite = $contentTypeService->createContentTypeGroup($groupCreate); - - $group = $contentTypeService->loadContentTypeGroupByIdentifier('new-group'); - - $groupUpdate = $contentTypeService->newContentTypeGroupUpdateStruct(); - $groupUpdate->identifier = 'updated-group'; - - // Exception, because group with identifier "updated-group" exists - $contentTypeService->updateContentTypeGroup($group, $groupUpdate); - /* END: Use Case */ - } - - /** - * Test for the deleteContentTypeGroup() method. - * - * @depends testCreateContentTypeGroup - * @depends testLoadContentTypeGroup - * @covers \eZ\Publish\Core\Repository\ContentTypeService::deleteContentTypeGroup - */ - public function testDeleteContentTypeGroup() - { - // Creates ContentTypeGroup with identifier "new-group" - $this->createContentTypeGroup(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $group = $contentTypeService->loadContentTypeGroupByIdentifier('new-group'); - - $contentTypeService->deleteContentTypeGroup($group); - /* END: Use Case */ - - try { - $contentTypeService->loadContentTypeGroup($group->id); - $this->fail('Content type group not deleted.'); - } catch (NotFoundException $e) { - // All fine - } - } - - /** - * Test for the deleteContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::deleteContentTypeGroup - */ - public function testDeleteContentTypeGroupThrowsInvalidArgumentException() - { - $this->createContentTypeGroup(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - // "Content" group - $contentGroup = $contentTypeService->loadContentTypeGroup(1); - - // Throws exception because group content type has instances - $contentTypeService->deleteContentTypeGroup($contentGroup); - /* END: Use Case */ - } - - /** - * Test for the deleteContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::deleteContentTypeGroup - */ - public function testDeleteContentTypeGroupThrowsUnauthorizedException() - { - $this->createContentTypeGroup(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $group = $contentTypeService->loadContentTypeGroupByIdentifier('new-group'); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->deleteContentTypeGroup($group); - } - - /** - * Creates a number of ContentTypeGroup objects and returns them. - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] - */ - protected function createGroups() - { - if (empty($this->contentTypeGroups)) { - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'first-group' - ); - $groupCreate->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $groupCreate->creationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupCreate->mainLanguageCode = 'de_DE'; - //$groupCreate->names = array( 'en_US' => 'A name.' ); - //$groupCreate->descriptions = array( 'en_US' => 'A description.' ); - $this->contentTypeGroups[] = $contentTypeService->createContentTypeGroup($groupCreate); - - $groupCreate->identifier = 'second-group'; - $this->contentTypeGroups[] = $contentTypeService->createContentTypeGroup($groupCreate); - } - - return $this->contentTypeGroups; - } - - /** - * Test for the newContentTypeUpdateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeUpdateStruct - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeUpdateStruct - */ - public function testNewContentTypeUpdateStruct() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $contentTypeUpdateStruct = $contentTypeService->newContentTypeUpdateStruct(); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeUpdateStruct', - $contentTypeUpdateStruct - ); - - return $contentTypeUpdateStruct; - } - - /** - * Test for the newContentTypeUpdateStruct() method. - * - * @depends testNewContentTypeUpdateStruct - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeUpdateStruct - * - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeUpdateStruct $contentTypeUpdateStruct - */ - public function testNewContentTypeUpdateStructValues($contentTypeUpdateStruct) - { - foreach ($contentTypeUpdateStruct as $propertyName => $propertyValue) { - $this->assertNull( - $propertyValue, - "Property '$propertyName' is not null." - ); - } - } - - /** - * Test for the newContentTypeCreateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeCreateStruct - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeCreateStruct - */ - public function testNewContentTypeCreateStruct() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $contentTypeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'new-type' - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeCreateStruct', - $contentTypeCreateStruct - ); - - return $contentTypeCreateStruct; - } - - /** - * Test for the newContentTypeCreateStruct() method. - * - * @depends testNewContentTypeCreateStruct - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeCreateStruct - * - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeCreateStruct $contentTypeCreateStruct - */ - public function testNewContentTypeCreateStructValues($contentTypeCreateStruct) - { - $this->assertPropertiesCorrect( - array( - 'identifier' => 'new-type', - 'mainLanguageCode' => null, - 'remoteId' => null, - 'urlAliasSchema' => null, - 'nameSchema' => null, - 'isContainer' => false, - 'defaultSortField' => Location::SORT_FIELD_PUBLISHED, - 'defaultSortOrder' => Location::SORT_ORDER_DESC, - 'defaultAlwaysAvailable' => true, - 'names' => null, - 'descriptions' => null, - 'creatorId' => null, - 'creationDate' => null, - 'fieldDefinitions' => array(), - ), - $contentTypeCreateStruct - ); - } - - /** - * Test for the newContentTypeCreateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newFieldDefinitionCreateStruct - * - * @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct - */ - public function testNewFieldDefinitionCreateStruct() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $fieldDefinitionCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct( - 'new-identifier', - 'new-fieldtype-identifier' - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinitionCreateStruct', - $fieldDefinitionCreateStruct - ); - - return $fieldDefinitionCreateStruct; - } - - /** - * Test for the newContentTypeCreateStruct() method. - * - * @depends testNewFieldDefinitionCreateStruct - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newFieldDefinitionCreateStruct - * - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct - */ - public function testNewFieldDefinitionCreateStructValues($fieldDefinitionCreateStruct) - { - $this->assertPropertiesCorrect( - array( - 'fieldTypeIdentifier' => 'new-fieldtype-identifier', - 'identifier' => 'new-identifier', - 'names' => null, - 'descriptions' => null, - 'fieldGroup' => null, - 'position' => null, - 'isTranslatable' => null, - 'isRequired' => null, - 'isInfoCollector' => null, - 'validatorConfiguration' => null, - 'fieldSettings' => null, - 'defaultValue' => null, - 'isSearchable' => null, - ), - $fieldDefinitionCreateStruct - ); - } - - /** - * Test for the newFieldDefinitionUpdateStruct() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newFieldDefinitionUpdateStruct - * - * @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct - */ - public function testNewFieldDefinitionUpdateStruct() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $fieldDefinitionUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct(); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinitionUpdateStruct', - $fieldDefinitionUpdateStruct - ); - - return $fieldDefinitionUpdateStruct; - } - - /** - * Test for the newFieldDefinitionUpdateStruct() method. - * - * @depends testNewFieldDefinitionUpdateStruct - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeUpdateStruct - * - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct - */ - public function testNewFieldDefinitionUpdateStructValues($fieldDefinitionUpdateStruct) - { - foreach ($fieldDefinitionUpdateStruct as $propertyName => $propertyValue) { - $this->assertNull( - $propertyValue, - "Property '$propertyName' is not null." - ); - } - } - - /** - * Creates a ContentType with identifier "new-type" and remoteId "new-remoteid". - * - * @param bool $publish - * @param int $creatorId - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType|\eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft - */ - protected function createContentType($publish = true, $creatorId = null) - { - $contentTypeService = $this->repository->getContentTypeService(); - if (!isset($creatorId)) { - $creatorId = $this->repository->getCurrentUserReference()->getUserId(); - } - - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'new-type' - ); - $typeCreateStruct->names = array( - 'eng-US' => 'American type title', - 'eng-GB' => 'British type title', - ); - $typeCreateStruct->descriptions = array( - 'eng-US' => 'American type description', - 'eng-GB' => 'British type description', - ); - $typeCreateStruct->remoteId = 'new-remoteid'; - $typeCreateStruct->creatorId = $creatorId; - $typeCreateStruct->creationDate = new \DateTime(); - $typeCreateStruct->mainLanguageCode = 'eng-GB'; - $typeCreateStruct->nameSchema = ''; - $typeCreateStruct->urlAliasSchema = '<title>'; - - $titleFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct( - 'title', - 'ezstring' - ); - $titleFieldCreate->names = array( - 'eng-US' => 'American title field name', - 'eng-GB' => 'British title field name', - ); - $titleFieldCreate->descriptions = array( - 'eng-US' => 'American title field description', - 'eng-GB' => 'British title field description', - ); - $titleFieldCreate->fieldGroup = 'blog-content'; - $titleFieldCreate->position = 1; - $titleFieldCreate->isTranslatable = true; - $titleFieldCreate->isRequired = true; - $titleFieldCreate->isInfoCollector = false; - $titleFieldCreate->isSearchable = true; - $titleFieldCreate->defaultValue = 'New text line'; - $titleFieldCreate->validatorConfiguration = array( - 'StringLengthValidator' => array( - 'maxStringLength' => 255, - 'minStringLength' => 128, - ), - ); - //$titleFieldCreate->fieldSettings - $typeCreateStruct->addFieldDefinition($titleFieldCreate); - - $bodyFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct( - 'body', - 'eztext' - ); - $bodyFieldCreate->names = array( - 'eng-US' => 'American body field name', - 'eng-GB' => 'British body field name', - ); - $bodyFieldCreate->descriptions = array( - 'eng-US' => 'American body field description', - 'eng-GB' => 'British body field description', - ); - $bodyFieldCreate->fieldGroup = 'blog-content'; - $bodyFieldCreate->position = 2; - $bodyFieldCreate->isTranslatable = true; - $bodyFieldCreate->isRequired = false; - $bodyFieldCreate->isInfoCollector = false; - $bodyFieldCreate->isSearchable = false; - $bodyFieldCreate->defaultValue = ''; - //$bodyFieldCreate->validatorConfiguration - $bodyFieldCreate->fieldSettings = array( - 'textRows' => 80, - ); - $typeCreateStruct->addFieldDefinition($bodyFieldCreate); - - $groups = $this->createGroups(); - - $type = $contentTypeService->createContentType( - $typeCreateStruct, - $groups - ); - - if ($publish !== true) { - return $type; - } - - $contentTypeService->publishContentTypeDraft($type); - - return $contentTypeService->loadContentType($type->id); - } - - /** - * Creates a ContentTypeDraft with identifier "new-type" and remoteId "new-remoteid". - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft - */ - protected function createDraftContentType() - { - return $this->createContentType(false); - } - - /** - * Creates a ContentType with identifier "new-type" and remoteId "new-remoteid". - * - * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType - */ - protected function createPublishedContentType() - { - return $this->createContentType(true); - } - - /** - * Test for the createContentTypeGroup() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - * - * @return array - */ - public function testCreateContentType() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'new-type' - ); - $typeCreateStruct->names = array( - 'eng-US' => 'American type title', - 'eng-GB' => 'British type title', - ); - $typeCreateStruct->descriptions = array( - 'eng-US' => 'American type description', - 'eng-GB' => 'British type description', - ); - $typeCreateStruct->remoteId = 'new-remoteid'; - $typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $typeCreateStruct->creationDate = new \DateTime(); - $typeCreateStruct->mainLanguageCode = 'eng-GB'; - $typeCreateStruct->nameSchema = '<name>'; - $typeCreateStruct->urlAliasSchema = '<name>'; - - $titleFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct( - 'title', - 'ezstring' - ); - $titleFieldCreate->names = array( - 'eng-US' => 'American title field name', - 'eng-GB' => 'British title field name', - ); - $titleFieldCreate->descriptions = array( - 'eng-US' => 'American title field description', - 'eng-GB' => 'British title field description', - ); - $titleFieldCreate->fieldGroup = 'blog-content'; - $titleFieldCreate->position = 1; - $titleFieldCreate->isTranslatable = true; - $titleFieldCreate->isRequired = true; - $titleFieldCreate->isInfoCollector = false; - $titleFieldCreate->isSearchable = true; - $titleFieldCreate->defaultValue = 'New text line'; - $titleFieldCreate->validatorConfiguration = array( - 'StringLengthValidator' => array( - 'maxStringLength' => 128, - ), - ); - //$titleFieldCreate->fieldSettings - $typeCreateStruct->addFieldDefinition($titleFieldCreate); - - $bodyFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct( - 'body', - 'eztext' - ); - $bodyFieldCreate->names = array( - 'eng-US' => 'American body field name', - 'eng-GB' => 'British body field name', - ); - $bodyFieldCreate->descriptions = array( - 'eng-US' => 'American body field description', - 'eng-GB' => 'British body field description', - ); - $bodyFieldCreate->fieldGroup = 'blog-content'; - $bodyFieldCreate->position = 2; - $bodyFieldCreate->isTranslatable = true; - $bodyFieldCreate->isRequired = false; - $bodyFieldCreate->isInfoCollector = false; - $bodyFieldCreate->isSearchable = false; - $bodyFieldCreate->defaultValue = ''; - //$bodyFieldCreate->validatorConfiguration - $bodyFieldCreate->fieldSettings = array( - 'textRows' => 20, - ); - $typeCreateStruct->addFieldDefinition($bodyFieldCreate); - - $groups = $this->createGroups(); - - $type = $contentTypeService->createContentType( - $typeCreateStruct, - $groups - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $type - ); - - return array( - 'expected' => $typeCreateStruct, - 'actual' => $type, - 'groups' => $groups, - ); - } - - /** - * Test for the newContentTypeGroupCreateStruct() method. - * - * @depends testCreateContentType - * @covers \eZ\Publish\Core\Repository\ContentTypeService::newContentTypeGroupCreateStruct - * - * @param array $data - */ - public function testCreateContentTypeStructValues(array $data) - { - /** @var $typeCreate \eZ\Publish\API\Repository\Values\ContentType\ContentTypeCreateStruct */ - $typeCreate = $data['expected']; - /** @var $contentType \eZ\Publish\Core\Repository\Values\ContentType\ContentType */ - $contentType = $data['actual']; - /** @var $groups \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] */ - $groups = $data['groups']; - - foreach ($typeCreate as $propertyName => $propertyValue) { - switch ($propertyName) { - case 'fieldDefinitions': - $this->assertCreatedFieldDefinitionsCorrect( - $typeCreate->fieldDefinitions, - $contentType->fieldDefinitions - ); - break; - - case 'contentTypeGroups': - $this->assertContentTypeGroupsCorrect( - $groups, - $contentType->contentTypeGroups - ); - break; - - case 'creationDate': - case 'modificationDate': - $this->assertEquals( - $typeCreate->$propertyName->getTimestamp(), - $contentType->$propertyName->getTimestamp() - ); - break; - - default: - $this->assertEquals( - $typeCreate->$propertyName, - $contentType->$propertyName, - "Did not assert that property '${propertyName}' is equal on struct and resulting value object" - ); - break; - } - } - - $this->assertContentTypeGroupsCorrect( - $groups, - $contentType->contentTypeGroups - ); - - $this->assertNotNull( - $contentType->id - ); - } - - /** - * Asserts field definition creation. - * - * Asserts that all field definitions defined through created structs in - * $expectedDefinitionCreates have been correctly created in - * $actualDefinitions. - * - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct[] $expectedDefinitionCreates - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $actualDefinitions - */ - protected function assertCreatedFieldDefinitionsCorrect(array $expectedDefinitionCreates, array $actualDefinitions) - { - $this->assertEquals( - count($expectedDefinitionCreates), - count($actualDefinitions), - 'Count of field definition creates did not match count of field definitions.' - ); - - $sorter = function ($a, $b) { - return strcmp($a->identifier, $b->identifier); - }; - - usort($expectedDefinitionCreates, $sorter); - usort($actualDefinitions, $sorter); - - foreach ($expectedDefinitionCreates as $key => $expectedCreate) { - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinition', - $actualDefinitions[$key] - ); - $this->assertCreatedFieldDefinitionCorrect( - $expectedCreate, - $actualDefinitions[$key] - ); - } - } - - /** - * Asserts that a field definition has been correctly created. - * - * Asserts that the given $fieldDefinition is correctly created from the - * create struct in $fieldDefinitionCreateStruct. - * - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition - */ - protected function assertCreatedFieldDefinitionCorrect($fieldDefinitionCreateStruct, $fieldDefinition) - { - foreach ($fieldDefinitionCreateStruct as $propertyName => $propertyValue) { - switch ($propertyName) { - case 'fieldSettings': - $defaultSettings = $this->repository->getFieldTypeService()->getFieldType( - $fieldDefinitionCreateStruct->fieldTypeIdentifier - )->getSettingsSchema(); - $fieldDefinitionPropertyValue = (array)$fieldDefinition->$propertyName + $defaultSettings; - $propertyValue = (array)$propertyValue + $defaultSettings; - ksort($fieldDefinitionPropertyValue); - ksort($propertyValue); - break; - case 'validatorConfiguration': - $fieldDefinitionPropertyValue = (array)$fieldDefinition->$propertyName; - $propertyValue = (array)$propertyValue; - $sorter = function ($a, $b) { - if ($a->identifier == $b->identifier) { - return 0; - } - - return ($a->identifier < $b->identifier) ? -1 : 1; - }; - usort($fieldDefinitionPropertyValue, $sorter); - usort($propertyValue, $sorter); - break; - default: - $fieldDefinitionPropertyValue = $fieldDefinition->$propertyName; - } - - $this->assertEquals( - $propertyValue, - $fieldDefinitionPropertyValue, - "Field definition property '{$propertyName}' is not correctly created" - ); - } - } - - /** - * Asserts that two sets of ContentTypeGroups are equal. - * - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $expectedGroups - * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $actualGroups - */ - protected function assertContentTypeGroupsCorrect(array $expectedGroups, array $actualGroups) - { - $sorter = function ($a, $b) { - if ($a->id == $b->id) { - return 0; - } - - return ($a->id < $b->id) ? -1 : 1; - }; - - usort($expectedGroups, $sorter); - usort($actualGroups, $sorter); - - foreach ($expectedGroups as $index => $expectedGroup) { - $this->assertContentTypeGroupsEqual( - array( - 'expected' => $expectedGroup, - 'actual' => $actualGroups[$index], - ) - ); - } - } - - /** - * Test for the createContentTypeGroup() method. - * - * @depends testCreateContentType - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - */ - public function testCreateContentTypeThrowsInvalidArgumentExceptionGroupsEmpty() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'new-type' - ); - - // Thrown an exception because array of content type groups is empty - $type = $contentTypeService->createContentType($typeCreateStruct, array()); - /* END: Use Case */ - } - - /** - * Test for the createContentTypeGroup() method. - * - * @depends testCreateContentType - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @expectedExceptionMessage Another ContentType with identifier 'new-type' exists - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - */ - public function testCreateContentTypeThrowsInvalidArgumentExceptionContentTypeExistsWithIdentifier() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - // Creates published content type with identifier "new-type" - $this->createPublishedContentType(); - - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'new-type' - ); - $typeCreateStruct->remoteId = 'other-remoteid'; - $typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $typeCreateStruct->creationDate = new \DateTime(); - $typeCreateStruct->mainLanguageCode = 'eng-US'; - $typeCreateStruct->names = array('eng-US' => 'A name.'); - $typeCreateStruct->descriptions = array('eng-US' => 'A description.'); - - $fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test', 'eztext'); - $typeCreateStruct->addFieldDefinition($fieldCreate); - - // Throws an exception because content type with identifier "new-type" already exists - $type = $contentTypeService->createContentType( - $typeCreateStruct, - array( - // "Content" group - $contentTypeService->loadContentTypeGroup(1), - ) - ); - /* END: Use Case */ - } - - /** - * Test for the createContentTypeGroup() method. - * - * @depends testCreateContentType - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @expectedExceptionMessage Another ContentType with remoteId 'new-remoteid' exists - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - */ - public function testCreateContentTypeThrowsInvalidArgumentExceptionContentTypeExistsWithRemoteId() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - // Creates published content type with remoteId "new-remoteid" - $this->createPublishedContentType(); - - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'other-type' - ); - $typeCreateStruct->remoteId = 'new-remoteid'; - $typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $typeCreateStruct->creationDate = new \DateTime(); - $typeCreateStruct->mainLanguageCode = 'eng-US'; - $typeCreateStruct->names = array('eng-US' => 'A name.'); - $typeCreateStruct->descriptions = array('eng-US' => 'A description.'); - - $fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test', 'eztext'); - $typeCreateStruct->addFieldDefinition($fieldCreate); - - // Throws an exception because content type with remoteId "new-remoteid" already exists - $type = $contentTypeService->createContentType( - $typeCreateStruct, - array( - // "Content" group - $contentTypeService->loadContentTypeGroup(1), - ) - ); - /* END: Use Case */ - } - - /** - * Test for the createContentTypeGroup() method. - * - * @depends testCreateContentType - * - * @return array - */ - public function testCreateContentTypeWithoutFieldDefinitions() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - // Creates published content type with remoteId "new-remoteid" - $this->createPublishedContentType(); - - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'other-type' - ); - $typeCreateStruct->remoteId = 'new-unique-remoteid'; - $typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $typeCreateStruct->creationDate = new \DateTime(); - $typeCreateStruct->mainLanguageCode = 'eng-US'; - $typeCreateStruct->names = array('eng-US' => 'A name.'); - $typeCreateStruct->descriptions = array('eng-US' => 'A description.'); - - // Throws an exception because content type create struct does not have any field definition create structs set - self::assertInstanceOf( - 'eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft', - $contentTypeService->createContentType( - $typeCreateStruct, - array( - // "Content" group - $contentTypeService->loadContentTypeGroup(1), - ) - ) - ); - /* END: Use Case */ - } - - /** - * Test for the createContentTypeGroup() method. - * - * @depends testCreateContentType - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @expectedExceptionMessage Argument contains duplicate field definition identifier 'title' - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeGroup - * - * @return array - */ - public function testCreateContentTypeThrowsInvalidArgumentExceptionDuplicateFieldDefinitionIdentifier() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'new-type' - ); - $typeCreateStruct->names = array( - 'eng-US' => 'American type title', - 'eng-GB' => 'British type title', - ); - $typeCreateStruct->descriptions = array( - 'eng-US' => 'American type description', - 'eng-GB' => 'British type description', - ); - $typeCreateStruct->remoteId = 'new-remoteid'; - $typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $typeCreateStruct->creationDate = new \DateTime(); - $typeCreateStruct->mainLanguageCode = 'eng-GB'; - $typeCreateStruct->nameSchema = '<name>'; - $typeCreateStruct->urlAliasSchema = '<name>'; - - $titleFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct( - 'title', - 'ezstring' - ); - $titleFieldCreate->names = array( - 'eng-US' => 'American title field name', - 'eng-GB' => 'British title field name', - ); - $titleFieldCreate->descriptions = array( - 'eng-US' => 'American title field description', - 'eng-GB' => 'British title field description', - ); - $titleFieldCreate->fieldGroup = 'blog-content'; - $titleFieldCreate->position = 1; - $titleFieldCreate->isTranslatable = true; - $titleFieldCreate->isRequired = true; - $titleFieldCreate->isInfoCollector = false; - $titleFieldCreate->isSearchable = true; - $titleFieldCreate->defaultValue = 'New text line'; - $titleFieldCreate->validatorConfiguration = array( - 'StringLengthValidator' => array( - 'maxStringLength' => 128, - ), - ); - //$titleFieldCreate->fieldSettings - - $typeCreateStruct->addFieldDefinition($titleFieldCreate); - $typeCreateStruct->addFieldDefinition(clone $titleFieldCreate); - - $groups = $this->createGroups(); - - // Throws an exception because two field definition create structs have the same identifier - $type = $contentTypeService->createContentType( - $typeCreateStruct, - $groups - ); - /* END: Use Case */ - } - - /** - * Test for the loadContentType() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentType - * - * @return array - */ - public function testLoadContentType() - { - $storedContentType = $this->createPublishedContentType(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentType = $contentTypeService->loadContentType( - $storedContentType->id - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType', - $loadedContentType - ); - - $this->assertNotInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $loadedContentType - ); - - return array( - 'expected' => $storedContentType, - 'actual' => $loadedContentType, - ); - } - - /** - * Test for the loadContentType() method. - * - * @depends testLoadContentType - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentType - * - * @param array $data - */ - public function testLoadContentTypeValues(array $data) - { - $this->compareContentTypes($data); - } - - /** - * Compares two given ContentType objects. - * - * @param array $data - * @param array $properties - * @param array $fieldProperties - */ - protected function compareContentTypes(array $data, array $properties = array(), array $fieldProperties = array()) - { - /** @var $storedContentType \eZ\Publish\Core\Repository\Values\ContentType\ContentType */ - $storedContentType = $data['expected']; - /** @var $loadedContentType \eZ\Publish\Core\Repository\Values\ContentType\ContentType */ - $loadedContentType = $data['actual']; - - $propertiesNames = array( - // Virtual properties - 'names', - 'descriptions', - 'contentTypeGroups', - //"fieldDefinitions", - // Standard properties - 'id', - 'status', - 'identifier', - 'creationDate', - 'modificationDate', - 'creatorId', - 'modifierId', - 'remoteId', - 'urlAliasSchema', - 'nameSchema', - 'isContainer', - 'mainLanguageCode', - 'defaultAlwaysAvailable', - 'defaultSortField', - 'defaultSortOrder', - ); - - $this->assertSameClassPropertiesCorrect( - array_diff( - $propertiesNames, - isset($properties['notEqual']) ? $properties['notEqual'] : array() - ), - $storedContentType, - $loadedContentType, - isset($properties['skip']) ? $properties['skip'] : array() - ); - - $this->assertSameClassPropertiesCorrect( - isset($properties['notEqual']) ? $properties['notEqual'] : array(), - $storedContentType, - $loadedContentType, - isset($properties['skip']) ? $properties['skip'] : array(), - false - ); - - $this->assertEquals( - count($storedContentType->fieldDefinitions), - count($loadedContentType->fieldDefinitions), - 'Field count in stored and loaded content type groups does not match' - ); - - foreach ($storedContentType->fieldDefinitions as $index => $expectedFieldDefinition) { - $actualFieldDefinition = $loadedContentType->fieldDefinitions[$index]; - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinition', - $actualFieldDefinition - ); - $this->compareFieldDefinitions( - $expectedFieldDefinition, - $actualFieldDefinition, - $fieldProperties - ); - } - } - - /** - * Compares two FieldDefinition objects. - * - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $expectedFieldDefinition - * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $actualFieldDefinition - * @param array $properties Array of field names to skip or compare as not equal - */ - protected function compareFieldDefinitions($expectedFieldDefinition, $actualFieldDefinition, $properties = array()) - { - $propertiesNames = array( - 'names', - 'descriptions', - 'fieldSettings', - 'validatorConfiguration', - 'id', - 'identifier', - 'fieldGroup', - 'position', - 'fieldTypeIdentifier', - 'isTranslatable', - 'isRequired', - 'isInfoCollector', - // Do not compare defaultValue as they may have different representations - //"defaultValue", - 'isSearchable', - ); - - $this->assertSameClassPropertiesCorrect( - array_diff( - $propertiesNames, - isset($properties['notEqual']) ? $properties['notEqual'] : array() - ), - $expectedFieldDefinition, - $actualFieldDefinition, - isset($properties['skip']) ? $properties['skip'] : array() - ); - - $this->assertSameClassPropertiesCorrect( - isset($properties['notEqual']) ? $properties['notEqual'] : array(), - $expectedFieldDefinition, - $actualFieldDefinition, - isset($properties['skip']) ? $properties['skip'] : array(), - false - ); - } - - /** - * Test for the loadContentType() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentType - */ - public function testLoadContentTypeThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentType = $contentTypeService->loadContentType( - APIBaseTest::DB_INT_MAX - ); - /* END: Use Case */ - } - - /** - * Test for the loadContentTypeByIdentifier() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeByIdentifier - * - * @return array - */ - public function testLoadContentTypeByIdentifier() - { - $storedContentType = $this->createPublishedContentType(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentType = $contentTypeService->loadContentTypeByIdentifier( - $storedContentType->identifier - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType', - $loadedContentType - ); - - return array( - 'expected' => $storedContentType, - 'actual' => $loadedContentType, - ); - } - - /** - * Test for the loadContentTypeByIdentifier() method. - * - * @depends testLoadContentTypeByIdentifier - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeByIdentifier - * - * @param array $data - */ - public function testLoadContentTypeByIdentifierValues(array $data) - { - $this->compareContentTypes($data); - } - - /** - * Test for the loadContentTypeByIdentifier() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeByIdentifier - */ - public function testLoadContentTypeByIdentifierThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentType = $contentTypeService->loadContentTypeByIdentifier( - 'non-existing-identifier' - ); - /* END: Use Case */ - } - - /** - * Test for the loadContentTypeByRemoteId() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeByRemoteId - * - * @return array - */ - public function testLoadContentTypeByRemoteId() - { - $storedContentType = $this->createPublishedContentType(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentType = $contentTypeService->loadContentTypeByRemoteId( - $storedContentType->remoteId - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType', - $loadedContentType - ); - - return array( - 'expected' => $storedContentType, - 'actual' => $loadedContentType, - ); - } - - /** - * Test for the loadContentTypeByRemoteId() method. - * - * @depends testLoadContentTypeByRemoteId - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeByRemoteId - * - * @param array $data - */ - public function testLoadContentTypeByRemoteIdValues(array $data) - { - $this->compareContentTypes($data); - } - - /** - * Test for the loadContentTypeByRemoteId() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeByRemoteId - */ - public function testLoadContentTypeByRemoteIdThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentType = $contentTypeService->loadContentTypeByRemoteId( - 'non-existing-remoteid' - ); - /* END: Use Case */ - } - - /** - * Test for the loadContentTypeDraft() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeDraft - * - * @return array - */ - public function testLoadContentTypeDraft() - { - $storedContentTypeDraft = $this->createDraftContentType(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentTypeDraft = $contentTypeService->loadContentTypeDraft( - $storedContentTypeDraft->id - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $loadedContentTypeDraft - ); - - return array( - 'expected' => $storedContentTypeDraft, - 'actual' => $loadedContentTypeDraft, - ); - } - - /** - * Test for the loadContentTypeDraft() method. - * - * @depends testLoadContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeDraft - * - * @param array $data - * - * @return array - */ - public function testLoadContentTypeDraftValues(array $data) - { - $this->compareContentTypes($data); - } - - /** - * Test for the loadContentTypeDraft() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypeDraft - * - * @return array - */ - public function testLoadContentTypeDraftThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $loadedContentType = $contentTypeService->loadContentTypeDraft( - APIBaseTest::DB_INT_MAX - ); - /* END: Use Case */ - } - - /** - * Test for the publishContentTypeDraft() method. - * - * @depends testCreateContentType - * @depends testLoadContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::publishContentTypeDraft - */ - public function testPublishContentTypeDraft() - { - $contentTypeDraft = $this->createDraftContentType(); - $draftId = $contentTypeDraft->id; - - /* BEGIN: Use Case */ - // $contentTypeDraft contains a ContentTypeDraft - $contentTypeService = $this->repository->getContentTypeService(); - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - - $contentTypeService->publishContentTypeDraft($contentTypeDraft); - /* END: Use Case */ - - $publishedType = $contentTypeService->loadContentType($draftId); - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType', - $publishedType - ); - $this->assertNotInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $publishedType - ); - } - - /** - * Test for the publishContentTypeDraft() method. - * - * @depends testPublishContentTypeDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::publishContentTypeDraft - */ - public function testPublishContentTypeDraftThrowsBadStateException() - { - $contentTypeDraft = $this->createDraftContentType(); - $draftId = $contentTypeDraft->id; - - /* BEGIN: Use Case */ - // $contentTypeDraft contains a ContentTypeDraft - $contentTypeService = $this->repository->getContentTypeService(); - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - - $contentTypeService->publishContentTypeDraft($contentTypeDraft); - - // Throws exception, since no draft exists anymore - $contentTypeService->publishContentTypeDraft($contentTypeDraft); - /* END: Use Case */ - } - - /** - * Test for the publishContentTypeDraft() method. - * - * @depends testPublishContentTypeDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::publishContentTypeDraft - */ - public function testPublishContentTypeDraftThrowsInvalidArgumentException() - { - $contentTypeService = $this->repository->getContentTypeService(); - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct('new-type'); - $typeCreateStruct->names = array('eng-GB' => 'Type title'); - $typeCreateStruct->mainLanguageCode = 'eng-GB'; - $type = $contentTypeService->createContentType( - $typeCreateStruct, - $this->createGroups() - ); - - // Throws an exception because type has no field definitions - $contentTypeService->publishContentTypeDraft($type); - } - - /** - * Test for the publishContentTypeDraft() method. - * - * @depends testPublishContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::publishContentTypeDraft - */ - public function testPublishContentTypeDraftSetsNameSchema() - { - $contentTypeService = $this->repository->getContentTypeService(); - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'new-type' - ); - $typeCreateStruct->names = array( - 'eng-GB' => 'Type title', - ); - $typeCreateStruct->mainLanguageCode = 'eng-GB'; - - $titleFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('title', 'ezstring'); - $titleFieldCreate->position = 1; - $typeCreateStruct->addFieldDefinition($titleFieldCreate); - - $type = $contentTypeService->createContentType( - $typeCreateStruct, - $this->createGroups() - ); - - $contentTypeService->publishContentTypeDraft($type); - - $loadedContentType = $contentTypeService->loadContentType($type->id); - - $this->assertEquals('<title>', $loadedContentType->nameSchema); - } - - /** - * Test for the publishContentTypeDraft() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::publishContentTypeDraft - */ - public function testPublishContentTypeDraftThrowsUnauthorizedException() - { - $contentTypeDraft = $this->createDraftContentType(); - $draftId = $contentTypeDraft->id; - - $contentTypeService = $this->repository->getContentTypeService(); - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->publishContentTypeDraft($contentTypeDraft); - } - - /** - * Test for the loadContentTypes() method. - * - * @depends testNewContentTypeGroupCreateStruct - * @depends testNewContentTypeCreateStruct - * @depends testNewFieldDefinitionCreateStruct - * @depends testCreateContentTypeGroup - * @depends testCreateContentType - * @depends testPublishContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypes - * - * @todo when all fieldTypes are functional revisit this and simplify by testing against fixtures - * - * @return array - */ - public function testLoadContentTypes() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct( - 'test-group-1' - ); - $groupCreate->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $groupCreate->creationDate = new \DateTime(); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - //$groupCreate->mainLanguageCode = 'ger-DE'; - //$groupCreate->names = array( 'eng-US' => 'A name.' ); - //$groupCreate->descriptions = array( 'eng-US' => 'A description.' ); - $group = $contentTypeService->createContentTypeGroup($groupCreate); - - $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( - 'test-type-1' - ); - $typeCreateStruct->names = array( - 'eng-US' => 'American type title', - 'eng-GB' => 'British type title', - ); - $typeCreateStruct->descriptions = array( - 'eng-US' => 'American type description', - 'eng-GB' => 'British type description', - ); - $typeCreateStruct->remoteId = 'test-remoteid-1'; - $typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); - $typeCreateStruct->creationDate = new \DateTime(); - $typeCreateStruct->mainLanguageCode = 'eng-GB'; - $typeCreateStruct->nameSchema = '<name>'; - $typeCreateStruct->urlAliasSchema = '<name>'; - - $titleFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct( - 'title', - 'ezstring' - ); - $titleFieldCreate->names = array( - 'eng-US' => 'American title field name', - 'eng-GB' => 'British title field name', - ); - $titleFieldCreate->descriptions = array( - 'eng-US' => 'American title field description', - 'eng-GB' => 'British title field description', - ); - $titleFieldCreate->fieldGroup = 'blog-content'; - $titleFieldCreate->position = 1; - $titleFieldCreate->isTranslatable = true; - $titleFieldCreate->isRequired = true; - $titleFieldCreate->isInfoCollector = false; - $titleFieldCreate->isSearchable = true; - $titleFieldCreate->defaultValue = 'New text line'; - //$titleFieldCreate->validators - //$titleFieldCreate->fieldSettings - $typeCreateStruct->addFieldDefinition($titleFieldCreate); - - $type1 = $contentTypeService->createContentType( - $typeCreateStruct, - array($group) - ); - $contentTypeService->publishContentTypeDraft($type1); - - $typeCreateStruct->identifier = 'test-type-2'; - $typeCreateStruct->remoteId = 'test-remoteid-2'; - $type2 = $contentTypeService->createContentType( - $typeCreateStruct, - array($group) - ); - $contentTypeService->publishContentTypeDraft($type2); - - /* BEGIN: Use Case */ - $loadedTypes = $contentTypeService->loadContentTypes($group); - /* END: Use Case */ - - $this->assertInternalType( - 'array', - $loadedTypes - ); - - return $loadedTypes; - } - - /** - * Test for the loadContentTypeGroups() method. - * - * @depends testLoadContentTypes - * @covers \eZ\Publish\Core\Repository\ContentTypeService::loadContentTypes - * - * @param array $types - */ - public function testLoadContentTypesIdentifiers(array $types) - { - $expectedIdentifiers = array('test-type-1' => true, 'test-type-2' => true); - - $this->assertEquals(count($expectedIdentifiers), count($types)); - - $actualIdentifiers = array('test-type-1' => false, 'test-type-2' => false); - - foreach ($types as $type) { - $actualIdentifiers[$type->identifier] = true; - } - - $this->assertEquals( - $expectedIdentifiers, - $actualIdentifiers, - 'Identifier mismatch in loaded types.' - ); - } - - /** - * Test for the createContentTypeDraft() method. - * - * @depends testCreateContentType - * @depends testPublishContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeDraft - * - * @return array - */ - public function testCreateContentTypeDraft() - { - $publishedType = $this->createPublishedContentType(); - - /* BEGIN: Use case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $draftType = $contentTypeService->createContentTypeDraft($publishedType); - /* END: Use case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $draftType - ); - - return array( - 'expected' => $publishedType, - 'actual' => $draftType, - ); - } - - /** - * Test for the createContentTypeDraft() method. - * - * @depends testCreateContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeDraft - * - * @param array $data - */ - public function testCreateContentTypeDraftValues(array $data) - { - /** @var $publishedType \eZ\Publish\Core\Repository\Values\ContentType\ContentType */ - $publishedType = $data['expected']; - /** @var $draftType \eZ\Publish\Core\Repository\Values\ContentType\ContentTypeDraft */ - $draftType = $data['actual']; - - $typeProperties = array( - 'skip' => array( - 'id', - 'status', - 'modificationDate', - ), - ); - $this->compareContentTypes( - $data, - $typeProperties - ); - - $this->assertEquals( - $publishedType->id, - $draftType->id - ); - - $this->assertEquals( - $draftType->status, - ContentType::STATUS_DRAFT - ); - } - - /** - * Test for the createContentTypeDraft() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeDraft - */ - public function testCreateContentTypeDraftThrowsUnauthorizedException() - { - $publishedType = $this->createPublishedContentType(); - - $contentTypeService = $this->repository->getContentTypeService(); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->createContentTypeDraft($publishedType); - } - - /** - * Test for the createContentTypeDraft() method. - * - * @depends testCreateContentTypeDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::createContentTypeDraft - */ - public function testCreateContentTypeDraftThrowsBadStateException() - { - $publishedType = $this->createPublishedContentType(); - // Create draft for current user - $this->repository->getContentTypeService()->createContentTypeDraft($publishedType); - - /* BEGIN: Use case */ - // $publishedType contains a ContentType object - $contentTypeService = $this->repository->getContentTypeService(); - - // Throws an exception because ContentType has an existing draft belonging to another user - $draft = $contentTypeService->createContentTypeDraft($publishedType); - /* END: Use case */ - } - - /** - * Test for the updateContentTypeDraft() method. - * - * @depends testCreateContentType - * @depends testLoadContentTypeDraft - * @depends testNewContentTypeUpdateStruct - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeDraft - * - * @return array - */ - public function testUpdateContentTypeDraft() - { - $contentTypeDraft = $this->createDraftContentType(); - - /* BEGIN: Use Case */ - // $contentTypeDraft contains a ContentTypeDraft - - $contentTypeService = $this->repository->getContentTypeService(); - - $typeUpdate = $contentTypeService->newContentTypeUpdateStruct(); - $typeUpdate->identifier = 'news-article'; - $typeUpdate->remoteId = '4cf35f5166fd31bf0cda859dc837e095daee9833'; - $typeUpdate->urlAliasSchema = 'url@alias|scheme'; - $typeUpdate->nameSchema = '@name@scheme@'; - $typeUpdate->isContainer = true; - $typeUpdate->mainLanguageCode = 'eng-US'; - $typeUpdate->defaultAlwaysAvailable = false; - $typeUpdate->modifierId = $this->repository->getCurrentUserReference()->getUserId(); - $typeUpdate->modificationDate = new \DateTime(); - $typeUpdate->defaultSortField = Location::SORT_FIELD_PUBLISHED; - $typeUpdate->defaultSortOrder = Location::SORT_ORDER_ASC; - $typeUpdate->names = array( - 'eng-US' => 'News article', - 'eng-GB' => 'Nachrichten-Artikel', - ); - $typeUpdate->descriptions = array( - 'eng-US' => 'A news article', - 'eng-GB' => 'Ein Nachrichten-Artikel', - ); - - $contentTypeService->updateContentTypeDraft($contentTypeDraft, $typeUpdate); - /* END: Use Case */ - - $updatedType = $contentTypeService->loadContentTypeDraft( - $contentTypeDraft->id - ); - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $updatedType - ); - - return array( - 'originalType' => $contentTypeDraft, - 'updateStruct' => $typeUpdate, - 'updatedType' => $updatedType, - ); - } - - /** - * Test for the updateContentTypeDraft() method. - * - * @depends testUpdateContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeDraft - * - * @param array $data - */ - public function testUpdateContentTypeDraftStructValues(array $data) - { - $originalType = $data['originalType']; - $updateStruct = $data['updateStruct']; - $updatedType = $data['updatedType']; - - $this->assertPropertiesCorrect( - array( - 'id' => $originalType->id, - 'names' => $updateStruct->names, - 'descriptions' => $updateStruct->descriptions, - 'identifier' => $updateStruct->identifier, - 'creationDate' => $originalType->creationDate, - 'modificationDate' => $updateStruct->modificationDate, - 'creatorId' => $originalType->creatorId, - 'modifierId' => $updateStruct->modifierId, - 'urlAliasSchema' => $updateStruct->urlAliasSchema, - 'nameSchema' => $updateStruct->nameSchema, - 'isContainer' => $updateStruct->isContainer, - 'mainLanguageCode' => $updateStruct->mainLanguageCode, - 'contentTypeGroups' => $originalType->contentTypeGroups, - //'fieldDefinitions' => $originalType->fieldDefinitions, - ), - $updatedType - ); - - $this->assertEquals( - count($originalType->fieldDefinitions), - count($updatedType->fieldDefinitions), - 'Field count in stored and loaded content type groups does not match' - ); - - foreach ($originalType->fieldDefinitions as $index => $expectedFieldDefinition) { - $actualFieldDefinition = $updatedType->fieldDefinitions[$index]; - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinition', - $actualFieldDefinition - ); - $this->compareFieldDefinitions( - $expectedFieldDefinition, - $actualFieldDefinition - ); - } - } - - /** - * Test for the updateContentTypeDraft() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeDraft - */ - public function testUpdateContentTypeDraftThrowsUnauthorizedException() - { - $contentTypeDraft = $this->createDraftContentType(); - $contentTypeService = $this->repository->getContentTypeService(); - - $typeUpdate = $contentTypeService->newContentTypeUpdateStruct(); - $typeUpdate->identifier = 'news-article'; - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->updateContentTypeDraft($contentTypeDraft, $typeUpdate); - } - - /** - * Test for the updateContentTypeDraft() method. - * - * @depends testUpdateContentTypeDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeDraft - */ - public function testUpdateContentTypeDraftThrowsInvalidArgumentExceptionDuplicateIdentifier() - { - $contentTypeDraft = $this->createDraftContentType(); - - /* BEGIN: Use Case */ - // $contentTypeDraft contains a ContentTypeDraft with identifier 'blog-post' - - $contentTypeService = $this->repository->getContentTypeService(); - - $typeUpdate = $contentTypeService->newContentTypeUpdateStruct(); - $typeUpdate->identifier = 'folder'; - - // Throws exception, since type "folder" already exists - $contentTypeService->updateContentTypeDraft($contentTypeDraft, $typeUpdate); - /* END: Use Case */ - } - - /** - * Test for the updateContentTypeDraft() method. - * - * @depends testUpdateContentTypeDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeDraft - */ - public function testUpdateContentTypeDraftThrowsInvalidArgumentExceptionDuplicateRemoteId() - { - $contentTypeDraft = $this->createDraftContentType(); - - /* BEGIN: Use Case */ - // $contentTypeDraft contains a ContentTypeDraft with identifier 'blog-post' - - $contentTypeService = $this->repository->getContentTypeService(); - - $typeUpdate = $contentTypeService->newContentTypeUpdateStruct(); - $typeUpdate->remoteId = 'a3d405b81be900468eb153d774f4f0d2'; - - // Throws exception, since remote ID of type "folder" is used - $contentTypeService->updateContentTypeDraft($contentTypeDraft, $typeUpdate); - /* END: Use Case */ - } - - /** - * Test for the updateContentTypeDraft() method. - * - * @depends testUpdateContentTypeDraft - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateContentTypeDraft - */ - public function testUpdateContentTypeDraftThrowsInvalidArgumentExceptionNoDraftForAuthenticatedUser() - { - $contentTypeDraft = $this->createContentType(false, $this->getStubbedUser(10)->id); - - /* BEGIN: Use Case */ - // $contentTypeDraft contains a ContentTypeDraft with identifier 'blog-post', belonging to the user with id=28 - - $contentTypeService = $this->repository->getContentTypeService(); - - $typeUpdate = $contentTypeService->newContentTypeUpdateStruct(); - - // Throws exception, since draft belongs to another user - $contentTypeService->updateContentTypeDraft($contentTypeDraft, $typeUpdate); - /* END: Use Case */ - } - - /** - * Test for the deleteContentType() method. - * - * @depends testLoadContentTypeByIdentifier - * @depends testLoadContentType - * @covers \eZ\Publish\Core\Repository\ContentTypeService::deleteContentType - */ - public function testDeleteContentType() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $commentType = $contentTypeService->loadContentTypeByIdentifier('comment'); - - $contentTypeService->deleteContentType($commentType); - /* END: Use Case */ - - try { - $contentTypeService->loadContentType($commentType->id); - $this->fail('Content type could be loaded after delete.'); - } catch (NotFoundException $e) { - // All fine - } - } - - /** - * Test for the deleteContentType() method. - * - * @depends testDeleteContentType - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::deleteContentType - */ - public function testDeleteContentTypeThrowsBadStateException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $commentType = $contentTypeService->loadContentTypeByIdentifier('folder'); - - // Throws an exception because folder type still has content instances - $contentTypeService->deleteContentType($commentType); - /* END: Use Case */ - } - - /** - * Test for the deleteContentType() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::deleteContentType - */ - public function testDeleteContentTypeThrowsUnauthorizedException() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $commentType = $contentTypeService->loadContentTypeByIdentifier('comment'); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->deleteContentType($commentType); - } - - /** - * Test for the copyContentType() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::copyContentType - * - * @return array - */ - public function testCopyContentType() - { - $time = time(); - - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $commentType = $contentTypeService->loadContentTypeByIdentifier('comment'); - - $copiedCommentType = $contentTypeService->copyContentType($commentType); - /* END: Use Case */ - - return array( - 'originalType' => $commentType, - 'copiedType' => $copiedCommentType, - 'time' => $time, - 'userId' => $this->repository->getCurrentUserReference()->getUserId(), - ); - } - - /** - * Test for the copyContentType() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::copyContentType - * - * @return array - */ - public function testCopyContentTypeWithSecondArgument() - { - $time = time(); - - /* BEGIN: Use Case */ - $user = $this->getStubbedUser(14); - $this->repository->setCurrentUser($user); - $contentTypeService = $this->repository->getContentTypeService(); - - $commentType = $contentTypeService->loadContentTypeByIdentifier('comment'); - - $copiedCommentType = $contentTypeService->copyContentType($commentType, $user); - /* END: Use Case */ - - return array( - 'originalType' => $commentType, - 'copiedType' => $copiedCommentType, - 'time' => $time, - 'userId' => $user->id, - ); - } - - /** - * Asserts that copied content type is valid copy of original content type. - * - * @param array $data - */ - protected function assertCopyContentTypeValues(array $data) - { - /** @var $originalType \eZ\Publish\Core\Repository\Values\ContentType\ContentType */ - $originalType = $data['originalType']; - /** @var $copiedType \eZ\Publish\Core\Repository\Values\ContentType\ContentType */ - $copiedType = $data['copiedType']; - $userId = $data['userId']; - $time = $data['time']; - - $this->compareContentTypes( - array( - 'expected' => $originalType, - 'actual' => $copiedType, - ), - array( - 'notEqual' => array( - 'id', - 'identifier', - 'creationDate', - 'modificationDate', - 'remoteId', - ), - 'skip' => array( - 'creatorId', - 'modifierId', - 'status', - ), - ), - array( - 'notEqual' => array( - 'id', - ), - ) - ); - - $this->assertGreaterThanOrEqual($time, $copiedType->creationDate->getTimestamp()); - $this->assertGreaterThanOrEqual($time, $copiedType->modificationDate->getTimestamp()); - $this->assertEquals($userId, $copiedType->creatorId); - $this->assertEquals($userId, $copiedType->modifierId); - $this->assertEquals(ContentType::STATUS_DEFINED, $copiedType->status); - } - - /** - * Test for the copyContentType() method. - * - * @depends testCopyContentType - * @covers \eZ\Publish\Core\Repository\ContentTypeService::copyContentType - * - * @param array $data - */ - public function testCopyContentTypeValues(array $data) - { - $this->assertCopyContentTypeValues($data); - } - - /** - * Test for the copyContentType() method. - * - * @depends testCopyContentTypeWithSecondArgument - * @covers \eZ\Publish\Core\Repository\ContentTypeService::copyContentType - * - * @param array $data - */ - public function testCopyContentTypeWithSecondArgumentValues(array $data) - { - $this->assertCopyContentTypeValues($data); - } - - /** - * Test for the copyContentType() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::copyContentType - */ - public function testCopyContentTypeThrowsUnauthorizedException() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $commentType = $contentTypeService->loadContentTypeByIdentifier('comment'); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->copyContentType($commentType); - } - - /** - * Test for the assignContentTypeGroup() method. - * - * @depends testLoadContentTypeGroupByIdentifier - * @depends testLoadContentTypeByIdentifier - * @depends testLoadContentType - * @covers \eZ\Publish\Core\Repository\ContentTypeService::assignContentTypeGroup - */ - public function testAssignContentTypeGroup() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $mediaGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Media'); - $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); - - $contentTypeService->assignContentTypeGroup($folderType, $mediaGroup); - /* END: Use Case */ - - $loadedType = $contentTypeService->loadContentType($folderType->id); - - foreach ($loadedType->contentTypeGroups as $loadedGroup) { - if ($mediaGroup->id == $loadedGroup->id) { - return; - } - } - $this->fail( - sprintf( - 'Group with ID "%s" not assigned to content type.', - $mediaGroup->id - ) - ); - } - - /** - * Test for the assignContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::assignContentTypeGroup - */ - public function testAssignContentTypeGroupThrowsUnauthorizedException() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $mediaGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Media'); - $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->assignContentTypeGroup($folderType, $mediaGroup); - } - - /** - * Test for the assignContentTypeGroup() method. - * - * @depends testAssignContentTypeGroup - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::assignContentTypeGroup - */ - public function testAssignContentTypeGroupThrowsInvalidArgumentException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); - $assignedGroups = $folderType->contentTypeGroups; - - foreach ($assignedGroups as $assignedGroup) { - // Throws an exception, since group is already assigned - $contentTypeService->assignContentTypeGroup($folderType, $assignedGroup); - } - /* END: Use Case */ - } - - /** - * Test for the unassignContentTypeGroup() method. - * - * @depends testLoadContentTypeGroupByIdentifier - * @depends testLoadContentTypeByIdentifier - * @depends testLoadContentType - * @depends testAssignContentTypeGroup - * @covers \eZ\Publish\Core\Repository\ContentTypeService::unassignContentTypeGroup - */ - public function testUnassignContentTypeGroup() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); - - $mediaGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Media'); - $contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content'); - - // May not unassign last group - $contentTypeService->assignContentTypeGroup($folderType, $mediaGroup); - - $contentTypeService->unassignContentTypeGroup($folderType, $contentGroup); - /* END: Use Case */ - - $loadedType = $contentTypeService->loadContentType($folderType->id); - - foreach ($loadedType->contentTypeGroups as $assignedGroup) { - if ($assignedGroup->id == $contentGroup->id) { - $this->fail( - sprintf( - 'Group with ID "%s" not unassigned.', - $contentGroup->id - ) - ); - } - } - } - - /** - * Test for the unassignContentTypeGroup() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::unassignContentTypeGroup - */ - public function testUnassignContentTypeGroupThrowsUnauthorizedException() - { - $contentTypeService = $this->repository->getContentTypeService(); - - $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); - - $mediaGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Media'); - $contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content'); - - // May not unassign last group - $contentTypeService->assignContentTypeGroup($folderType, $mediaGroup); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->unassignContentTypeGroup($folderType, $contentGroup); - } - - /** - * Test for the unassignContentTypeGroup() method. - * - * @depends testUnassignContentTypeGroup - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::unassignContentTypeGroup - */ - public function testUnassignContentTypeGroupThrowsInvalidArgumentException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); - $notAssignedGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Media'); - - // Throws an exception, since "Media" group is not assigned to "folder" - $contentTypeService->unassignContentTypeGroup($folderType, $notAssignedGroup); - /* END: Use Case */ - } - - /** - * Test for the unassignContentTypeGroup() method. - * - * @depends testUnassignContentTypeGroup - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::unassignContentTypeGroup - */ - public function testUnassignContentTypeGroupThrowsBadStateException() - { - /* BEGIN: Use Case */ - $contentTypeService = $this->repository->getContentTypeService(); - - $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); - $assignedGroups = $folderType->contentTypeGroups; - - foreach ($assignedGroups as $assignedGroup) { - // Throws an exception, when last group is to be removed - $contentTypeService->unassignContentTypeGroup($folderType, $assignedGroup); - } - /* END: Use Case */ - } - - /** - * Test for the addFieldDefinition() method. - * - * @dep_ends testCreateContentType - * @dep_ends testLoadContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::addFieldDefinition - * - * @return array - */ - public function testAddFieldDefinitionWithValidators() - { - $contentTypeDraft = $this->createDraftContentType(); - $contentTypeService = $this->repository->getContentTypeService(); - - $fieldDefCreate = $contentTypeService->newFieldDefinitionCreateStruct('tags', 'ezstring'); - $fieldDefCreate->names = array( - 'eng-US' => 'Tags', - 'ger-DE' => 'Schlagworte', - ); - $fieldDefCreate->descriptions = array( - 'eng-US' => 'Tags of the blog post', - 'ger-DE' => 'Schlagworte des Blog-Eintrages', - ); - $fieldDefCreate->fieldGroup = 'blog-meta'; - $fieldDefCreate->position = 1; - $fieldDefCreate->isTranslatable = true; - $fieldDefCreate->isRequired = true; - $fieldDefCreate->isInfoCollector = false; - $fieldDefCreate->defaultValue = 'New tags text line'; - $fieldDefCreate->validatorConfiguration = array( - 'StringLengthValidator' => array( - 'maxStringLength' => 255, - 'minStringLength' => 128, - ), - ); - $fieldDefCreate->fieldSettings = null; - $fieldDefCreate->isSearchable = true; - - $contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreate); - - $loadedType = $contentTypeService->loadContentTypeDraft($contentTypeDraft->id); - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $loadedType - ); - - $this->assertAddFieldDefinitionStructValues($loadedType, $fieldDefCreate); - } - - /** - * Test for the addFieldDefinition() method. - * - * @depends testCreateContentType - * @depends testLoadContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::addFieldDefinition - * - * @return array - */ - public function testAddFieldDefinitionWithSettings() - { - $contentTypeDraft = $this->createDraftContentType(); - $contentTypeService = $this->repository->getContentTypeService(); - - $fieldDefCreate = $contentTypeService->newFieldDefinitionCreateStruct('body2', 'ezrichtext'); - $fieldDefCreate->names = array( - 'eng-US' => 'Body', - 'ger-DE' => 'Körper', - ); - $fieldDefCreate->descriptions = array( - 'eng-US' => 'Body of the blog post', - 'ger-DE' => 'Körper der den Blog-Post', - ); - $fieldDefCreate->fieldGroup = 'blog-content'; - $fieldDefCreate->position = 1; - $fieldDefCreate->isTranslatable = true; - $fieldDefCreate->isRequired = false; - $fieldDefCreate->isInfoCollector = false; - $fieldDefCreate->defaultValue = new RichTextValue(); - $fieldDefCreate->validatorConfiguration = array(); - $fieldDefCreate->fieldSettings = array( - 'numRows' => 10, - ); - $fieldDefCreate->isSearchable = true; - - $contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreate); - - $loadedType = $contentTypeService->loadContentTypeDraft($contentTypeDraft->id); - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $loadedType - ); - - $this->assertAddFieldDefinitionStructValues($loadedType, $fieldDefCreate); - } - - public function assertAddFieldDefinitionStructValues($loadedType, $fieldDefCreate) - { - foreach ($loadedType->fieldDefinitions as $fieldDefinition) { - if ($fieldDefinition->identifier == $fieldDefCreate->identifier) { - $this->assertCreatedFieldDefinitionCorrect($fieldDefCreate, $fieldDefinition); - - return; - } - } - - $this->fail( - sprintf( - 'Field definition with identifier "%s" not created.', - $fieldDefCreate->identifier - ) - ); - } - - /** - * Test for the addFieldDefinition() method. - * - * @dep_ends testAddFieldDefinition - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::addFieldDefinition - */ - public function testAddFieldDefinitionThrowsInvalidArgumentExceptionDuplicateFieldIdentifier() - { - $contentTypeDraft = $this->createDraftContentType(); - - /* BEGIN: Use Case */ - // $contentTypeDraft contains a ContentTypeDraft - // $contentTypeDraft has a field "title" - - $contentTypeService = $this->repository->getContentTypeService(); - - $fieldDefCreate = $contentTypeService->newFieldDefinitionCreateStruct('title', 'string'); - - // Throws an exception - $contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreate); - /* END: Use Case */ - } - - /** - * Test for the addFieldDefinition() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::addFieldDefinition - */ - public function testAddFieldDefinitionThrowsUnauthorizedException() - { - $contentTypeDraft = $this->createDraftContentType(); - $contentTypeService = $this->repository->getContentTypeService(); - - $fieldDefCreate = $contentTypeService->newFieldDefinitionCreateStruct('tags', 'ezstring'); - $fieldDefCreate->names = array('eng-US' => 'Tags'); - $fieldDefCreate->descriptions = array('eng-US' => 'Tags of the blog post'); - $fieldDefCreate->fieldGroup = 'blog-meta'; - $fieldDefCreate->position = 1; - $fieldDefCreate->isTranslatable = true; - $fieldDefCreate->isRequired = true; - $fieldDefCreate->isInfoCollector = false; - $fieldDefCreate->defaultValue = 'New tags text line'; - $fieldDefCreate->fieldSettings = null; - $fieldDefCreate->isSearchable = true; - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreate); - } - - /** - * Test for the removeFieldDefinition() method. - * - * @depends testCreateContentType - * @depends testLoadContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::removeFieldDefinition - * - * @return array - */ - public function testRemoveFieldDefinition() - { - $contentTypeDraft = $this->createDraftContentType(); - $draftId = $contentTypeDraft->id; - - /* BEGIN: Use Case */ - // $draftId contains the ID of a content type draft - $contentTypeService = $this->repository->getContentTypeService(); - - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - - $bodyField = $contentTypeDraft->getFieldDefinition('body'); - - $contentTypeService->removeFieldDefinition($contentTypeDraft, $bodyField); - /* END: Use Case */ - - $loadedType = $contentTypeService->loadContentTypeDraft($contentTypeDraft->id); - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentTypeDraft', - $loadedType - ); - - return array( - 'removedFieldDefinition' => $bodyField, - 'loadedType' => $loadedType, - ); - } - - /** - * Test for the removeFieldDefinition() method. - * - * @depends testRemoveFieldDefinition - * @covers \eZ\Publish\Core\Repository\ContentTypeService::removeFieldDefinition - * - * @param array $data - */ - public function testRemoveFieldDefinitionRemoved(array $data) - { - $removedFieldDefinition = $data['removedFieldDefinition']; - $loadedType = $data['loadedType']; - - foreach ($loadedType->fieldDefinitions as $fieldDefinition) { - if ($fieldDefinition->identifier == $removedFieldDefinition->identifier) { - $this->fail( - sprintf( - 'Field definition with identifier "%s" not removed.', - $removedFieldDefinition->identifier - ) - ); - } - } - } - - /** - * Test for the removeFieldDefinition() method. - * - * @depends testRemoveFieldDefinition - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::removeFieldDefinition - */ - public function testRemoveFieldDefinitionThrowsInvalidArgumentException() - { - $draftId = $this->createDraftContentType()->id; - - /* BEGIN: Use Case */ - // $draftId contains the ID of a content type draft - $contentTypeService = $this->repository->getContentTypeService(); - - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - - $bodyField = $contentTypeDraft->getFieldDefinition('body'); - $contentTypeService->removeFieldDefinition($contentTypeDraft, $bodyField); - - // Throws an exception because "body" has already been removed - $contentTypeService->removeFieldDefinition($contentTypeDraft, $bodyField); - /* END: Use Case */ - } - - /** - * Test for the removeFieldDefinition() method. - * - * @depends testRemoveFieldDefinition - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::removeFieldDefinition - */ - public function testRemoveFieldDefinitionThrowsInvalidArgumentExceptionVariation() - { - $draftId = $this->createDraftContentType()->id; - $secondDraftId = $this->createDraftContentType()->id; - - /* BEGIN: Use Case */ - // $draftId and $secondDraftId contain the ids of a different content type drafts that both have "body" field - $contentTypeService = $this->repository->getContentTypeService(); - - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - $secondContentTypeDraft = $contentTypeService->loadContentTypeDraft($secondDraftId); - - $bodyField = $secondContentTypeDraft->getFieldDefinition('body'); - - // Throws an exception because $bodyField field belongs to another draft - $contentTypeService->removeFieldDefinition($contentTypeDraft, $bodyField); - /* END: Use Case */ - } - - /** - * Test for the removeFieldDefinition() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::removeFieldDefinition - */ - public function testRemoveFieldDefinitionThrowsUnauthorizedException() - { - $contentTypeDraft = $this->createDraftContentType(); - $bodyField = $contentTypeDraft->getFieldDefinition('body'); - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $this->repository->getContentTypeService()->removeFieldDefinition($contentTypeDraft, $bodyField); - } - - /** - * Test for the updateFieldDefinition() method. - * - * @depends testCreateContentType - * @depends testLoadContentTypeDraft - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateFieldDefinition - * - * @return array - */ - public function testUpdateFieldDefinition() - { - $draftId = $this->createDraftContentType()->id; - $contentTypeService = $this->repository->getContentTypeService(); - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - $fieldDefinition = $contentTypeDraft->getFieldDefinition('body'); - - $fieldDefinitionUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct(); - $fieldDefinitionUpdateStruct->identifier = $fieldDefinition->identifier . 'changed'; - $fieldDefinitionUpdateStruct->names = array( - 'eng-US' => $fieldDefinition->getName('eng-US') . 'changed', - 'ger-DE' => $fieldDefinition->getName('ger-DE') . 'changed', - ); - $fieldDefinitionUpdateStruct->descriptions = array( - 'eng-US' => $fieldDefinition->getDescription('eng-US') . 'changed', - 'ger-DE' => $fieldDefinition->getDescription('ger-DE') . 'changed', - ); - $fieldDefinitionUpdateStruct->fieldGroup = $fieldDefinition->fieldGroup . 'changed'; - $fieldDefinitionUpdateStruct->position = $fieldDefinition->position + 1; - $fieldDefinitionUpdateStruct->isTranslatable = !$fieldDefinition->isTranslatable; - $fieldDefinitionUpdateStruct->isRequired = !$fieldDefinition->isRequired; - $fieldDefinitionUpdateStruct->isInfoCollector = !$fieldDefinition->isInfoCollector; - $fieldDefinitionUpdateStruct->defaultValue = (string)$fieldDefinition->defaultValue . 'changed'; - //$fieldDefinitionUpdateStruct->validators - $fieldDefinitionUpdateStruct->fieldSettings = array( - 'textRows' => $fieldDefinition->fieldSettings['textRows'] + 1, - ); - $fieldDefinitionUpdateStruct->isSearchable = $fieldDefinition->isSearchable; - - $contentTypeService->updateFieldDefinition( - $contentTypeDraft, - $fieldDefinition, - $fieldDefinitionUpdateStruct - ); - - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - $updatedFieldDefinition = $contentTypeDraft->getFieldDefinition($fieldDefinitionUpdateStruct->identifier); - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinition', - $updatedFieldDefinition - ); - - $this->assertUpdateFieldDefinitionStructValues( - $fieldDefinition, - $updatedFieldDefinition, - $fieldDefinitionUpdateStruct - ); - } - - /** - * Test for the updateFieldDefinition() method. - * - * @depends testUpdateFieldDefinition - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateFieldDefinition - * - * @return array - */ - public function testUpdateFieldDefinitionWithValidatorConfiguration() - { - $draftId = $this->createDraftContentType()->id; - $contentTypeService = $this->repository->getContentTypeService(); - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - $fieldDefinition = $contentTypeDraft->getFieldDefinition('title'); - - $fieldDefinitionUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct(); - $fieldDefinitionUpdateStruct->validatorConfiguration = array( - 'StringLengthValidator' => array( - 'minStringLength' => (int)$fieldDefinition->validatorConfiguration['StringLengthValidator']['minStringLength'] + 1, - 'maxStringLength' => (int)$fieldDefinition->validatorConfiguration['StringLengthValidator']['maxStringLength'] + 1, - ), - ); - - $contentTypeService->updateFieldDefinition( - $contentTypeDraft, - $fieldDefinition, - $fieldDefinitionUpdateStruct - ); - - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - $updatedFieldDefinition = $contentTypeDraft->getFieldDefinition('title'); - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinition', - $updatedFieldDefinition - ); - - $this->assertUpdateFieldDefinitionStructValues( - $fieldDefinition, - $updatedFieldDefinition, - $fieldDefinitionUpdateStruct - ); - } - - /** - * Test for the updateFieldDefinition() method. - * - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateFieldDefinition - */ - public function testUpdateFieldDefinitionWithEmptyStruct() - { - $draftId = $this->createDraftContentType()->id; - $contentTypeService = $this->repository->getContentTypeService(); - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - $fieldDefinition = $contentTypeDraft->getFieldDefinition('body'); - $fieldDefinitionUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct(); - - $contentTypeService->updateFieldDefinition( - $contentTypeDraft, - $fieldDefinition, - $fieldDefinitionUpdateStruct - ); - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - $updatedFieldDefinition = $contentTypeDraft->getFieldDefinition('body'); - - self::assertEquals( - $fieldDefinition, - $updatedFieldDefinition - ); - } - - protected function assertUpdateFieldDefinitionStructValues($originalField, $updatedField, $updateStruct) - { - $this->assertPropertiesCorrect( - array( - 'id' => $originalField->id, - 'fieldTypeIdentifier' => $originalField->fieldTypeIdentifier, - 'identifier' => $updateStruct->identifier === null ? - $originalField->identifier : - $updateStruct->identifier, - 'names' => $updateStruct->names === null ? - $originalField->names : - $updateStruct->names, - 'descriptions' => $updateStruct->descriptions === null ? - $originalField->descriptions : - $updateStruct->descriptions, - 'fieldGroup' => $updateStruct->fieldGroup === null ? - $originalField->fieldGroup : - $updateStruct->fieldGroup, - 'position' => $updateStruct->position === null ? - $originalField->position : - $updateStruct->position, - 'isTranslatable' => $updateStruct->isTranslatable === null ? - $originalField->isTranslatable : - $updateStruct->isTranslatable, - 'isRequired' => $updateStruct->isRequired === null ? - $originalField->isRequired : - $updateStruct->isRequired, - 'isInfoCollector' => $updateStruct->isInfoCollector === null ? - $originalField->isInfoCollector : - $updateStruct->isInfoCollector, - 'defaultValue' => $originalField->defaultValue === null ? - $originalField->defaultValue : - $updateStruct->defaultValue, - 'isSearchable' => $updateStruct->isSearchable === null ? - $originalField->isSearchable : - $updateStruct->isSearchable, - ), - $updatedField, - // Do not compare defaultValue as they may have different representations - array('defaultValue') - ); - - $expectedFieldSettings = (array)$updateStruct->fieldSettings; - $actualFieldSettings = (array)$updatedField->fieldSettings; - ksort($expectedFieldSettings); - ksort($actualFieldSettings); - $this->assertEquals( - $expectedFieldSettings, - $actualFieldSettings, - "Field definition property 'fieldSettings' is not correctly updated" - ); - - $expectedValidators = (array)$updateStruct->validatorConfiguration; - $actualValidators = (array)$updatedField->validatorConfiguration; - $sorter = function ($a, $b) { - if ($a->identifier == $b->identifier) { - return 0; - } - - return ($a->identifier < $b->identifier) ? -1 : 1; - }; - usort($expectedValidators, $sorter); - usort($actualValidators, $sorter); - $this->assertEquals( - $expectedValidators, - $actualValidators, - "Field definition property 'validatorConfiguration' is not correctly updated" - ); - } - - /** - * Test for the updateFieldDefinition() method. - * - * @depends testUpdateFieldDefinition - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateFieldDefinition - */ - public function testUpdateFieldDefinitionThrowsInvalidArgumentExceptionFieldIdentifierExists() - { - $contentTypeDraft = $this->createDraftContentType(); - $draftId = $contentTypeDraft->id; - - /* BEGIN: Use Case */ - // $draftId contains the ID of a content type draft - $contentTypeService = $this->repository->getContentTypeService(); - - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - - $bodyField = $contentTypeDraft->getFieldDefinition('body'); - $titleField = $contentTypeDraft->getFieldDefinition('title'); - - $bodyUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct(); - $bodyUpdateStruct->identifier = 'title'; - - // Throws exception, since "title" field already exists - $contentTypeService->updateFieldDefinition( - $contentTypeDraft, - $bodyField, - $bodyUpdateStruct - ); - /* END: Use Case */ - } - - /** - * Test for the updateFieldDefinition() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateFieldDefinition - */ - public function testUpdateFieldDefinitionThrowsUnauthorizedException() - { - $contentTypeService = $this->repository->getContentTypeService(); - $contentTypeDraft = $this->createDraftContentType(); - $fieldDefinition = $contentTypeDraft->getFieldDefinition('body'); - - $fieldDefinitionUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct(); - $fieldDefinitionUpdateStruct->identifier = $fieldDefinition->identifier . 'changed'; - - // Set anonymous as current user - $this->repository->setCurrentUser($this->getStubbedUser(10)); - - $contentTypeService->updateFieldDefinition( - $contentTypeDraft, - $fieldDefinition, - $fieldDefinitionUpdateStruct - ); - } - - /** - * Test for the updateFieldDefinition() method. - * - * @depends testUpdateFieldDefinition - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\ContentTypeService::updateFieldDefinition - */ - public function testUpdateFieldDefinitionThrowsInvalidArgumentExceptionFieldIdNotFound() - { - $contentTypeDraft = $this->createDraftContentType(); - $draftId = $contentTypeDraft->id; - - /* BEGIN: Use Case */ - // $draftId contains the ID of a content type draft - $contentTypeService = $this->repository->getContentTypeService(); - - $contentTypeDraft = $contentTypeService->loadContentTypeDraft($draftId); - - $bodyField = $contentTypeDraft->getFieldDefinition('body'); - $contentTypeService->removeFieldDefinition($contentTypeDraft, $bodyField); - - $loadedDraft = $contentTypeService->loadContentTypeDraft($draftId); - - $bodyUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct(); - - // Throws exception, since field "body" is already deleted - $contentTypeService->updateFieldDefinition( - $loadedDraft, - $bodyField, - $bodyUpdateStruct - ); - /* END: Use Case */ - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/LanguageBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/LanguageBase.php deleted file mode 100644 index 773b0a669e2..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/LanguageBase.php +++ /dev/null @@ -1,421 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\LanguageBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\API\Repository\Values\Content\Language; -use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; -use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; -use eZ\Publish\API\Repository\Exceptions\NotFoundException; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; - -/** - * Test case for Language Service. - */ -abstract class LanguageBase extends BaseServiceTest -{ - /** - * Test a new class and default values on properties. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Language::__construct - */ - public function testNewClass() - { - $language = new Language(); - - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'languageCode' => null, - 'name' => null, - 'enabled' => null, - ), - $language - ); - } - - /** - * Test retrieving missing property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Language::__get - */ - public function testMissingProperty() - { - try { - $language = new Language(); - $value = $language->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - } - - /** - * Test setting read only property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Language::__set - */ - public function testReadOnlyProperty() - { - try { - $language = new Language(); - $language->id = 42; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test if property exists. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Language::__isset - */ - public function testIsPropertySet() - { - $language = new Language(); - $value = isset($language->notDefined); - self::assertEquals(false, $value); - - $value = isset($language->id); - self::assertEquals(true, $value); - } - - /** - * Test unsetting a property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Language::__unset - */ - public function testUnsetProperty() - { - $language = new Language(array('id' => 2)); - try { - unset($language->id); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test service method for creating language. - * - * @covers \eZ\Publish\API\Repository\LanguageService::createLanguage - */ - public function testCreateLanguage() - { - $service = $this->repository->getContentLanguageService(); - - $languageCreateStruct = $service->newLanguageCreateStruct(); - $languageCreateStruct->languageCode = 'test-TEST'; - $languageCreateStruct->name = 'test'; - - $newLanguage = $service->createLanguage($languageCreateStruct); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language', $newLanguage); - - self::assertGreaterThan(0, $newLanguage->id); - - $this->assertPropertiesCorrect( - array( - 'languageCode' => $languageCreateStruct->languageCode, - 'name' => $languageCreateStruct->name, - 'enabled' => $languageCreateStruct->enabled, - ), - $newLanguage - ); - } - - /** - * Test service method for creating language throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LanguageService::createLanguage - */ - public function testCreateLanguageThrowsInvalidArgumentException() - { - $service = $this->repository->getContentLanguageService(); - - $languageCreateStruct = $service->newLanguageCreateStruct(); - $languageCreateStruct->languageCode = 'eng-GB'; - $languageCreateStruct->name = 'English'; - - $service->createLanguage($languageCreateStruct); - } - - /** - * Test service method for updating language name. - * - * @covers \eZ\Publish\API\Repository\LanguageService::updateLanguageName - */ - public function testUpdateLanguageName() - { - $languageService = $this->repository->getContentLanguageService(); - - $language = $languageService->loadLanguage('eng-GB'); - self::assertEquals('English (United Kingdom)', $language->name); - - $updatedLanguage = $languageService->updateLanguageName($language, 'English'); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language', $updatedLanguage); - - $this->assertPropertiesCorrect( - array( - 'id' => $language->id, - 'languageCode' => $language->languageCode, - 'name' => 'English', - 'enabled' => $language->enabled, - ), - $updatedLanguage - ); - } - - /** - * Test service method for updating language name throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LanguageService::updateLanguageName - */ - public function testUpdateLanguageNameThrowsInvalidArgumentException() - { - $languageService = $this->repository->getContentLanguageService(); - - $language = $languageService->loadLanguage('eng-GB'); - $languageService->updateLanguageName($language, 1); - } - - /** - * Test service method for enabling language. - * - * @covers \eZ\Publish\API\Repository\LanguageService::enableLanguage - */ - public function testEnableLanguage() - { - $languageService = $this->repository->getContentLanguageService(); - - $language = $languageService->loadLanguage('eng-GB'); - self::assertEquals(true, $language->enabled); - - $updatedLanguage = $languageService->disableLanguage($language); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language', $updatedLanguage); - - $this->assertPropertiesCorrect( - array( - 'id' => $language->id, - 'languageCode' => $language->languageCode, - 'name' => $language->name, - 'enabled' => false, - ), - $updatedLanguage - ); - - $finalLanguage = $languageService->enableLanguage($updatedLanguage); - - $this->assertPropertiesCorrect( - array( - 'id' => $updatedLanguage->id, - 'languageCode' => $updatedLanguage->languageCode, - 'name' => $updatedLanguage->name, - 'enabled' => true, - ), - $finalLanguage - ); - } - - /** - * Test service method for disabling language. - * - * @covers \eZ\Publish\API\Repository\LanguageService::disableLanguage - */ - public function testDisableLanguage() - { - $languageService = $this->repository->getContentLanguageService(); - - $language = $languageService->loadLanguage('eng-GB'); - self::assertEquals(true, $language->enabled); - - $updatedLanguage = $languageService->disableLanguage($language); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language', $updatedLanguage); - - $this->assertPropertiesCorrect( - array( - 'id' => $language->id, - 'languageCode' => $language->languageCode, - 'name' => $language->name, - 'enabled' => false, - ), - $updatedLanguage - ); - } - - /** - * Test service method for loading language. - * - * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage - */ - public function testLoadLanguage() - { - $language = $this->repository->getContentLanguageService()->loadLanguage('eng-GB'); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language', $language); - self::assertGreaterThan(0, $language->id); - - $this->assertPropertiesCorrect( - array( - 'languageCode' => 'eng-GB', - 'name' => 'English (United Kingdom)', - 'enabled' => true, - ), - $language - ); - } - - /** - * Test service method for loading language throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage - */ - public function testLoadLanguageThrowsInvalidArgumentException() - { - $this->repository->getContentLanguageService()->loadLanguage(PHP_INT_MAX); - } - - /** - * Test service function for loading language throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage - */ - public function testLoadLanguageThrowsNotFoundException() - { - $this->repository->getContentLanguageService()->loadLanguage('ita-FR'); - } - - /** - * Test service method for loading all languages. - * - * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguages - */ - public function testLoadLanguages() - { - $languageService = $this->repository->getContentLanguageService(); - - $languages = $languageService->loadLanguages(); - - self::assertInternalType('array', $languages); - self::assertNotEmpty($languages); - - foreach ($languages as $language) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language', $language); - } - } - - /** - * Test service method for loading language by ID. - * - * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageById - */ - public function testLoadLanguageById() - { - $language = $this->repository->getContentLanguageService()->loadLanguageById(2); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language', $language); - - $this->assertPropertiesCorrect( - array( - 'id' => 2, - 'languageCode' => 'eng-US', - 'name' => 'English (American)', - 'enabled' => true, - ), - $language - ); - } - - /** - * Test service method for loading language by ID throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageById - */ - public function testLoadLanguageByIdThrowsNotFoundException() - { - $this->repository->getContentLanguageService()->loadLanguageById(APIBaseTest::DB_INT_MAX); - } - - /** - * Test service method for deleting language. - * - * @covers \eZ\Publish\API\Repository\LanguageService::deleteLanguage - */ - public function testDeleteLanguage() - { - $languageService = $this->repository->getContentLanguageService(); - - $languageCreateStruct = $languageService->newLanguageCreateStruct(); - $languageCreateStruct->name = 'test'; - $languageCreateStruct->languageCode = 'test-TEST'; - - $newLanguage = $languageService->createLanguage($languageCreateStruct); - $languageService->deleteLanguage($newLanguage); - - try { - $languageService->loadLanguage($languageCreateStruct->languageCode); - self::fail('Language is still returned after being deleted'); - } catch (NotFoundException $e) { - } - } - - /** - * Test service method for deleting language throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LanguageService::deleteLanguage - */ - public function testDeleteLanguageThrowsInvalidArgumentException() - { - $languageService = $this->repository->getContentLanguageService(); - - $language = $languageService->loadLanguage('eng-GB'); - $languageService->deleteLanguage($language); - } - - /** - * Test service method for fetching the default language code. - * - * @covers \eZ\Publish\API\Repository\LanguageService::getDefaultLanguageCode - */ - public function testGetDefaultLanguageCode() - { - $defaultLanguageCode = $this->repository->getContentLanguageService()->getDefaultLanguageCode(); - - self::assertEquals('eng-GB', $defaultLanguageCode); - } - - /** - * Test service method for creating a new language create struct object. - * - * @covers \eZ\Publish\API\Repository\LanguageService::newLanguageCreateStruct - */ - public function testNewLanguageCreateStruct() - { - $languageCreateStruct = $this->repository->getContentLanguageService()->newLanguageCreateStruct(); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LanguageCreateStruct', $languageCreateStruct); - - $this->assertPropertiesCorrect( - array( - 'languageCode' => null, - 'name' => null, - 'enabled' => true, - ), - $languageCreateStruct - ); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ContentTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ContentTest.php deleted file mode 100644 index a953fb8ea2f..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ContentTest.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\ContentTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\ContentBase as BaseContentServiceTest; - -/** - * Test case for Content Service using Legacy storage class. - */ -class ContentTest extends BaseContentServiceTest -{ - protected function getRepository() - { - return Utils::getRepository(); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ContentTypeTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ContentTypeTest.php deleted file mode 100644 index da04e08f485..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ContentTypeTest.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\ContentTypeTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\ContentTypeBase as BaseContentTypeServiceTest; - -/** - * Test case for ContentType Service using Legacy storage class. - */ -class ContentTypeTest extends BaseContentTypeServiceTest -{ - protected function getRepository() - { - return Utils::getRepository(); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/LanguageTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/LanguageTest.php deleted file mode 100644 index ba8e536c9dd..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/LanguageTest.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\LanguageTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\LanguageBase as BaseLanguageServiceTest; - -/** - * Test case for Language Service using Legacy storage class. - */ -class LanguageTest extends BaseLanguageServiceTest -{ - protected function getRepository() - { - return Utils::getRepository(); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/LocationTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/LocationTest.php deleted file mode 100644 index c5156a08b02..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/LocationTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\LocationTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\LocationBase as BaseLocationServiceTest; -use Exception; - -/** - * Test case for Location Service using Legacy storage class. - */ -class LocationTest extends BaseLocationServiceTest -{ - protected function getRepository() - { - try { - return Utils::getRepository(); - } catch (Exception $e) { - $this->markTestIncomplete($e->getMessage()); - } - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/NameSchemaTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/NameSchemaTest.php deleted file mode 100644 index 33f132836b1..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/NameSchemaTest.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\NameSchemaTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\NameSchemaBase as BaseNameSchemaTest; - -/** - * Test case for NameSchema Service using Legacy storage class. - */ -class NameSchemaTest extends BaseNameSchemaTest -{ - protected function getRepository() - { - return Utils::getRepository(); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ObjectStateTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ObjectStateTest.php deleted file mode 100644 index 6639a1899a4..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/ObjectStateTest.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\ObjectStateTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\ObjectStateBase as BaseObjectStateServiceTest; - -/** - * Test case for object state Service using Legacy storage class. - */ -class ObjectStateTest extends BaseObjectStateServiceTest -{ - protected function getRepository() - { - return Utils::getRepository(); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/RepositoryTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/RepositoryTest.php deleted file mode 100644 index 641bdf1c80a..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/RepositoryTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\RepositoryTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\RepositoryTest as BaseRepositoryTest; -use Exception; - -/** - * Test case for Repository Service using Legacy storage class. - */ -class RepositoryTest extends BaseRepositoryTest -{ - protected function getRepository() - { - try { - return Utils::getRepository(); - } catch (Exception $e) { - $this->markTestIncomplete($e->getMessage()); - } - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/RoleTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/RoleTest.php deleted file mode 100644 index eef85753800..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/RoleTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\RoleTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\RoleBase as BaseRoleServiceTest; -use Exception; - -/** - * Test case for Role Service using Legacy storage class. - */ -class RoleTest extends BaseRoleServiceTest -{ - protected function getRepository() - { - try { - return Utils::getRepository(); - } catch (Exception $e) { - $this->markTestIncomplete($e->getMessage()); - } - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SearchTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SearchTest.php deleted file mode 100644 index eb247ef8043..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SearchTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\SearchTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\SearchBase as BaseSearchServiceTest; -use Exception; - -/** - * Test case for Search Service using Legacy storage class. - */ -class SearchTest extends BaseSearchServiceTest -{ - protected function getRepository() - { - try { - return Utils::getRepository(); - } catch (Exception $e) { - $this->markTestIncomplete($e->getMessage()); - } - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SectionTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SectionTest.php deleted file mode 100644 index a78fbf5cfe4..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SectionTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\SectionTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\SectionBase as BaseSectionServiceTest; -use Exception; - -/** - * Test case for Section Service using Legacy storage class. - */ -class SectionTest extends BaseSectionServiceTest -{ - protected function getRepository() - { - try { - return Utils::getRepository(); - } catch (Exception $e) { - $this->markTestIncomplete($e->getMessage()); - } - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SetupFactory.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SetupFactory.php deleted file mode 100644 index 7ea1700ccc8..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/SetupFactory.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -/** - * File containing the Test Setup Factory base class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Base\ServiceContainer; -use eZ\Publish\API\Repository\Tests\SetupFactory\Legacy as APILegacySetupFactory; - -/** - * A Test Factory is used to setup the infrastructure for a tests, based on a - * specific repository implementation to test. - */ -class SetupFactory extends APILegacySetupFactory -{ - /** - * @var string - */ - protected $repositoryReference = 'ezpublish.api.inner_repository'; - - /** - * Returns the service container used for initialization of the repository. - * - * @return \eZ\Publish\Core\Base\ServiceContainer - */ - public function getServiceContainer() - { - if (!isset(static::$serviceContainer)) { - $config = include __DIR__ . '/../../../../../../../../config.php'; - $installDir = $config['install_dir']; - - /** @var \Symfony\Component\DependencyInjection\ContainerBuilder $containerBuilder */ - $containerBuilder = include $config['container_builder_path']; - - /* @var \Symfony\Component\DependencyInjection\Loader\YamlFileLoader $loader */ - $loader->load('search_engines/legacy.yml'); - $loader->load('tests/integration_legacy_core.yml'); - - $containerBuilder->setParameter( - 'legacy_dsn', - static::$dsn - ); - - static::$serviceContainer = new ServiceContainer( - $containerBuilder, - $installDir, - $config['cache_dir'], - true, - true - ); - } - - return static::$serviceContainer; - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/TrashTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/TrashTest.php deleted file mode 100644 index 69b4c46fabc..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/TrashTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\TrashTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\TrashBase as BaseTrashServiceTest; -use Exception; - -/** - * Test case for Trash Service using Legacy storage class. - */ -class TrashTest extends BaseTrashServiceTest -{ - protected function getRepository() - { - try { - return Utils::getRepository(); - } catch (Exception $e) { - $this->markTestIncomplete($e->getMessage()); - } - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/UserTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/UserTest.php deleted file mode 100644 index d63ed9ee997..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/UserTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\UserTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\UserBase as BaseUserServiceTest; -use Exception; - -/** - * Test case for User Service using Legacy storage class. - */ -class UserTest extends BaseUserServiceTest -{ - protected function getRepository() - { - try { - return Utils::getRepository(); - } catch (Exception $e) { - $this->markTestIncomplete($e->getMessage()); - } - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/Utils.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/Utils.php deleted file mode 100644 index 3ad65248340..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/Utils.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\Utils class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy; - -/** - * Utils class for LegacySE test. - */ -abstract class Utils -{ - /** - * @var \eZ\Publish\API\Repository\Tests\SetupFactory - */ - public static $setupFactory; - - /** - * @return \eZ\Publish\API\Repository\Repository - */ - final public static function getRepository() - { - if (static::$setupFactory === null) { - static::$setupFactory = static::getSetupFactory(); - } - - // Return repository - return static::$setupFactory->getRepository(); - } - - /** - * @return \eZ\Publish\API\Repository\Tests\SetupFactory - */ - protected static function getSetupFactory() - { - return new SetupFactory(); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/upload.phpt b/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/upload.phpt deleted file mode 100644 index 590b18071b4..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/Legacy/upload.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -Test file upload for IOService with Legacy persistence handler ---POST_RAW-- -Content-Type: multipart/form-data; boundary=---------------------------2921238217421 - ------------------------------2921238217421 -Content-Disposition: form-data; name="file"; filename="stairway_to_heaven.txt" -Content-Type: text/plain - -There's a lady who's sure -All that glitters is gold -And she's buying a stairway to heaven. - -When she gets there she knows -If the stores are all closed -With a word she can get what she came for. - ------------------------------2921238217421 -Content-Disposition: form-data; name="submit" - -Upload ------------------------------2921238217421-- ---FILE-- -<?php - -chdir( __DIR__ . '/../../../../../../../' ); - -require_once 'bootstrap.php'; -require_once 'PHPUnit/Autoload.php'; - -$repository = \eZ\Publish\Core\Repository\Tests\Service\Integration\Legacy\IOUploadPHPT::getRepository( array() ); - -$binaryCreateStruct = $repository->getIOService()->newBinaryCreateStructFromUploadedFile( $_FILES['file'] ); - -var_dump( $binaryCreateStruct instanceof \eZ\Publish\API\Repository\Values\IO\BinaryFileCreateStruct ); - -?> ---EXPECT-- -bool(true) diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/LocationBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/LocationBase.php deleted file mode 100644 index 7227da25bda..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/LocationBase.php +++ /dev/null @@ -1,709 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\LocationBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\Core\Repository\Values\Content\Location; -use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; -use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; -use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; -use eZ\Publish\API\Repository\Exceptions\NotFoundException; -use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; - -/** - * Test case for Location Service. - */ -abstract class LocationBase extends BaseServiceTest -{ - /** - * Test a new class and default values on properties. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Location::__construct - */ - public function testNewClass() - { - $location = new Location(); - - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'priority' => null, - 'hidden' => null, - 'invisible' => null, - 'remoteId' => null, - 'parentLocationId' => null, - 'pathString' => null, - 'path' => array(), - 'depth' => null, - 'sortField' => null, - 'sortOrder' => null, - ), - $location - ); - } - - /** - * Test retrieving missing property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Location::__get - */ - public function testMissingProperty() - { - try { - $location = new Location(); - $value = $location->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - } - - /** - * Test setting read only property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Location::__set - */ - public function testReadOnlyProperty() - { - try { - $location = new Location(); - $location->id = 42; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test if property exists. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Location::__isset - */ - public function testIsPropertySet() - { - $location = new Location(); - $value = isset($location->notDefined); - self::assertEquals(false, $value); - - $value = isset($location->id); - self::assertEquals(true, $value); - } - - /** - * Test unsetting a property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Location::__unset - */ - public function testUnsetProperty() - { - $location = new Location(array('id' => 2)); - try { - unset($location->id); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * @param int $parentLocationId - * - * @return \eZ\Publish\API\Repository\Values\Content\Content - */ - protected function createTestContentLocation($parentLocationId) - { - $contentService = $this->repository->getContentService(); - $contentTypeService = $this->repository->getContentTypeService(); - // User Group content type - $contentType = $contentTypeService->loadContentType(3); - - $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-GB'); - $contentCreate->setField('name', 'dummy value'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = md5(uniqid(get_class($this), true)); - $contentCreate->alwaysAvailable = true; - - $locationCreates = array( - new LocationCreateStruct( - array( - //priority = 0 - //hidden = false - 'remoteId' => md5(uniqid(get_class($this), true)), - //sortField = Location::SORT_FIELD_NAME - //sortOrder = Location::SORT_ORDER_ASC - 'parentLocationId' => $parentLocationId, - ) - ), - ); - - return $contentService->publishVersion( - $contentService->createContent( - $contentCreate, - $locationCreates - )->versionInfo - ); - } - - /** - * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo - * @param int $parentLocationId - * - * @return mixed - */ - protected function addNewMainLocation($contentInfo, $parentLocationId) - { - $locationService = $this->repository->getLocationService(); - $contentService = $this->repository->getContentService(); - - $newLocation = $locationService->createLocation( - $contentInfo, - new LocationCreateStruct( - array( - 'remoteId' => md5(uniqid(get_class($this), true)), - 'parentLocationId' => $parentLocationId, - ) - ) - ); - $contentService->updateContentMetadata( - $contentInfo, - new ContentMetadataUpdateStruct(array('mainLocationId' => $newLocation->id)) - ); - - return $newLocation->id; - } - - /** - * Test copying a subtree. - * - * @group current - * @covers \eZ\Publish\API\Repository\LocationService::copySubtree - */ - public function testCopySubtree() - { - // Prepare test tree - $outsideLocationId = $this->createTestContentLocation(5)->contentInfo->mainLocationId; - $targetLocationId = $this->createTestContentLocation(5)->contentInfo->mainLocationId; - $locationToCopyContent = $this->createTestContentLocation(5); - - $locationToCopyId = $locationToCopyContent->contentInfo->mainLocationId; - - $this->createTestContentLocation($locationToCopyId); - $subLocationContent20 = $this->createTestContentLocation($locationToCopyId); - $subLocationId20 = $subLocationContent20->contentInfo->mainLocationId; - $subLocationContent21 = $this->createTestContentLocation($subLocationId20); - - // Add main locations outside subtree - $this->addNewMainLocation($locationToCopyContent->contentInfo, $outsideLocationId); - $this->addNewMainLocation($subLocationContent20->contentInfo, $outsideLocationId); - - // Add main locations inside subtree - $lastLocationId = $this->addNewMainLocation($subLocationContent21->contentInfo, $locationToCopyId); - - /* BEGIN: Use Case */ - $locationService = $this->repository->getLocationService(); - $locationToCopy = $locationService->loadLocation($locationToCopyId); - $targetLocation = $locationService->loadLocation($targetLocationId); - - $copiedSubtreeRootLocation = $locationService->copySubtree($locationToCopy, $targetLocation); - /* END: Use Case */ - - self::assertEquals($lastLocationId + 1, $copiedSubtreeRootLocation->id); - - // Check structure - $subtreeRootChildren = $locationService->loadLocationChildren($copiedSubtreeRootLocation); - self::assertEquals(3, $subtreeRootChildren->totalCount); - self::assertEquals(0, $locationService->getLocationChildCount($subtreeRootChildren->locations[0])); - $subLocationChildren = $locationService->loadLocationChildren($subtreeRootChildren->locations[1]); - self::assertEquals(1, $subLocationChildren->totalCount); - self::assertEquals(0, $locationService->getLocationChildCount($subtreeRootChildren->locations[2])); - self::assertEquals(0, $locationService->getLocationChildCount($subLocationChildren->locations[0])); - - // Check main locations - self::assertEquals($copiedSubtreeRootLocation->contentInfo->mainLocationId, $copiedSubtreeRootLocation->id); - self::assertEquals($subtreeRootChildren->locations[0]->contentInfo->mainLocationId, $subtreeRootChildren->locations[0]->id); - self::assertEquals($subtreeRootChildren->locations[1]->contentInfo->mainLocationId, $subtreeRootChildren->locations[1]->id); - self::assertEquals($subtreeRootChildren->locations[2]->contentInfo->mainLocationId, $subtreeRootChildren->locations[2]->id); - self::assertEquals($subLocationChildren->locations[0]->contentInfo->mainLocationId, $subtreeRootChildren->locations[2]->id); - - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $copiedSubtreeRootLocation); - self::assertEquals($targetLocation->id, $copiedSubtreeRootLocation->parentLocationId); - } - - /** - * Test copying a subtree throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LocationService::copySubtree - */ - public function testCopySubtreeThrowsInvalidArgumentException() - { - $locationService = $this->repository->getLocationService(); - $locationToCopy = $locationService->loadLocation(5); - $targetLocation = $locationService->loadLocation(44); - - $locationService->copySubtree($locationToCopy, $targetLocation); - } - - /** - * Test loading a location. - * - * @covers \eZ\Publish\API\Repository\LocationService::loadLocation - */ - public function testLoadLocation() - { - $locationService = $this->repository->getLocationService(); - $loadedLocation = $locationService->loadLocation(5); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $loadedLocation); - self::assertEquals(5, $loadedLocation->id); - } - - /** - * Test loading a location throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\LocationService::loadLocation - */ - public function testLoadLocationThrowsNotFoundException() - { - $locationService = $this->repository->getLocationService(); - $locationService->loadLocation(APIBaseTest::DB_INT_MAX); - } - - /** - * Test loading location by remote ID. - * - * @covers \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId - */ - public function testLoadLocationByRemoteId() - { - $location = $this->repository->getLocationService()->loadLocationByRemoteId('769380b7aa94541679167eab817ca893'); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); - self::assertGreaterThan(0, $location->id); - self::assertEquals('769380b7aa94541679167eab817ca893', $location->remoteId); - } - - /** - * Test loading location by remote ID. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId - */ - public function testLoadLocationByRemoteIdThrowsNotFoundException() - { - $this->repository->getLocationService()->loadLocationByRemoteId('not-existing'); - } - - protected function createContentDraft() - { - $contentTypeService = $this->repository->getContentTypeService(); - $contentService = $this->repository->getContentService(); - $locationService = $this->repository->getLocationService(); - - $contentCreateStruct = $contentService->newContentCreateStruct( - $contentTypeService->loadContentType(3), - 'eng-GB' - ); - $contentCreateStruct->sectionId = 1; - $contentCreateStruct->ownerId = 14; - - $contentCreateStruct->setField('name', 'New group'); - $contentCreateStruct->setField('description', 'New group description'); - - $locationCreateStruct = $locationService->newLocationCreateStruct(5); - - return $contentService->createContent($contentCreateStruct, array($locationCreateStruct)); - } - - /** - * Test loading locations for content. - * - * @covers \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct - * @covers \eZ\Publish\API\Repository\LocationService::createLocation - * @covers \eZ\Publish\API\Repository\LocationService::loadLocations - */ - public function testLoadLocations() - { - $contentInfo = $this->repository->getContentService()->loadContentInfo(12); - - $locationService = $this->repository->getLocationService(); - $locations = $locationService->loadLocations($contentInfo); - - self::assertInternalType('array', $locations); - self::assertNotEmpty($locations); - - foreach ($locations as $location) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); - self::assertEquals($contentInfo->id, $location->getContentInfo()->id); - } - - $locationsCount = count($locations); - - $locationCreateStruct = $locationService->newLocationCreateStruct(44); - $locationService->createLocation($contentInfo, $locationCreateStruct); - - $locations = $locationService->loadLocations($contentInfo); - - self::assertInternalType('array', $locations); - self::assertNotEmpty($locations); - - foreach ($locations as $location) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); - self::assertEquals($contentInfo->id, $location->getContentInfo()->id); - } - - $newLocationsCount = count($locations); - - self::assertEquals($locationsCount + 1, $newLocationsCount); - } - - /** - * Test loading locations for content with root location specified. - * - * @covers \eZ\Publish\API\Repository\LocationService::loadLocations - */ - public function testLoadLocationsWithRootLocation() - { - $contentInfo = $this->repository->getContentService()->loadContentInfo(12); - - $locationService = $this->repository->getLocationService(); - $parentLocation = $locationService->loadLocation(5); - - $locations = $locationService->loadLocations($contentInfo, $parentLocation); - - self::assertInternalType('array', $locations); - self::assertNotEmpty($locations); - - foreach ($locations as $location) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); - } - - foreach ($locations as $location) { - if (stripos($location->pathString, $parentLocation->pathString) === false) { - self::fail('fetched locations outside root node'); - } - } - } - - /** - * Test loading locations for content throwing BadStateException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - * @covers \eZ\Publish\API\Repository\LocationService::loadLocations - */ - public function testLoadLocationsThrowsBadStateException() - { - $contentDraft = $this->createContentDraft(); - - $this->repository->getLocationService()->loadLocations( - $contentDraft->getVersionInfo()->getContentInfo() - ); - } - - /** - * Test loading location children. - * - * @covers \eZ\Publish\API\Repository\LocationService::loadLocationChildren - */ - public function testLoadLocationChildren() - { - $locationService = $this->repository->getLocationService(); - - $rootLocation = $locationService->loadLocation(5); - $childrenLocations = $locationService->loadLocationChildren($rootLocation); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationList', $childrenLocations); - self::assertInternalType('array', $childrenLocations->locations); - self::assertInternalType('int', $childrenLocations->totalCount); - self::assertNotEmpty($childrenLocations->locations); - - foreach ($childrenLocations->locations as $childLocation) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $childLocation); - self::assertEquals($rootLocation->id, $childLocation->parentLocationId); - } - } - - /** - * Test creating a location. - * - * @covers \eZ\Publish\API\Repository\LocationService::createLocation - */ - public function testCreateLocation() - { - $locationService = $this->repository->getLocationService(); - $contentService = $this->repository->getContentService(); - - $parentLocation = $locationService->loadLocation(44); - - $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocation->id); - $locationCreateStruct->priority = 42; - $locationCreateStruct->remoteId = 'new-remote-id'; - $locationCreateStruct->hidden = true; - $locationCreateStruct->sortField = Location::SORT_FIELD_DEPTH; - $locationCreateStruct->sortOrder = Location::SORT_ORDER_DESC; - - $contentInfo = $contentService->loadContentInfo(12); - - $createdLocation = $locationService->createLocation( - $contentInfo, - $locationCreateStruct - ); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $createdLocation); - self::assertGreaterThan(0, $createdLocation->id); - $createdPath = $parentLocation->path; - $createdPath[] = $createdLocation->id; - - $this->assertPropertiesCorrect( - array( - 'priority' => $locationCreateStruct->priority, - 'hidden' => $locationCreateStruct->hidden, - 'invisible' => $locationCreateStruct->hidden, - 'remoteId' => $locationCreateStruct->remoteId, - 'parentLocationId' => $locationCreateStruct->parentLocationId, - 'pathString' => $parentLocation->pathString . $createdLocation->id . '/', - 'path' => $createdPath, - 'depth' => $parentLocation->depth + 1, - 'sortField' => $locationCreateStruct->sortField, - 'sortOrder' => $locationCreateStruct->sortOrder, - ), - $createdLocation - ); - - self::assertEquals($contentInfo->id, $createdLocation->getContentInfo()->id); - } - - /** - * Test creating a location throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LocationService::createLocation - */ - public function testCreateLocationThrowsInvalidArgumentExceptionLocationExistsBelowParent() - { - $locationService = $this->repository->getLocationService(); - $contentService = $this->repository->getContentService(); - - $locationCreateStruct = $locationService->newLocationCreateStruct(5); - $contentInfo = $contentService->loadContentInfo(12); - $locationService->createLocation($contentInfo, $locationCreateStruct); - } - - /** - * Test creating a location throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LocationService::createLocation - */ - public function testCreateLocationThrowsInvalidArgumentExceptionExistingRemoteId() - { - $locationService = $this->repository->getLocationService(); - $contentService = $this->repository->getContentService(); - - $locationCreateStruct = $locationService->newLocationCreateStruct(2); - $locationCreateStruct->remoteId = '769380b7aa94541679167eab817ca893'; - $contentInfo = $contentService->loadContentInfo(4); - $locationService->createLocation($contentInfo, $locationCreateStruct); - } - - /** - * Test creating a location throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LocationService::createLocation - */ - public function testCreateLocationThrowsInvalidArgumentExceptionParentIsASubLocation() - { - $locationService = $this->repository->getLocationService(); - $contentService = $this->repository->getContentService(); - - $locationCreateStruct = $locationService->newLocationCreateStruct(44); - $contentInfo = $contentService->loadContentInfo(4); - $locationService->createLocation($contentInfo, $locationCreateStruct); - } - - /** - * Test updating location. - * - * @covers \eZ\Publish\API\Repository\LocationService::updateLocation - */ - public function testUpdateLocation() - { - $locationService = $this->repository->getLocationService(); - - $location = $locationService->loadLocation(5); - $locationUpdateStruct = $locationService->newLocationUpdateStruct(); - $locationUpdateStruct->priority = 42; - $locationUpdateStruct->sortField = Location::SORT_FIELD_DEPTH; - $locationUpdateStruct->sortOrder = Location::SORT_ORDER_DESC; - $locationUpdateStruct->remoteId = 'NEW_REMOTE_ID'; - - $location = $locationService->updateLocation($location, $locationUpdateStruct); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); - - $this->assertPropertiesCorrect( - array( - 'priority' => $locationUpdateStruct->priority, - 'sortField' => $locationUpdateStruct->sortField, - 'sortOrder' => $locationUpdateStruct->sortOrder, - 'remoteId' => $locationUpdateStruct->remoteId, - ), - $location - ); - } - - /** - * Test updating location throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\LocationService::updateLocation - */ - public function testUpdateLocationThrowsInvalidArgumentException() - { - $locationService = $this->repository->getLocationService(); - - $location = $locationService->loadLocation(5); - $locationUpdateStruct = $locationService->newLocationUpdateStruct(); - $locationUpdateStruct->remoteId = '769380b7aa94541679167eab817ca893'; - - $locationService->updateLocation($location, $locationUpdateStruct); - } - - /** - * Test swapping location. - * - * @covers \eZ\Publish\API\Repository\LocationService::swapLocation - */ - public function testSwapLocation() - { - $locationService = $this->repository->getLocationService(); - - $location1 = $locationService->loadLocation(2); - $location2 = $locationService->loadLocation(44); - - $contentId1 = $location1->getContentInfo()->id; - $contentId2 = $location2->getContentInfo()->id; - - $locationService->swapLocation($location1, $location2); - - $location1 = $locationService->loadLocation(2); - $location2 = $locationService->loadLocation(44); - - self::assertEquals($contentId1, $location2->getContentInfo()->id); - self::assertEquals($contentId2, $location1->getContentInfo()->id); - } - - /** - * Test hiding & unhiding a location. - * - * @covers \eZ\Publish\API\Repository\LocationService::hideLocation - * @covers \eZ\Publish\API\Repository\LocationService::unhideLocation - */ - public function testHideUnhideLocation() - { - $locationService = $this->repository->getLocationService(); - - $location = $locationService->loadLocation(5); - $location = $locationService->hideLocation($location); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); - self::assertEquals(true, $location->hidden); - self::assertEquals(true, $location->invisible); - - $location = $locationService->unhideLocation($location); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); - self::assertEquals(false, $location->hidden); - self::assertEquals(false, $location->invisible); - } - - /** - * Test moving a subtree. - * - * @covers \eZ\Publish\API\Repository\LocationService::moveSubtree - */ - public function testMoveSubtree() - { - $locationService = $this->repository->getLocationService(); - - $locationToMove = $locationService->loadLocation(13); - $newParent = $locationService->loadLocation(44); - $locationService->moveSubtree($locationToMove, $newParent); - - $loadedLocation = $locationService->loadLocation($locationToMove->id); - self::assertEquals($newParent->id, $loadedLocation->parentLocationId); - } - - /** - * Test deleting a location. - * - * @covers \eZ\Publish\API\Repository\LocationService::deleteLocation - */ - public function testDeleteLocation() - { - $locationService = $this->repository->getLocationService(); - - $location = $locationService->loadLocation(44); - $locationService->deleteLocation($location); - - try { - $locationService->loadLocation($location->id); - self::fail('failed deleting a location'); - } catch (NotFoundException $e) { - // Do nothing - } - } - - /** - * Test creating new LocationCreateStruct. - * - * @covers \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct - */ - public function testNewLocationCreateStruct() - { - $locationService = $this->repository->getLocationService(); - - $locationCreateStruct = $locationService->newLocationCreateStruct(2); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationCreateStruct', $locationCreateStruct); - - $this->assertPropertiesCorrect( - array( - 'priority' => 0, - 'hidden' => false, - 'remoteId' => null, - 'sortField' => Location::SORT_FIELD_NAME, - 'sortOrder' => Location::SORT_ORDER_ASC, - 'parentLocationId' => 2, - ), - $locationCreateStruct - ); - } - - /** - * Test creating new LocationUpdateStruct. - * - * @covers \eZ\Publish\API\Repository\LocationService::newLocationUpdateStruct - */ - public function testNewLocationUpdateStruct() - { - $locationService = $this->repository->getLocationService(); - - $locationUpdateStruct = $locationService->newLocationUpdateStruct(); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationUpdateStruct', $locationUpdateStruct); - - $this->assertPropertiesCorrect( - array( - 'priority' => null, - 'remoteId' => null, - 'sortField' => null, - 'sortOrder' => null, - ), - $locationUpdateStruct - ); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/NameSchemaBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/NameSchemaBase.php deleted file mode 100644 index 7409ee736c9..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/NameSchemaBase.php +++ /dev/null @@ -1,303 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\NameSchemaBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\Core\Repository\Values\Content\Content; -use eZ\Publish\Core\Repository\Values\Content\VersionInfo; -use eZ\Publish\Core\Repository\Values\ContentType\ContentType; -use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; -use eZ\Publish\API\Repository\Values\Content\Field; -use eZ\Publish\Core\FieldType\TextLine\Value as TextLineValue; - -/** - * Test case for NameSchema service. - */ -abstract class NameSchemaBase extends BaseServiceTest -{ - /** - * Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. - * - * @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolve - * @dataProvider providerForTestResolve - */ - public function testResolve($nameSchema, $expectedName) - { - $service = $this->repository->getNameSchemaService(); - - list($content, $contentType) = $this->buildTestObjects(); - - $name = $service->resolve( - $nameSchema, - $contentType, - $content->fields, - $content->versionInfo->languageCodes - ); - - self::assertEquals($expectedName, $name); - } - - /** - * Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. - * - * @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolve - */ - public function testResolveWithSettings() - { - $service = $this->repository->getNameSchemaService(); - - $this->setConfiguration( - $service, - array( - 'limit' => 38, - 'sequence' => '...', - ) - ); - - list($content, $contentType) = $this->buildTestObjects(); - - $name = $service->resolve( - 'Hello, <text1> and <text2> and then goodbye and hello again', - $contentType, - $content->fields, - $content->versionInfo->languageCodes - ); - - self::assertEquals( - array( - 'eng-GB' => 'Hello, one and two and then goodbye...', - 'cro-HR' => 'Hello, jedan and dva and then goodb...', - ), - $name - ); - } - - /** - */ - public function providerForTestResolve() - { - return array( - array( - '<text1>', - array( - 'eng-GB' => 'one', - 'cro-HR' => 'jedan', - ), - ), - array( - '<text1> <text2>', - array( - 'eng-GB' => 'one two', - 'cro-HR' => 'jedan dva', - ), - ), - array( - 'Hello <text1>', - array( - 'eng-GB' => 'Hello one', - 'cro-HR' => 'Hello jedan', - ), - ), - array( - 'Hello, <text1> and <text2> and then goodbye', - array( - 'eng-GB' => 'Hello, one and two and then goodbye', - 'cro-HR' => 'Hello, jedan and dva and then goodbye', - ), - ), - array( - '<text1|text2>', - array( - 'eng-GB' => 'one', - 'cro-HR' => 'jedan', - ), - ), - array( - '<text2|text1>', - array( - 'eng-GB' => 'two', - 'cro-HR' => 'dva', - ), - ), - array( - '<text3|text1>', - array( - 'eng-GB' => 'one', - 'cro-HR' => 'jedan', - ), - ), - array( - '<(<text1> <text2>)>', - array( - 'eng-GB' => 'one two', - 'cro-HR' => 'jedan dva', - ), - ), - array( - '<(<text3|text2>)>', - array( - 'eng-GB' => 'two', - 'cro-HR' => 'dva', - ), - ), - array( - '<text3|(<text3|text2>)>', - array( - 'eng-GB' => 'two', - 'cro-HR' => 'dva', - ), - ), - array( - '<text3|(Hello <text2> and <text1>!)>', - array( - 'eng-GB' => 'Hello two and one!', - 'cro-HR' => 'Hello dva and jedan!', - ), - ), - array( - '<text3|(Hello <text3> and <text1>)|text2>!', - array( - 'eng-GB' => 'Hello and one!', - 'cro-HR' => 'Hello and jedan!', - ), - ), - array( - '<text3|(Hello <text3|text2> and <text1>)|text2>!', - array( - 'eng-GB' => 'Hello two and one!', - 'cro-HR' => 'Hello dva and jedan!', - ), - ), - ); - } - - /** - * @return \eZ\Publish\API\Repository\Values\Content\Field[] - */ - protected function getFields() - { - return array( - new Field( - array( - 'languageCode' => 'eng-GB', - 'fieldDefIdentifier' => 'text1', - 'value' => new TextLineValue('one'), - ) - ), - new Field( - array( - 'languageCode' => 'eng-GB', - 'fieldDefIdentifier' => 'text2', - 'value' => new TextLineValue('two'), - ) - ), - new Field( - array( - 'languageCode' => 'eng-GB', - 'fieldDefIdentifier' => 'text3', - 'value' => new TextLineValue(''), - ) - ), - new Field( - array( - 'languageCode' => 'cro-HR', - 'fieldDefIdentifier' => 'text1', - 'value' => new TextLineValue('jedan'), - ) - ), - new Field( - array( - 'languageCode' => 'cro-HR', - 'fieldDefIdentifier' => 'text2', - 'value' => new TextLineValue('dva'), - ) - ), - new Field( - array( - 'languageCode' => 'cro-HR', - 'fieldDefIdentifier' => 'text3', - 'value' => new TextLineValue(''), - ) - ), - ); - } - - /** - * @return \eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition[] - */ - protected function getFieldDefinitions() - { - return array( - new FieldDefinition( - array( - 'id' => '1', - 'identifier' => 'text1', - 'fieldTypeIdentifier' => 'ezstring', - ) - ), - new FieldDefinition( - array( - 'id' => '2', - 'identifier' => 'text2', - 'fieldTypeIdentifier' => 'ezstring', - ) - ), - new FieldDefinition( - array( - 'id' => '3', - 'identifier' => 'text3', - 'fieldTypeIdentifier' => 'ezstring', - ) - ), - ); - } - - /** - * Builds stubbed content for testing purpose. - * - * @return \eZ\Publish\API\Repository\Values\Content\Content - */ - protected function buildTestObjects($nameSchema = '<name_schema>', $urlAliasSchema = '<urlalias_schema>') - { - $contentType = new ContentType( - array( - 'nameSchema' => $nameSchema, - 'urlAliasSchema' => $urlAliasSchema, - 'fieldDefinitions' => $this->getFieldDefinitions(), - ) - ); - $content = new Content( - array( - 'internalFields' => $this->getFields(), - 'versionInfo' => new VersionInfo( - array( - 'languageCodes' => array('eng-GB', 'cro-HR'), - ) - ), - ) - ); - - return array($content, $contentType); - } - - /** - * @param object $service - * @param array $configuration - */ - protected function setConfiguration($service, array $configuration) - { - $refObject = new \ReflectionObject($service); - $refProperty = $refObject->getProperty('settings'); - $refProperty->setAccessible(true); - $refProperty->setValue( - $service, - $configuration - ); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/ObjectStateBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/ObjectStateBase.php deleted file mode 100644 index 0660666469a..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/ObjectStateBase.php +++ /dev/null @@ -1,967 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\ObjectStateBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\Core\Repository\Values\ObjectState\ObjectState; -use eZ\Publish\Core\Repository\Values\ObjectState\ObjectStateGroup; -use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; -use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; -use eZ\Publish\API\Repository\Exceptions\NotFoundException; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; - -/** - * Test case for object state Service. - */ -abstract class ObjectStateBase extends BaseServiceTest -{ - /** - * Test a new class and default values on properties. - * - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__construct - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__construct - */ - public function testNewClass() - { - $objectState = new ObjectState(); - - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'identifier' => null, - 'priority' => null, - 'defaultLanguageCode' => null, - 'languageCodes' => null, - 'names' => array(), - 'descriptions' => array(), - ), - $objectState - ); - - $objectStateGroup = new ObjectStateGroup(); - - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'identifier' => null, - 'defaultLanguageCode' => null, - 'languageCodes' => null, - 'names' => array(), - 'descriptions' => array(), - ), - $objectStateGroup - ); - } - - /** - * Test retrieving missing property. - * - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__get - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__get - */ - public function testMissingProperty() - { - try { - $objectState = new ObjectState(); - $value = $objectState->notDefined; - $this->fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - - try { - $objectStateGroup = new ObjectStateGroup(); - $value = $objectStateGroup->notDefined; - $this->fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - } - - /** - * Test setting read only property. - * - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__set - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__set - */ - public function testReadOnlyProperty() - { - try { - $objectState = new ObjectState(); - $objectState->id = 42; - $this->fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - - try { - $objectStateGroup = new ObjectStateGroup(); - $objectStateGroup->id = 42; - $this->fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test if property exists. - * - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__isset - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__isset - */ - public function testIsPropertySet() - { - $objectState = new ObjectState(); - $value = isset($objectState->notDefined); - $this->assertEquals(false, $value); - - $value = isset($objectState->id); - $this->assertEquals(true, $value); - - $objectStateGroup = new ObjectStateGroup(); - $value = isset($objectStateGroup->notDefined); - $this->assertEquals(false, $value); - - $value = isset($objectStateGroup->id); - $this->assertEquals(true, $value); - } - - /** - * Test unsetting a property. - * - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__unset - * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__unset - */ - public function testUnsetProperty() - { - $objectState = new ObjectState(array('id' => 2)); - try { - unset($objectState->id); - $this->fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - - $objectStateGroup = new ObjectStateGroup(array('id' => 2)); - try { - unset($objectStateGroup->id); - $this->fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test service method for creating object state group. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::createObjectStateGroup - */ - public function testCreateGroup() - { - $objectStateService = $this->repository->getObjectStateService(); - - $groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('test'); - $groupCreateStruct->defaultLanguageCode = 'eng-GB'; - $groupCreateStruct->names = array('eng-GB' => 'Test'); - $groupCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $createdGroup = $objectStateService->createObjectStateGroup($groupCreateStruct); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $createdGroup - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 3, - 'identifier' => 'test', - 'defaultLanguageCode' => 'eng-GB', - 'languageCodes' => array('eng-GB'), - 'names' => array('eng-GB' => 'Test'), - 'descriptions' => array('eng-GB' => 'Test description'), - ), - $createdGroup - ); - } - - /** - * Test service method for creating object state group throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\ObjectStateService::createObjectStateGroup - */ - public function testCreateGroupThrowsInvalidArgumentException() - { - $objectStateService = $this->repository->getObjectStateService(); - - $groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('ez_lock'); - $groupCreateStruct->defaultLanguageCode = 'eng-GB'; - $groupCreateStruct->names = array('eng-GB' => 'Test'); - $groupCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $objectStateService->createObjectStateGroup($groupCreateStruct); - } - - /** - * Test service method for loading object state group. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroup - */ - public function testLoadObjectStateGroup() - { - $group = $this->repository->getObjectStateService()->loadObjectStateGroup(2); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $group - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 2, - 'identifier' => 'ez_lock', - 'defaultLanguageCode' => 'eng-US', - 'languageCodes' => array('eng-US'), - 'names' => array('eng-US' => 'Lock'), - 'descriptions' => array('eng-US' => ''), - ), - $group - ); - } - - /** - * Test service method for loading object state group throwing NotFoundException. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroup - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadObjectStateGroupThrowsNotFoundException() - { - $this->repository->getObjectStateService()->loadObjectStateGroup(APIBaseTest::DB_INT_MAX); - } - - /** - * Test service method for loading object state groups. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroups - */ - public function testLoadObjectStateGroups() - { - $groups = $this->repository->getObjectStateService()->loadObjectStateGroups(); - - $this->assertInternalType('array', $groups); - $this->assertCount(1, $groups); - - foreach ($groups as $group) { - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $group - ); - } - } - - /** - * Test service method for loading object states within a group. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::loadObjectStates - */ - public function testLoadObjectStates() - { - $objectStateService = $this->repository->getObjectStateService(); - $group = $objectStateService->loadObjectStateGroup(2); - $states = $this->repository->getObjectStateService()->loadObjectStates($group); - - $this->assertInternalType('array', $states); - $this->assertCount(2, $states); - - $priority = 0; - foreach ($states as $state) { - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $state - ); - - $this->assertEquals($group->id, $state->getObjectStateGroup()->id); - $this->assertEquals($priority, $state->priority); - ++$priority; - } - } - - /** - * Test service method for updating object state group. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup - */ - public function testUpdateObjectStateGroup() - { - $objectStateService = $this->repository->getObjectStateService(); - - $groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); - $groupUpdateStruct->identifier = 'test'; - $groupUpdateStruct->defaultLanguageCode = 'eng-GB'; - $groupUpdateStruct->names = array('eng-GB' => 'Test'); - $groupUpdateStruct->descriptions = array('eng-GB' => 'Test description'); - - $group = $objectStateService->loadObjectStateGroup(2); - - $updatedGroup = $objectStateService->updateObjectStateGroup($group, $groupUpdateStruct); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $updatedGroup - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 2, - 'identifier' => 'test', - 'defaultLanguageCode' => 'eng-GB', - 'languageCodes' => array('eng-GB'), - 'names' => array('eng-GB' => 'Test'), - 'descriptions' => array('eng-GB' => 'Test description'), - ), - $updatedGroup - ); - } - - /** - * Test service method for partially updating object state group. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup - */ - public function testPartiallyUpdateObjectStateGroup() - { - $objectStateService = $this->repository->getObjectStateService(); - - $groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); - $groupUpdateStruct->defaultLanguageCode = 'eng-GB'; - $groupUpdateStruct->names = array('eng-GB' => 'Test'); - - $group = $objectStateService->loadObjectStateGroup(2); - - $updatedGroup = $objectStateService->updateObjectStateGroup($group, $groupUpdateStruct); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $updatedGroup - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 2, - 'identifier' => 'ez_lock', - 'defaultLanguageCode' => 'eng-GB', - 'languageCodes' => array('eng-GB'), - 'names' => array('eng-GB' => 'Test'), - // descriptions array should have an empty value for eng-GB - // without the original descriptions - // since the descriptions were not in the update struct and we're changing default language - 'descriptions' => array('eng-GB' => ''), - ), - $updatedGroup - ); - } - - /** - * Test service method for updating object state group throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup - */ - public function testUpdateObjectStateGroupThrowsInvalidArgumentException() - { - $objectStateService = $this->repository->getObjectStateService(); - - $groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('test'); - $groupCreateStruct->defaultLanguageCode = 'eng-GB'; - $groupCreateStruct->names = array('eng-GB' => 'Test'); - $groupCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $createdGroup = $objectStateService->createObjectStateGroup($groupCreateStruct); - - $groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); - $groupUpdateStruct->identifier = 'ez_lock'; - - $objectStateService->updateObjectStateGroup($createdGroup, $groupUpdateStruct); - } - - /** - * Test service method for deleting object state group. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::deleteObjectStateGroup - */ - public function testDeleteObjectStateGroup() - { - $objectStateService = $this->repository->getObjectStateService(); - - $group = $objectStateService->loadObjectStateGroup(2); - - $objectStateService->deleteObjectStateGroup($group); - - try { - $objectStateService->loadObjectStateGroup(2); - $this->fail('Successfully loaded object state group after deleting it'); - } catch (NotFoundException $e) { - // Do nothing - } - - try { - $objectStateService->loadObjectState(1); - $this->fail('Successfully loaded object state from deleted group'); - } catch (NotFoundException $e) { - // Do nothing - } - - try { - $objectStateService->loadObjectState(2); - $this->fail('Successfully loaded object state from deleted group'); - } catch (NotFoundException $e) { - // Do nothing - } - } - - /** - * Test service method for creating object state. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::createObjectState - */ - public function testCreateObjectState() - { - $objectStateService = $this->repository->getObjectStateService(); - - $group = $objectStateService->loadObjectStateGroup(2); - - $stateCreateStruct = $objectStateService->newObjectStateCreateStruct('test'); - $stateCreateStruct->priority = 2; - $stateCreateStruct->defaultLanguageCode = 'eng-GB'; - $stateCreateStruct->names = array('eng-GB' => 'Test'); - $stateCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $createdState = $objectStateService->createObjectState( - $group, - $stateCreateStruct - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $createdState - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 3, - 'identifier' => 'test', - 'priority' => 2, - 'defaultLanguageCode' => 'eng-GB', - 'languageCodes' => array('eng-GB'), - 'names' => array('eng-GB' => 'Test'), - 'descriptions' => array('eng-GB' => 'Test description'), - ), - $createdState - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $createdState->getObjectStateGroup() - ); - - $this->assertEquals($group->id, $createdState->getObjectStateGroup()->id); - } - - /** - * Test service method for creating object state in empty group. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::createObjectState - */ - public function testCreateObjectStateInEmptyGroup() - { - $objectStateService = $this->repository->getObjectStateService(); - - $groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('test'); - $groupCreateStruct->defaultLanguageCode = 'eng-GB'; - $groupCreateStruct->names = array('eng-GB' => 'Test'); - $groupCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $createdGroup = $objectStateService->createObjectStateGroup($groupCreateStruct); - - $stateCreateStruct = $objectStateService->newObjectStateCreateStruct('test'); - $stateCreateStruct->priority = 2; - $stateCreateStruct->defaultLanguageCode = 'eng-GB'; - $stateCreateStruct->names = array('eng-GB' => 'Test'); - $stateCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $createdState = $objectStateService->createObjectState( - $createdGroup, - $stateCreateStruct - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $createdState - ); - - $this->assertNotNull($createdState->id); - $this->assertPropertiesCorrect( - array( - 'identifier' => 'test', - 'priority' => 0, - 'defaultLanguageCode' => 'eng-GB', - 'languageCodes' => array('eng-GB'), - 'names' => array('eng-GB' => 'Test'), - 'descriptions' => array('eng-GB' => 'Test description'), - ), - $createdState - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $createdState->getObjectStateGroup() - ); - - $this->assertEquals($createdGroup->id, $createdState->getObjectStateGroup()->id); - $this->assertGreaterThan(0, $objectStateService->getContentCount($createdState)); - } - - /** - * Test service method for creating object state throwing InvalidArgumentException. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::createObjectState - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - */ - public function testCreateObjectStateThrowsInvalidArgumentException() - { - $objectStateService = $this->repository->getObjectStateService(); - - $group = $objectStateService->loadObjectStateGroup(2); - - $stateCreateStruct = $objectStateService->newObjectStateCreateStruct('not_locked'); - $stateCreateStruct->priority = 2; - $stateCreateStruct->defaultLanguageCode = 'eng-GB'; - $stateCreateStruct->names = array('eng-GB' => 'Test'); - $stateCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $objectStateService->createObjectState( - $group, - $stateCreateStruct - ); - } - - /** - * Test service method for loading object state. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::loadObjectState - */ - public function testLoadObjectState() - { - $state = $this->repository->getObjectStateService()->loadObjectState(1); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $state - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'identifier' => 'not_locked', - 'priority' => 0, - 'defaultLanguageCode' => 'eng-US', - 'languageCodes' => array('eng-US'), - 'names' => array('eng-US' => 'Not locked'), - 'descriptions' => array('eng-US' => ''), - ), - $state - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $state->getObjectStateGroup() - ); - - $this->assertEquals(2, $state->getObjectStateGroup()->id); - } - - /** - * Test service method for loading object state throwing NotFoundException. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::loadObjectState - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testLoadObjectStateThrowsNotFoundException() - { - $this->repository->getObjectStateService()->loadObjectState(APIBaseTest::DB_INT_MAX); - } - - /** - * Test service method for updating object state. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectState - */ - public function testUpdateObjectState() - { - $objectStateService = $this->repository->getObjectStateService(); - - $stateUpdateStruct = $objectStateService->newObjectStateUpdateStruct(); - $stateUpdateStruct->identifier = 'test'; - $stateUpdateStruct->defaultLanguageCode = 'eng-GB'; - $stateUpdateStruct->names = array('eng-GB' => 'Test'); - $stateUpdateStruct->descriptions = array('eng-GB' => 'Test description'); - - $state = $objectStateService->loadObjectState(1); - - $updatedState = $objectStateService->updateObjectState($state, $stateUpdateStruct); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $updatedState - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'identifier' => 'test', - 'priority' => 0, - 'defaultLanguageCode' => 'eng-GB', - 'languageCodes' => array('eng-GB'), - 'names' => array('eng-GB' => 'Test'), - 'descriptions' => array('eng-GB' => 'Test description'), - ), - $updatedState - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $updatedState->getObjectStateGroup() - ); - - $this->assertEquals($state->getObjectStateGroup()->id, $updatedState->getObjectStateGroup()->id); - } - - /** - * Test service method for partially updating object state. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectState - */ - public function testPartiallyUpdateObjectState() - { - $objectStateService = $this->repository->getObjectStateService(); - - $stateUpdateStruct = $objectStateService->newObjectStateUpdateStruct(); - $stateUpdateStruct->identifier = 'test'; - $stateUpdateStruct->names = array('eng-US' => 'Test'); - - $state = $objectStateService->loadObjectState(1); - - $updatedState = $objectStateService->updateObjectState($state, $stateUpdateStruct); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $updatedState - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'identifier' => 'test', - 'priority' => 0, - 'defaultLanguageCode' => 'eng-US', - 'languageCodes' => array('eng-US'), - 'names' => array('eng-US' => 'Test'), - // Original value of empty description for eng-US should be kept - 'descriptions' => array('eng-US' => ''), - ), - $updatedState - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $updatedState->getObjectStateGroup() - ); - - $this->assertEquals($state->getObjectStateGroup()->id, $updatedState->getObjectStateGroup()->id); - } - - /** - * Test service method for updating object state throwing InvalidArgumentException. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectState - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - */ - public function testUpdateObjectStateThrowsInvalidArgumentException() - { - $objectStateService = $this->repository->getObjectStateService(); - - $stateUpdateStruct = $objectStateService->newObjectStateUpdateStruct(); - $stateUpdateStruct->identifier = 'locked'; - - $state = $objectStateService->loadObjectState(1); - - $objectStateService->updateObjectState($state, $stateUpdateStruct); - } - - /** - * Test service method for setting the priority of object state. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::setPriorityOfObjectState - */ - public function testSetPriorityOfObjectState() - { - $objectStateService = $this->repository->getObjectStateService(); - - $state = $objectStateService->loadObjectState(2); - $objectStateService->setPriorityOfObjectState($state, 0); - - $firstState = $objectStateService->loadObjectState(1); - $this->assertEquals(1, $firstState->priority); - - $secondState = $objectStateService->loadObjectState(2); - $this->assertEquals(0, $secondState->priority); - } - - /** - * Test service method for deleting object state. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::deleteObjectState - */ - public function testDeleteObjectState() - { - $objectStateService = $this->repository->getObjectStateService(); - - $state = $objectStateService->loadObjectState(1); - $objectStateService->deleteObjectState($state); - - try { - $objectStateService->loadObjectState(1); - $this->fail('Successfully loaded object state after deleting it'); - } catch (NotFoundException $e) { - // Do nothing - } - - $this->assertEquals(0, $objectStateService->getContentCount($state)); - $this->assertGreaterThan( - 0, - $objectStateService->getContentCount( - $objectStateService->loadObjectState(2) - ) - ); - } - - /** - * Test service method for setting the object state to content. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::setContentState - */ - public function testSetContentState() - { - $objectStateService = $this->repository->getObjectStateService(); - - $state = $objectStateService->loadObjectState(2); - $group = $state->getObjectStateGroup(); - $contentInfo = $this->repository->getContentService()->loadContentInfo(4); - $objectStateService->setContentState( - $contentInfo, - $group, - $state - ); - - $newObjectState = $objectStateService->getContentState($contentInfo, $group); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $newObjectState - ); - - $this->assertEquals(2, $newObjectState->id); - } - - /** - * Test service method for setting the object state to content throwing InvalidArgumentException. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::setContentState - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - */ - public function testSetContentStateThrowsInvalidArgumentException() - { - $objectStateService = $this->repository->getObjectStateService(); - - $groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('test'); - $groupCreateStruct->defaultLanguageCode = 'eng-GB'; - $groupCreateStruct->names = array('eng-GB' => 'Test'); - $groupCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $createdGroup = $objectStateService->createObjectStateGroup($groupCreateStruct); - - $stateCreateStruct = $objectStateService->newObjectStateCreateStruct('test'); - $stateCreateStruct->priority = 2; - $stateCreateStruct->defaultLanguageCode = 'eng-GB'; - $stateCreateStruct->names = array('eng-GB' => 'Test'); - $stateCreateStruct->descriptions = array('eng-GB' => 'Test description'); - - $createdState = $objectStateService->createObjectState( - $createdGroup, - $stateCreateStruct - ); - - $objectStateService->setContentState( - $this->repository->getContentService()->loadContentInfo(4), - $objectStateService->loadObjectStateGroup(2), - $createdState - ); - } - - /** - * Test service method for getting the object state of content. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::getContentState - */ - public function testGetContentState() - { - $objectStateService = $this->repository->getObjectStateService(); - - $objectState = $objectStateService->getContentState( - $this->repository->getContentService()->loadContentInfo(4), - $objectStateService->loadObjectStateGroup(2) - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', - $objectState - ); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'identifier' => 'not_locked', - 'priority' => 0, - 'defaultLanguageCode' => 'eng-US', - 'languageCodes' => array('eng-US'), - 'names' => array('eng-US' => 'Not locked'), - 'descriptions' => array('eng-US' => ''), - ), - $objectState - ); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', - $objectState->getObjectStateGroup() - ); - - $this->assertEquals(2, $objectState->getObjectStateGroup()->id); - } - - /** - * Test service method for getting the count of content assigned to object state. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::getContentCount - */ - public function testGetContentCount() - { - $objectStateService = $this->repository->getObjectStateService(); - $state = $objectStateService->loadObjectState(1); - $count = $objectStateService->getContentCount($state); - - $this->assertGreaterThan(0, $count); - } - - /** - * Test service method for creating a new object state create struct object. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::newObjectStateCreateStruct - */ - public function testNewObjectStateCreateStruct() - { - $objectStateCreateStruct = $this->repository->getObjectStateService()->newObjectStateCreateStruct('test'); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateCreateStruct', - $objectStateCreateStruct - ); - - $this->assertPropertiesCorrect( - array( - 'identifier' => 'test', - 'priority' => false, - 'defaultLanguageCode' => null, - 'names' => null, - 'descriptions' => null, - ), - $objectStateCreateStruct - ); - } - - /** - * Test service method for creating a new object state update struct object. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::newObjectStateUpdateStruct - */ - public function testNewObjectStateUpdateStruct() - { - $objectStateUpdateStruct = $this->repository->getObjectStateService()->newObjectStateUpdateStruct(); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateUpdateStruct', - $objectStateUpdateStruct - ); - - $this->assertPropertiesCorrect( - array( - 'identifier' => null, - 'defaultLanguageCode' => null, - 'names' => null, - 'descriptions' => null, - ), - $objectStateUpdateStruct - ); - } - - /** - * Test service method for creating a new object state group create struct object. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::newObjectStateGroupCreateStruct - */ - public function testNewObjectStateGroupCreateStruct() - { - $objectStateGroupCreateStruct = $this->repository->getObjectStateService()->newObjectStateGroupCreateStruct('test'); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroupCreateStruct', - $objectStateGroupCreateStruct - ); - - $this->assertPropertiesCorrect( - array( - 'identifier' => 'test', - 'defaultLanguageCode' => null, - 'names' => null, - 'descriptions' => null, - ), - $objectStateGroupCreateStruct - ); - } - - /** - * Test service method for creating a new object state group update struct object. - * - * @covers \eZ\Publish\API\Repository\ObjectStateService::newObjectStateGroupUpdateStruct - */ - public function testNewObjectStateGroupUpdateStruct() - { - $objectStateGroupUpdateStruct = $this->repository->getObjectStateService()->newObjectStateGroupUpdateStruct(); - - $this->assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroupUpdateStruct', - $objectStateGroupUpdateStruct - ); - - $this->assertPropertiesCorrect( - array( - 'identifier' => null, - 'defaultLanguageCode' => null, - 'names' => null, - 'descriptions' => null, - ), - $objectStateGroupUpdateStruct - ); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/RepositoryTest.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/RepositoryTest.php deleted file mode 100644 index 3a5208f8963..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/RepositoryTest.php +++ /dev/null @@ -1,170 +0,0 @@ -<?php - -/** - * File containing the RepositoryTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; - -/** - * @group repository - */ -abstract class RepositoryTest extends BaseServiceTest -{ - /** - * Test repository instance. - * - * @covers \eZ\Publish\API\Repository\Repository - */ - public function testRepositoryInstance() - { - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Repository', $this->repository); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getContentService - */ - public function testGetContentService() - { - $service = $this->repository->getContentService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\ContentService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getContentTypeService - */ - public function testGetContentTypeService() - { - $service = $this->repository->getContentTypeService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\ContentTypeService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getFieldTypeService - */ - public function testGetFieldTypeService() - { - $service = $this->repository->getFieldTypeService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\FieldTypeService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getContentLanguageService - */ - public function testGetContentLanguageService() - { - $service = $this->repository->getContentLanguageService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\LanguageService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getLocationService - */ - public function testGetLocationService() - { - $service = $this->repository->getLocationService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\LocationService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getObjectStateService - */ - public function testGetObjectStateService() - { - $service = $this->repository->getObjectStateService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\ObjectStateService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getRoleService - */ - public function testGetRoleService() - { - $service = $this->repository->getRoleService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\RoleService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getSearchService - */ - public function testGetSearchService() - { - $service = $this->repository->getSearchService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\SearchService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getSectionService - */ - public function testGetSectionService() - { - $service = $this->repository->getSectionService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\SectionService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getTrashService - */ - public function testGetTrashService() - { - $service = $this->repository->getTrashService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\TrashService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getURLAliasService - */ - public function testGetURLAliasService() - { - $service = $this->repository->getURLAliasService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\URLAliasService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getURLWildcardService - */ - public function testGetURLWildcardService() - { - $service = $this->repository->getURLWildcardService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\URLWildcardService', $service); - } - - /** - * Test service method. - * - * @covers \eZ\Publish\API\Repository\Repository::getUserService - */ - public function testGetUserService() - { - $service = $this->repository->getUserService(); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\UserService', $service); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/RoleBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/RoleBase.php deleted file mode 100644 index 0887192acb3..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/RoleBase.php +++ /dev/null @@ -1,924 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\RoleBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\Core\Repository\Values\User\Role; -use eZ\Publish\Core\Repository\Values\User\Policy; -use eZ\Publish\API\Repository\Values\User\Limitation; -use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; -use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; -use eZ\Publish\API\Repository\Exceptions\NotFoundException; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; -use Exception; - -/** - * Test case for Role Service. - */ -abstract class RoleBase extends BaseServiceTest -{ - /** - * Test a new class and default values on properties. - * - * @covers \eZ\Publish\API\Repository\Values\User\Role::__construct - * @covers \eZ\Publish\API\Repository\Values\User\Policy::__construct - */ - public function testNewClass() - { - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'identifier' => null, - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // 'mainLanguageCode' => null, - 'policies' => array(), - ), - new Role() - ); - - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'roleId' => null, - 'module' => null, - 'function' => null, - 'limitations' => array(), - ), - new Policy() - ); - } - - /** - * Test retrieving missing property. - * - * @covers \eZ\Publish\API\Repository\Values\User\Role::__get - * @covers \eZ\Publish\API\Repository\Values\User\Policy::__get - */ - public function testMissingProperty() - { - try { - $role = new Role(); - $value = $role->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - - try { - $policy = new Policy(); - $value = $policy->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - } - - /** - * Test setting read only property. - * - * @covers \eZ\Publish\API\Repository\Values\User\Role::__set - * @covers \eZ\Publish\API\Repository\Values\User\Policy::__set - */ - public function testReadOnlyProperty() - { - try { - $role = new Role(); - $role->id = 42; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - - try { - $policy = new Policy(); - $policy->id = 42; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test if property exists. - * - * @covers \eZ\Publish\API\Repository\Values\User\Role::__isset - * @covers \eZ\Publish\API\Repository\Values\User\Policy::__isset - */ - public function testIsPropertySet() - { - $role = new Role(); - $value = isset($role->notDefined); - self::assertEquals(false, $value); - - $value = isset($role->id); - self::assertEquals(true, $value); - - $policy = new Policy(); - $value = isset($policy->notDefined); - self::assertEquals(false, $value); - - $value = isset($policy->id); - self::assertEquals(true, $value); - } - - /** - * Test unsetting a property. - * - * @covers \eZ\Publish\API\Repository\Values\User\Role::__unset - * @covers \eZ\Publish\API\Repository\Values\User\Policy::__unset - */ - public function testUnsetProperty() - { - $role = new Role(array('id' => 1)); - try { - unset($role->id); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - - $policy = new Policy(array('id' => 1)); - try { - unset($policy->id); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test creating a role. - * - * @covers \eZ\Publish\API\Repository\RoleService::createRole - */ - public function testCreateRole() - { - $roleService = $this->repository->getRoleService(); - $roleCreateStruct = $roleService->newRoleCreateStruct('ultimate_permissions'); - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // $roleCreateStruct->mainLanguageCode = 'eng-GB'; - // $roleCreateStruct->names = array( 'eng-GB' => 'Ultimate permissions' ); - // $roleCreateStruct->descriptions = array( 'eng-GB' => 'This is a role with ultimate permissions' ); - - $createdRole = $roleService->createRole($roleCreateStruct); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $createdRole); - self::assertGreaterThan(0, $createdRole->id); - - /* @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - self::assertEquals( - array( - 'eng-GB' => $roleCreateStruct->names['eng-GB'] - ), - $createdRole->getNames() - ); - - self::assertEquals( - array( - 'eng-GB' => $roleCreateStruct->descriptions['eng-GB'] - ), - $createdRole->getDescriptions() - ); - */ - - $this->assertPropertiesCorrect( - array( - 'identifier' => $roleCreateStruct->identifier, - 'policies' => array(), - ), - $createdRole - ); - } - - /** - * Test creating a role throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\RoleService::createRole - */ - public function testCreateRoleThrowsInvalidArgumentException() - { - $roleService = $this->repository->getRoleService(); - $roleCreateStruct = $roleService->newRoleCreateStruct('Anonymous'); - - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // $roleCreateStruct->mainLanguageCode = 'eng-GB'; - // $roleCreateStruct->names = array( 'eng-GB' => 'Anonymous' ); - // $roleCreateStruct->descriptions = array( 'eng-GB' => 'Anonymous role' ); - - $roleService->createRole($roleCreateStruct); - } - - /** - * Test creating a role with policies. - * - * @covers \eZ\Publish\API\Repository\RoleService::createRole - */ - public function testCreateRoleWithPolicies() - { - $roleService = $this->repository->getRoleService(); - - $limitation1 = new Limitation\ContentTypeLimitation(); - $limitation1->limitationValues = array('1', '3', '13'); - - $limitation2 = new Limitation\SectionLimitation(); - $limitation2->limitationValues = array('2', '3'); - - $limitation3 = new Limitation\OwnerLimitation(); - $limitation3->limitationValues = array('1', '2'); - - $limitation4 = new Limitation\UserGroupLimitation(); - $limitation4->limitationValues = array('1'); - - $policyCreateStruct1 = $roleService->newPolicyCreateStruct('content', 'read'); - $policyCreateStruct1->addLimitation($limitation1); - $policyCreateStruct1->addLimitation($limitation2); - - $policyCreateStruct2 = $roleService->newPolicyCreateStruct('content', 'edit'); - $policyCreateStruct2->addLimitation($limitation3); - $policyCreateStruct2->addLimitation($limitation4); - - $roleCreateStruct = $roleService->newRoleCreateStruct('ultimate_permissions'); - - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // $roleCreateStruct->mainLanguageCode = 'eng-GB'; - // $roleCreateStruct->names = array( 'eng-GB' => 'Ultimate permissions' ); - // $roleCreateStruct->descriptions = array( 'eng-GB' => 'This is a role with ultimate permissions' ); - - $roleCreateStruct->addPolicy($policyCreateStruct1); - $roleCreateStruct->addPolicy($policyCreateStruct2); - - $createdRole = $roleService->createRole($roleCreateStruct); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $createdRole); - self::assertGreaterThan(0, $createdRole->id); - - /* @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - self::assertEquals( - array( - 'eng-GB' => $roleCreateStruct->names['eng-GB'] - ), - $createdRole->getNames() - ); - - self::assertEquals( - array( - 'eng-GB' => $roleCreateStruct->descriptions['eng-GB'] - ), - $createdRole->getDescriptions() - ); - */ - - $this->assertPropertiesCorrect( - array( - 'identifier' => $roleCreateStruct->identifier, - ), - $createdRole - ); - - self::assertCount(2, $createdRole->getPolicies()); - - foreach ($createdRole->getPolicies() as $policy) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy', $policy); - self::assertGreaterThan(0, $policy->id); - self::assertEquals($createdRole->id, $policy->roleId); - - self::assertCount(2, $policy->getLimitations()); - - foreach ($policy->getLimitations() as $limitation) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Limitation', $limitation); - - if ($policy->module == 'content' && $policy->function == 'read') { - switch ($limitation->getIdentifier()) { - case Limitation::CONTENTTYPE: - self::assertEquals($limitation1->limitationValues, $limitation->limitationValues); - break; - - case Limitation::SECTION: - self::assertEquals($limitation2->limitationValues, $limitation->limitationValues); - break; - - default: - self::fail('Created role contains limitations not defined with create struct'); - } - } elseif ($policy->module == 'content' && $policy->function == 'edit') { - switch ($limitation->getIdentifier()) { - case Limitation::OWNER: - self::assertEquals($limitation3->limitationValues, $limitation->limitationValues); - break; - - case Limitation::USERGROUP: - self::assertEquals($limitation4->limitationValues, $limitation->limitationValues); - break; - - default: - self::fail('Created role contains limitations not defined with create struct'); - } - } else { - self::fail('Created role contains policy not defined with create struct'); - } - } - } - } - - /** - * Test updating role. - * - * @covers \eZ\Publish\API\Repository\RoleService::updateRole - */ - public function testUpdateRole() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRoleByIdentifier('Anonymous'); - - $roleUpdateStruct = $roleService->newRoleUpdateStruct(); - $roleUpdateStruct->identifier = 'Anonymous 2'; - - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // $roleUpdateStruct->mainLanguageCode = 'eng-US'; - // $roleUpdateStruct->names['eng-US'] = 'Anonymous 2'; - // $roleUpdateStruct->descriptions['eng-US'] = 'Anonymous 2 role'; - - $updatedRole = $roleService->updateRole($role, $roleUpdateStruct); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $updatedRole); - - // @todo: enable -/* - self::assertEquals( - array( - 'eng-US' => $roleUpdateStruct->names['eng-US'] - ), - $updatedRole->getNames() - ); - - self::assertEquals( - array( - 'eng-US' => $roleUpdateStruct->descriptions['eng-US'] - ), - $updatedRole->getDescriptions() - ); -*/ - $this->assertPropertiesCorrect( - array( - 'id' => $role->id, - 'identifier' => $roleUpdateStruct->identifier, - 'policies' => $role->getPolicies(), - ), - $updatedRole - ); - } - - /** - * Test updating role throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\RoleService::updateRole - */ - public function testUpdateRoleThrowsInvalidArgumentException() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRoleByIdentifier('Anonymous'); - - $roleUpdateStruct = $roleService->newRoleUpdateStruct(); - $roleUpdateStruct->identifier = 'Administrator'; - - $roleService->updateRole($role, $roleUpdateStruct); - } - - /** - * Test adding policy to role. - * - * @covers \eZ\Publish\API\Repository\RoleService::addPolicy - */ - public function testAddPolicy() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(1); - $policyCount = count($role->getPolicies()); - - $limitation1 = new Limitation\ContentTypeLimitation(); - $limitation1->limitationValues = array('1', '3', '13'); - - $limitation2 = new Limitation\SectionLimitation(); - $limitation2->limitationValues = array('2', '3'); - - $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'read'); - $policyCreateStruct->addLimitation($limitation1); - $policyCreateStruct->addLimitation($limitation2); - - $updatedRole = $roleService->addPolicy($role, $policyCreateStruct); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $updatedRole); - self::assertCount($policyCount + 1, $updatedRole->getPolicies()); - - foreach ($updatedRole->getPolicies() as $policy) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy', $policy); - self::assertGreaterThan(0, $policy->id); - self::assertEquals($role->id, $policy->roleId); - } - } - - /** - * Test removing policy from the role. - * - * @covers \eZ\Publish\API\Repository\RoleService::removePolicy - */ - public function testRemovePolicy() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(1); - $policies = $role->getPolicies(); - $policyCount = count($policies); - - self::assertGreaterThan(0, $policyCount); - - $updatedRole = $roleService->removePolicy($role, $policies[0]); - self::assertCount($policyCount - 1, $updatedRole->getPolicies()); - } - - /** - * Test updating policies of a role, depends on proper eZ Publish clean data - * which has a number of policies and limitations applied to Anonymous role. - * - * @covers \eZ\Publish\API\Repository\RoleService::updatePolicy - */ - public function testUpdatePolicy() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(1); - $policies = $role->getPolicies(); - $policy = $policies[0]; - - // Verify we get correct data from backend - self::assertEquals('content', $policy->module); - self::assertEquals('read', $policy->function); - - $limitation = new Limitation\ContentTypeLimitation(); - $limitation->limitationValues = array('1', '3', '13'); - - $policyUpdateStruct = $roleService->newPolicyUpdateStruct(); - $policyUpdateStruct->addLimitation($limitation); - - $updatedPolicy = $roleService->updatePolicy($policy, $policyUpdateStruct); - - $this->assertPropertiesCorrect( - array( - 'id' => $policy->id, - 'roleId' => $policy->roleId, - 'module' => $policy->module, - 'function' => $policy->function, - ), - $updatedPolicy - ); - - $limitations = $updatedPolicy->getLimitations(); - - self::assertCount(1, $limitations); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Limitation', $limitations[0]); - self::assertEquals(Limitation::CONTENTTYPE, $limitations[0]->getIdentifier()); - self::assertEquals($limitation->limitationValues, $limitations[0]->limitationValues); - } - - /** - * Test loading role by id. - * - * @covers \eZ\Publish\API\Repository\RoleService::loadRole - */ - public function testLoadRole() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(1); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $role); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'identifier' => 'Anonymous', - ), - $role - ); - } - - /** - * Test loading role by id throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\RoleService::loadRole - */ - public function testLoadRoleThrowsNotFoundException() - { - $roleService = $this->repository->getRoleService(); - - $roleService->loadRole(APIBaseTest::DB_INT_MAX); - } - - /** - * Test loading role by identifier. - * - * @covers \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier - */ - public function testLoadRoleByIdentifier() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRoleByIdentifier('Anonymous'); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $role); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'identifier' => 'Anonymous', - ), - $role - ); - } - - /** - * Test loading role by identifier throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier - */ - public function testLoadRoleByIdentifierThrowsNotFoundException() - { - $roleService = $this->repository->getRoleService(); - - $roleService->loadRoleByIdentifier('non-existing'); - } - - /** - * Test loading all roles. - * - * @covers \eZ\Publish\API\Repository\RoleService::loadRoles - */ - public function testLoadRoles() - { - $roleService = $this->repository->getRoleService(); - - $roles = $roleService->loadRoles(); - self::assertInternalType('array', $roles); - self::assertGreaterThan(0, count($roles)); - - foreach ($roles as $role) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $role); - self::assertGreaterThan(0, $role->id); - } - } - - /** - * Test deleting a role. - * - * @covers \eZ\Publish\API\Repository\RoleService::deleteRole - */ - public function testDeleteRole() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(1); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', $role); - - $roleService->deleteRole($role); - - try { - $roleService->loadRole(1); - self::fail('Succeeded loading role after deleting it'); - } catch (NotFoundException $e) { - // Do nothing - } - } - - /** - * Test loading policies by user ID. - * - * @covers \eZ\Publish\API\Repository\RoleService::loadPoliciesByUserId - */ - public function testLoadPoliciesByUserId() - { - $roleService = $this->repository->getRoleService(); - - $policies = $roleService->loadPoliciesByUserId(10); - self::assertInternalType('array', $policies); - self::assertNotEmpty($policies); - - foreach ($policies as $policy) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy', $policy); - self::assertGreaterThan(0, $policy->id); - self::assertGreaterThan(0, $policy->roleId); - } - } - - /** - * Test loading policies by non existing user ID. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\RoleService::loadPoliciesByUserId - */ - public function testLoadPoliciesByNonExistingUserId() - { - $roleService = $this->repository->getRoleService(); - - $roleService->loadPoliciesByUserId(APIBaseTest::DB_INT_MAX); - } - - /** - * Test assigning role to user group. - * - * @covers \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup - */ - public function testAssignRoleToUserGroup() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(1); - $userGroup = $this->repository->getUserService()->loadUserGroup(12); - - $originalAssignmentCount = count($roleService->getRoleAssignmentsForUserGroup($userGroup)); - - $roleService->assignRoleToUserGroup($role, $userGroup); - $newAssignmentCount = count($roleService->getRoleAssignmentsForUserGroup($userGroup)); - self::assertEquals($originalAssignmentCount + 1, $newAssignmentCount); - } - - /** - * Test unassigning role from user group. - * - * @covers \eZ\Publish\API\Repository\RoleService::unassignRoleFromUserGroup - */ - public function testUnassignRoleFromUserGroup() - { - $roleService = $this->repository->getRoleService(); - - $anonymousRole = $roleService->loadRole(1); - $anonymousUserGroup = $this->repository->getUserService()->loadUserGroup(42); - - $originalAssignmentCount = count($roleService->getRoleAssignmentsForUserGroup($anonymousUserGroup)); - - $roleService->unassignRoleFromUserGroup($anonymousRole, $anonymousUserGroup); - $newAssignmentCount = count($roleService->getRoleAssignmentsForUserGroup($anonymousUserGroup)); - self::assertEquals($originalAssignmentCount - 1, $newAssignmentCount); - } - - /** - * Test unassigning role from user group. - * - * But on current admin user so he lacks access to read roles. - * - * @covers \eZ\Publish\API\Repository\RoleService::unassignRoleFromUserGroup - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - public function testUnassignRoleFromUserGroupUnauthorizedException() - { - $roleService = $this->repository->getRoleService(); - - try { - $adminRole = $roleService->loadRole(2); - $adminUserGroup = $this->repository->getUserService()->loadUserGroup(12); - $roleService->getRoleAssignmentsForUserGroup($adminUserGroup); - $roleService->unassignRoleFromUserGroup($adminRole, $adminUserGroup); - } catch (Exception $e) { - self::fail('Unexpected exception: ' . $e->getMessage() . " \n[" . $e->getFile() . ' (' . $e->getLine() . ')]'); - } - - $roleService->getRoleAssignmentsForUserGroup($adminUserGroup); - } - - /** - * Test unassigning role from user group which is not already assigned to the group. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\RoleService::unassignRoleFromUserGroup - */ - public function testUnassignRoleFromUserGroupThrowsInvalidArgumentException() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(1); - $userGroup = $this->repository->getUserService()->loadUserGroup(12); - - $roleService->unassignRoleFromUserGroup($role, $userGroup); - } - - /** - * Test assigning role to user. - * - * @covers \eZ\Publish\API\Repository\RoleService::assignRoleToUser - */ - public function testAssignRoleToUser() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(2); - $user = $this->repository->getUserService()->loadUser(14); - - $originalAssignmentCount = count($roleService->getRoleAssignmentsForUser($user)); - - $roleService->assignRoleToUser($role, $user); - $newAssignmentCount = count($roleService->getRoleAssignmentsForUser($user)); - self::assertEquals($originalAssignmentCount + 1, $newAssignmentCount); - } - - /** - * Test unassigning role from user. - * - * @covers \eZ\Publish\API\Repository\RoleService::unassignRoleFromUser - */ - public function testUnassignRoleFromUser() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(2); - $user = $this->repository->getUserService()->loadUser(14); - - $originalAssignmentCount = count($roleService->getRoleAssignmentsForUser($user)); - - $roleService->assignRoleToUser($role, $user); - $newAssignmentCount = count($roleService->getRoleAssignmentsForUser($user)); - self::assertEquals($originalAssignmentCount + 1, $newAssignmentCount); - - $roleService->unassignRoleFromUser($role, $user); - $finalAssignmentCount = count($roleService->getRoleAssignmentsForUser($user)); - self::assertEquals($newAssignmentCount - 1, $finalAssignmentCount); - } - - /** - * Test unassigning role from user which is not already assigned to the user. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\RoleService::unassignRoleFromUser - */ - public function testUnassignRoleFromUserThrowsInvalidArgumentException() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(2); - $user = $this->repository->getUserService()->loadUser(14); - - $roleService->unassignRoleFromUser($role, $user); - } - - /** - * Test fetching all role assignments for specified role. - * - * @covers \eZ\Publish\API\Repository\RoleService::getRoleAssignments - */ - public function testGetRoleAssignments() - { - $roleService = $this->repository->getRoleService(); - - $role = $roleService->loadRole(2); - - $roleAssignments = $roleService->getRoleAssignments($role); - - self::assertInternalType('array', $roleAssignments); - self::assertNotEmpty($roleAssignments); - - foreach ($roleAssignments as $assignment) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleAssignment', $assignment); - } - } - - /** - * Test fetching role assignments for specified user. - * - * @covers \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser - */ - public function testGetRoleAssignmentsForUser() - { - $roleService = $this->repository->getRoleService(); - - $user = $this->repository->getUserService()->loadUser(14); - $role = $roleService->loadRole(2); - $roleService->assignRoleToUser($role, $user); - - $userAssignments = $roleService->getRoleAssignmentsForUser($user); - - self::assertInternalType('array', $userAssignments); - self::assertNotEmpty($userAssignments); - - foreach ($userAssignments as $assignment) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', $assignment); - } - } - - /** - * Test fetching role assignments for specified user group. - * - * @covers \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUserGroup - */ - public function testGetRoleAssignmentsForUserGroup() - { - $userGroup = $this->repository->getUserService()->loadUserGroup(12); - - $userGroupAssignments = $this->repository->getRoleService()->getRoleAssignmentsForUserGroup($userGroup); - - self::assertInternalType('array', $userGroupAssignments); - self::assertNotEmpty($userGroupAssignments); - - foreach ($userGroupAssignments as $assignment) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', $assignment); - } - } - - /** - * Test creating new RoleCreateStruct. - * - * @covers \eZ\Publish\API\Repository\RoleService::newRoleCreateStruct - */ - public function testNewRoleCreateStruct() - { - $roleService = $this->repository->getRoleService(); - - $roleCreateStruct = $roleService->newRoleCreateStruct('Ultimate permissions'); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleCreateStruct', $roleCreateStruct); - - $this->assertPropertiesCorrect( - array( - 'identifier' => 'Ultimate permissions', - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // 'mainLanguageCode' => null, - // 'names' => null, - // 'descriptions' => null - ), - $roleCreateStruct - ); - - self::assertEquals('Ultimate permissions', $roleCreateStruct->identifier); - self::assertInternalType('array', $roleCreateStruct->getPolicies()); - self::assertEmpty($roleCreateStruct->getPolicies()); - } - - /** - * Test creating new PolicyCreateStruct. - * - * @covers \eZ\Publish\API\Repository\RoleService::newPolicyCreateStruct - */ - public function testNewPolicyCreateStruct() - { - $roleService = $this->repository->getRoleService(); - - $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'read'); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\PolicyCreateStruct', $policyCreateStruct); - - $this->assertPropertiesCorrect( - array( - 'module' => 'content', - 'function' => 'read', - ), - $policyCreateStruct - ); - - self::assertInternalType('array', $policyCreateStruct->getLimitations()); - self::assertEmpty($policyCreateStruct->getLimitations()); - } - - /** - * Test creating new RoleUpdateStruct. - * - * @covers \eZ\Publish\API\Repository\RoleService::newRoleUpdateStruct - */ - public function testNewRoleUpdateStruct() - { - $roleService = $this->repository->getRoleService(); - - $roleUpdateStruct = $roleService->newRoleUpdateStruct(); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleUpdateStruct', $roleUpdateStruct); - - $this->assertPropertiesCorrect( - array( - 'identifier' => null, - // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 - // 'mainLanguageCode' => null, - // 'names' => null, - // 'descriptions' => null - ), - $roleUpdateStruct - ); - } - - /** - * Test creating new PolicyUpdateStruct. - * - * @covers \eZ\Publish\API\Repository\RoleService::newPolicyUpdateStruct - */ - public function testNewPolicyUpdateStruct() - { - $roleService = $this->repository->getRoleService(); - - $policyUpdateStruct = $roleService->newPolicyUpdateStruct(); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\PolicyUpdateStruct', $policyUpdateStruct); - - self::assertInternalType('array', $policyUpdateStruct->getLimitations()); - self::assertEmpty($policyUpdateStruct->getLimitations()); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/SearchBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/SearchBase.php deleted file mode 100644 index 962da2ab231..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/SearchBase.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\SearchBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\API\Repository\Values\Content\Query; -use eZ\Publish\API\Repository\Values\Content\Query\Criterion; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; - -/** - * Test case for Content service. - */ -abstract class SearchBase extends BaseServiceTest -{ - /** - * Test for the findContent() method. - * - * @covers \eZ\Publish\Core\Repository\SearchService::findContent - */ - public function testFindContent() - { - /* BEGIN: Use Case */ - $searchService = $this->repository->getSearchService(); - $query = new Query( - array( - 'filter' => new Criterion\ContentId(array(4)), - 'offset' => 0, - ) - ); - - $searchResult = $searchService->findContent( - $query, - array(), - false - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Search\\SearchResult', - $searchResult - ); - - $this->assertEquals(1, $searchResult->totalCount); - $this->assertCount($searchResult->totalCount, $searchResult->searchHits); - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Search\\SearchHit', - reset($searchResult->searchHits) - ); - } - - /** - * Test for the findContent() method. - * - * @covers \eZ\Publish\Core\Repository\SearchService::findContent - */ - public function testFindContentWithLanguageFilter() - { - /* BEGIN: Use Case */ - $searchService = $this->repository->getSearchService(); - $query = new Query( - array( - 'filter' => new Criterion\ContentId(array(4)), - 'offset' => 0, - ) - ); - - $searchResult = $searchService->findContent( - $query, - array('languages' => array('eng-US')), - false - ); - /* END: Use Case */ - - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Search\\SearchResult', - $searchResult - ); - - $this->assertEquals(1, $searchResult->totalCount); - $this->assertCount($searchResult->totalCount, $searchResult->searchHits); - $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\Search\\SearchHit', - reset($searchResult->searchHits) - ); - } - - /** - * Test for the findSingle() method. - * - * @covers \eZ\Publish\Core\Repository\SearchService::findSingle - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - */ - public function testFindSingleThrowsNotFoundException() - { - /* BEGIN: Use Case */ - $searchService = $this->repository->getSearchService(); - - // Throws an exception because content with given id does not exist - $searchResult = $searchService->findSingle( - new Criterion\ContentId(array(APIBaseTest::DB_INT_MAX)), - array('languages' => array('eng-US')), - false - ); - /* END: Use Case */ - } - - /** - * Test for the findSingle() method. - * - * @covers \eZ\Publish\Core\Repository\SearchService::findSingle - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - */ - public function testFindSingleThrowsInvalidArgumentException() - { - /* BEGIN: Use Case */ - $searchService = $this->repository->getSearchService(); - - // Throws an exception because more than one result was returned for the given query - $searchResult = $searchService->findSingle( - new Criterion\ContentId(array(4, 10)), - array('languages' => array('eng-US')) - ); - /* END: Use Case */ - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/SectionBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/SectionBase.php deleted file mode 100644 index 79ded789f4b..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/SectionBase.php +++ /dev/null @@ -1,415 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\SectionTest class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\API\Repository\Values\Content\Section; -use eZ\Publish\API\Repository\Exceptions\NotFoundException; -use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; -use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; - -/** - * Test case for Section Service using InMemory storage class. - */ -abstract class SectionBase extends BaseServiceTest -{ - /** - * Test a new class and default values on properties. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Section::__construct - */ - public function testNewClass() - { - $section = new Section(); - - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'identifier' => null, - 'name' => null, - ), - $section - ); - } - - /** - * Test retrieving missing property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Section::__get - */ - public function testMissingProperty() - { - try { - $section = new Section(); - $value = $section->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - } - - /** - * Test setting read only property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Section::__set - */ - public function testReadOnlyProperty() - { - try { - $section = new Section(); - $section->id = 22; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test if property exists. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Section::__isset - */ - public function testIsPropertySet() - { - $section = new Section(); - $value = isset($section->notDefined); - self::assertEquals(false, $value); - - $value = isset($section->id); - self::assertEquals(true, $value); - } - - /** - * Test unsetting a property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\Section::__unset - */ - public function testUnsetProperty() - { - $section = new Section(array('id' => 1)); - try { - unset($section->id); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test service function for creating sections. - * - * @covers \eZ\Publish\Core\Repository\SectionService::createSection - */ - public function testCreateSection() - { - $sectionService = $this->repository->getSectionService(); - - $sectionCreateStruct = $sectionService->newSectionCreateStruct(); - $sectionCreateStruct->identifier = 'test'; - $sectionCreateStruct->name = 'Test'; - - $createdSection = $sectionService->createSection($sectionCreateStruct); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Section', $createdSection); - self::assertGreaterThan(0, $createdSection->id); - - $this->assertStructPropertiesCorrect( - $sectionCreateStruct, - $createdSection - ); - } - - /** - * Test service function for creating sections throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\SectionService::createSection - */ - public function testCreateSectionThrowsInvalidArgumentException() - { - $sectionService = $this->repository->getSectionService(); - - $sectionCreateStruct = $sectionService->newSectionCreateStruct(); - $sectionCreateStruct->identifier = 'standard'; - $sectionCreateStruct->name = 'Standard'; - - $sectionService->createSection($sectionCreateStruct); - } - - /** - * Test service function for updating sections. - * - * @covers \eZ\Publish\Core\Repository\SectionService::updateSection - */ - public function testUpdateSection() - { - $sectionService = $this->repository->getSectionService(); - - $loadedSection = $sectionService->loadSection(1); - - $sectionUpdateStruct = $sectionService->newSectionUpdateStruct(); - $sectionUpdateStruct->identifier = 'test'; - $sectionUpdateStruct->name = 'Test'; - - $updatedSection = $sectionService->updateSection($loadedSection, $sectionUpdateStruct); - - self::assertEquals($loadedSection->id, $updatedSection->id); - - $this->assertStructPropertiesCorrect( - $sectionUpdateStruct, - $updatedSection - ); - } - - /** - * Test service function for updating sections. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\Core\Repository\SectionService::updateSection - */ - public function testUpdateSectionThrowsInvalidArgumentException() - { - $sectionService = $this->repository->getSectionService(); - - $loadedSection = $sectionService->loadSectionByIdentifier('standard'); - - $sectionUpdateStruct = $sectionService->newSectionUpdateStruct(); - $sectionUpdateStruct->identifier = 'media'; - $sectionUpdateStruct->name = 'Media'; - - $sectionService->updateSection($loadedSection, $sectionUpdateStruct); - } - - /** - * Test service function for loading sections. - * - * @covers \eZ\Publish\Core\Repository\SectionService::loadSection - */ - public function testLoadSection() - { - $sectionService = $this->repository->getSectionService(); - - $section = $sectionService->loadSection(1); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'name' => 'Standard', - 'identifier' => 'standard', - ), - $section - ); - } - - /** - * Test service function for loading sections throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\SectionService::loadSection - */ - public function testLoadSectionThrowsNotFoundException() - { - $sectionService = $this->repository->getSectionService(); - - $sectionService->loadSection(APIBaseTest::DB_INT_MAX); - } - - /** - * Test service function for loading all sections. - * - * @covers \eZ\Publish\Core\Repository\SectionService::loadSections - */ - public function testLoadSections() - { - $sections = $this->repository->getSectionService()->loadSections(); - - self::assertInternalType('array', $sections); - self::assertGreaterThan(0, count($sections)); - - foreach ($sections as $section) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Section', $section); - } - } - - /** - * Test service function for loading section by identifier. - * - * @covers \eZ\Publish\Core\Repository\SectionService::loadSectionByIdentifier - */ - public function testLoadSectionByIdentifier() - { - $sectionService = $this->repository->getSectionService(); - - $section = $sectionService->loadSectionByIdentifier('standard'); - - $this->assertPropertiesCorrect( - array( - 'id' => 1, - 'name' => 'Standard', - 'identifier' => 'standard', - ), - $section - ); - } - - /** - * Test service function for loading section by identifier throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\SectionService::loadSectionByIdentifier - */ - public function testLoadSectionByIdentifierThrowsNotFoundException() - { - $sectionService = $this->repository->getSectionService(); - - $sectionService->loadSectionByIdentifier('non-existing'); - } - - /** - * Test service function for counting content assigned to section. - * - * @covers \eZ\Publish\Core\Repository\SectionService::countAssignedContents - */ - public function testCountAssignedContents() - { - $sectionService = $this->repository->getSectionService(); - - $section = $sectionService->loadSection(1); - $contentCount = $sectionService->countAssignedContents($section); - - self::assertGreaterThan(0, $contentCount); - - $sectionCreateStruct = $sectionService->newSectionCreateStruct(); - $sectionCreateStruct->identifier = 'test'; - $sectionCreateStruct->name = 'Test'; - - $newSection = $sectionService->createSection($sectionCreateStruct); - $contentCount = $sectionService->countAssignedContents($newSection); - - self::assertEquals(0, $contentCount); - } - - /** - * Test service function for assigning section to content. - * - * @covers \eZ\Publish\Core\Repository\SectionService::assignSection - */ - public function testAssignSection() - { - $sectionService = $this->repository->getSectionService(); - $contentService = $this->repository->getContentService(); - - $section = $sectionService->loadSection(1); - $contentInfo = $contentService->loadContentInfo(4); - - self::assertEquals(2, $contentInfo->sectionId); - - $sectionService->assignSection($contentInfo, $section); - - $contentInfo = $contentService->loadContentInfo(4); - - self::assertEquals($section->id, $contentInfo->sectionId); - } - - /** - * Test service function for deleting sections. - * - * @covers \eZ\Publish\Core\Repository\SectionService::deleteSection - */ - public function testDeleteSection() - { - $sectionService = $this->repository->getSectionService(); - - $sectionCreateStruct = $sectionService->newSectionCreateStruct(); - $sectionCreateStruct->identifier = 'test'; - $sectionCreateStruct->name = 'Test'; - - $newSection = $sectionService->createSection($sectionCreateStruct); - $sectionService->deleteSection($newSection); - - try { - $sectionService->loadSection($newSection->id); - self::fail('Section is still returned after being deleted'); - } catch (NotFoundException $e) { - // Do nothing - } - } - - /** - * Test service function for deleting sections throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\Core\Repository\SectionService::deleteSection - */ - public function testDeleteSectionThrowsNotFoundException() - { - $sectionService = $this->repository->getSectionService(); - - $section = new Section(array('id' => APIBaseTest::DB_INT_MAX)); - - $sectionService->deleteSection($section); - } - - /** - * Test service function for deleting sections throwing BadStateException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - * @covers \eZ\Publish\Core\Repository\SectionService::deleteSection - */ - public function testDeleteSectionThrowsBadStateException() - { - $sectionService = $this->repository->getSectionService(); - - $section = $sectionService->loadSection(1); - - $sectionService->deleteSection($section); - } - - /** - * Test service function for creating new SectionCreateStruct. - * - * @covers \eZ\Publish\Core\Repository\SectionService::newSectionCreateStruct - */ - public function testNewSectionCreateStruct() - { - $sectionService = $this->repository->getSectionService(); - - $sectionCreateStruct = $sectionService->newSectionCreateStruct(); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\SectionCreateStruct', $sectionCreateStruct); - - $this->assertPropertiesCorrect( - array( - 'identifier' => null, - 'name' => null, - ), - $sectionCreateStruct - ); - } - - /** - * Test service function for creating new SectionUpdateStruct. - * - * @covers \eZ\Publish\Core\Repository\SectionService::newSectionUpdateStruct - */ - public function testNewSectionUpdateStruct() - { - $sectionService = $this->repository->getSectionService(); - - $sectionUpdateStruct = $sectionService->newSectionUpdateStruct(); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\SectionUpdateStruct', $sectionUpdateStruct); - - $this->assertPropertiesCorrect( - array( - 'identifier' => null, - 'name' => null, - ), - $sectionUpdateStruct - ); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/TrashBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/TrashBase.php deleted file mode 100644 index cc1d66fc7d8..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/TrashBase.php +++ /dev/null @@ -1,475 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\TrashBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\Core\Repository\Values\Content\TrashItem; -use eZ\Publish\Core\Repository\Values\Content\Location; -use eZ\Publish\API\Repository\Values\Content\Query; -use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; -use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; -use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; -use eZ\Publish\API\Repository\Exceptions\NotFoundException; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; - -/** - * Test case for Trash Service. - */ -abstract class TrashBase extends BaseServiceTest -{ - /** - * Test a new class and default values on properties. - * - * @covers \eZ\Publish\API\Repository\Values\Content\TrashItem::__construct - */ - public function testNewClass() - { - $trashItem = new TrashItem(); - - $this->assertPropertiesCorrect( - array( - 'id' => null, - 'priority' => null, - 'hidden' => null, - 'invisible' => null, - 'remoteId' => null, - 'parentLocationId' => null, - 'pathString' => null, - 'depth' => null, - 'sortField' => null, - 'sortOrder' => null, - ), - $trashItem - ); - } - - /** - * Test retrieving missing property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\TrashItem::__get - */ - public function testMissingProperty() - { - try { - $trashItem = new TrashItem(); - $value = $trashItem->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - } - - /** - * Test setting read only property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\TrashItem::__set - */ - public function testReadOnlyProperty() - { - try { - $trashItem = new TrashItem(); - $trashItem->id = 42; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test if property exists. - * - * @covers \eZ\Publish\API\Repository\Values\Content\TrashItem::__isset - */ - public function testIsPropertySet() - { - $trashItem = new TrashItem(); - $value = isset($trashItem->notDefined); - self::assertEquals(false, $value); - - $value = isset($trashItem->id); - self::assertEquals(true, $value); - } - - /** - * Test unsetting a property. - * - * @covers \eZ\Publish\API\Repository\Values\Content\TrashItem::__unset - */ - public function testUnsetProperty() - { - $trashItem = new TrashItem(array('id' => 2)); - try { - unset($trashItem->id); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test loading a trash item. - * - * @covers \eZ\Publish\API\Repository\TrashService::loadTrashItem - */ - public function testLoadTrashItem() - { - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $trashItem = $location = $trashService->trash($locationService->loadLocation(44)); - $loadedTrashItem = $trashService->loadTrashItem($location->id); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\TrashItem', $trashItem); - - self::assertSameClassPropertiesCorrect( - array( - 'id', - 'priority', - 'hidden', - 'invisible', - 'remoteId', - 'parentLocationId', - 'pathString', - 'depth', - 'sortField', - 'sortOrder', - ), - $trashItem, - $loadedTrashItem - ); - } - - /** - * Test loading a trash item throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\TrashService::loadTrashItem - */ - public function testLoadTrashItemThrowsNotFoundException() - { - $trashService = $this->repository->getTrashService(); - $trashService->loadTrashItem(44); - } - - /** - * Test sending a location to trash. - * - * @covers \eZ\Publish\API\Repository\TrashService::trash - */ - public function testTrash() - { - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $location = $locationService->loadLocation(44); - $trashItem = $trashService->trash($location); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\TrashItem', $trashItem); - - self::assertSameClassPropertiesCorrect( - array( - 'id', - 'priority', - 'hidden', - 'invisible', - 'remoteId', - 'parentLocationId', - 'pathString', - 'depth', - 'sortField', - 'sortOrder', - ), - $location, - $trashItem - ); - } - - /** - * Test sending a location to trash. - * - * @covers \eZ\Publish\API\Repository\TrashService::trash - */ - public function testTrashUpdatesMainLocation() - { - $contentService = $this->repository->getContentService(); - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $contentInfo = $contentService->loadContentInfo(42); - - // Create additional location that will become new main location - $location = $locationService->createLocation( - $contentInfo, - new LocationCreateStruct(array('parentLocationId' => 2)) - ); - - $trashService->trash( - $locationService->loadLocation($contentInfo->mainLocationId) - ); - - self::assertEquals( - $location->id, - $contentService->loadContentInfo(42)->mainLocationId - ); - } - - /** - * Test sending a location to trash. - * - * @covers \eZ\Publish\API\Repository\TrashService::trash - */ - public function testTrashReturnsNull() - { - $contentService = $this->repository->getContentService(); - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - // Create additional location to trash - $location = $locationService->createLocation( - $contentService->loadContentInfo(42), - new LocationCreateStruct(array('parentLocationId' => 2)) - ); - - $trashItem = $trashService->trash($location); - - self::assertNull($trashItem); - } - - /** - * Test recovering a location from trash to original location. - * - * @covers \eZ\Publish\API\Repository\TrashService::recover - */ - public function testRecover() - { - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $location = $locationService->loadLocation(44); - $trashItem = $trashService->trash($location); - - $recoveredLocation = $trashService->recover($trashItem); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $recoveredLocation); - - self::assertSameClassPropertiesCorrect( - array( - 'priority', - 'hidden', - 'invisible', - 'remoteId', - 'parentLocationId', - 'depth', - 'sortField', - 'sortOrder', - ), - $location, - $recoveredLocation - ); - - $parentLocation = $locationService->loadLocation($location->parentLocationId); - $newPathString = $parentLocation->pathString . $recoveredLocation->id . '/'; - - self::assertEquals($newPathString, $recoveredLocation->pathString); - self::assertGreaterThan(0, $recoveredLocation->id); - self::assertEquals($recoveredLocation->id, $recoveredLocation->contentInfo->mainLocationId); - } - - /** - * Test recovering a non existing trash item. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\TrashService::recover - */ - public function testRecoverNonExistingTrashItem() - { - $trashService = $this->repository->getTrashService(); - - $trashItem = new TrashItem(array('id' => APIBaseTest::DB_INT_MAX, 'parentLocationId' => APIBaseTest::DB_INT_MAX)); - $trashService->recover($trashItem); - } - - /** - * Test recovering a location from trash to different location. - * - * @covers \eZ\Publish\API\Repository\TrashService::recover - */ - public function testRecoverToDifferentLocation() - { - // @todo: remove creating test locations when field types are fully functional - // Create test locations - $deleteLocationId = $this->createTestContentLocation(5)->contentInfo->mainLocationId; - $recoverLocationId = $this->createTestContentLocation(5)->contentInfo->mainLocationId; - - /* BEGIN: Use Case */ - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $location = $locationService->loadLocation($deleteLocationId); - $trashItem = $trashService->trash($location); - - $newParentLocation = $locationService->loadLocation($recoverLocationId); - - $recoveredLocation = $trashService->recover($trashItem, $newParentLocation); - /* END: Use Case */ - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $recoveredLocation); - - self::assertSameClassPropertiesCorrect( - array( - 'priority', - 'hidden', - 'invisible', - 'remoteId', - 'depth', - 'sortField', - 'sortOrder', - ), - $location, - $recoveredLocation, - array('depth') - ); - - $parentLocation = $locationService->loadLocation($recoveredLocation->parentLocationId); - $newPathString = $parentLocation->pathString . $recoveredLocation->id . '/'; - - self::assertEquals($parentLocation->depth + 1, $recoveredLocation->depth); - self::assertEquals($newPathString, $recoveredLocation->pathString); - self::assertGreaterThan(0, $recoveredLocation->id); - self::assertEquals($newParentLocation->id, $recoveredLocation->parentLocationId); - } - - /** - * Test recovering a location from trash to non existing location. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\TrashService::recover - */ - public function testRecoverToNonExistingLocation() - { - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $location = $locationService->loadLocation(44); - $trashItem = $trashService->trash($location); - - $newParentLocation = new Location( - array( - 'id' => APIBaseTest::DB_INT_MAX, - 'parentLocationId' => APIBaseTest::DB_INT_MAX, - ) - ); - $trashService->recover($trashItem, $newParentLocation); - } - - /** - * Test deleting a trash item. - * - * @covers \eZ\Publish\API\Repository\TrashService::deleteTrashItem - */ - public function testDeleteTrashItem() - { - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $location = $locationService->loadLocation(44); - $trashItem = $trashService->trash($location); - - $trashService->deleteTrashItem($trashItem); - - try { - $trashService->loadTrashItem($trashItem->id); - self::fail('Succeeded loading deleted trash item'); - } catch (NotFoundException $e) { - // Do nothing - } - } - - /** - * Test deleting a non existing trash item. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\TrashService::deleteTrashItem - */ - public function testDeleteNonExistingTrashItem() - { - $trashService = $this->repository->getTrashService(); - - $trashItem = new TrashItem(array('id' => APIBaseTest::DB_INT_MAX)); - $trashService->deleteTrashItem($trashItem); - } - - /** - * Test searching for trash items. - * - * @covers \eZ\Publish\API\Repository\TrashService::findTrashItems - * @covers \eZ\Publish\API\Repository\TrashService::emptyTrash - */ - public function testFindTrashItemsAndEmptyTrash() - { - // @todo: remove creating test location when field types are fully functional - $newLocationId = $this->createTestContentLocation(5)->contentInfo->mainLocationId; - - $locationService = $this->repository->getLocationService(); - $trashService = $this->repository->getTrashService(); - - $searchResult = $trashService->findTrashItems(new Query()); - $countBeforeTrashing = $searchResult->count; - - $location = $locationService->loadLocation($newLocationId); - $trashService->trash($location); - - $searchResult = $trashService->findTrashItems(new Query()); - $countAfterTrashing = $searchResult->count; - - self::assertGreaterThan($countBeforeTrashing, $countAfterTrashing); - - $trashService->emptyTrash(); - $searchResult = $trashService->findTrashItems(new Query()); - - self::assertEquals(0, $searchResult->count); - } - - /** - * @param int $parentLocationId - * - * @return \eZ\Publish\API\Repository\Values\Content\Content - */ - protected function createTestContentLocation($parentLocationId) - { - $contentService = $this->repository->getContentService(); - $contentTypeService = $this->repository->getContentTypeService(); - // User Group content type - $contentType = $contentTypeService->loadContentType(3); - - $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-GB'); - $contentCreate->setField('name', 'dummy value'); - $contentCreate->sectionId = 1; - $contentCreate->ownerId = 14; - $contentCreate->remoteId = md5(uniqid(get_class($this), true)); - $contentCreate->alwaysAvailable = true; - - $locationCreates = array( - new LocationCreateStruct( - array( - //priority = 0 - //hidden = false - 'remoteId' => md5(uniqid(get_class($this), true)), - //sortField = Location::SORT_FIELD_NAME - //sortOrder = Location::SORT_ORDER_ASC - 'parentLocationId' => $parentLocationId, - ) - ), - ); - - return $contentService->publishVersion( - $contentService->createContent( - $contentCreate, - $locationCreates - )->versionInfo - ); - } -} diff --git a/eZ/Publish/Core/Repository/Tests/Service/Integration/UserBase.php b/eZ/Publish/Core/Repository/Tests/Service/Integration/UserBase.php deleted file mode 100644 index 0b63b365c35..00000000000 --- a/eZ/Publish/Core/Repository/Tests/Service/Integration/UserBase.php +++ /dev/null @@ -1,939 +0,0 @@ -<?php - -/** - * File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\UserBase class. - * - * @copyright Copyright (C) eZ Systems AS. All rights reserved. - * @license For full copyright and license information view LICENSE file distributed with this source code. - */ -namespace eZ\Publish\Core\Repository\Tests\Service\Integration; - -use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; -use eZ\Publish\Core\Repository\Values\User\User; -use eZ\Publish\Core\Repository\Values\User\UserGroup; -use eZ\Publish\Core\Repository\Values\Content\Content; -use eZ\Publish\Core\Repository\Values\Content\VersionInfo; -use eZ\Publish\API\Repository\Values\Content\ContentInfo; -use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; -use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; -use eZ\Publish\API\Repository\Exceptions\NotFoundException; -use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; - -/** - * Test case for User Service. - */ -abstract class UserBase extends BaseServiceTest -{ - /** - * Test a new class and default values on properties. - * - * @covers \eZ\Publish\API\Repository\Values\User\User::__construct - * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__construct - */ - public function testNewClass() - { - $user = new User(); - - $this->assertPropertiesCorrect( - array( - 'login' => null, - 'email' => null, - 'passwordHash' => null, - 'hashAlgorithm' => null, - 'maxLogin' => null, - 'enabled' => null, - ), - $user - ); - - $group = new UserGroup(); - self::assertEquals(null, $group->parentId); - self::assertEquals(null, $group->subGroupCount); - - $this->assertPropertiesCorrect( - array( - 'parentId' => null, - 'subGroupCount' => null, - ), - $group - ); - } - - /** - * Test retrieving missing property. - * - * @covers \eZ\Publish\API\Repository\Values\User\User::__get - * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__get - */ - public function testMissingProperty() - { - try { - $user = new User(); - $value = $user->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - - try { - $userGroup = new UserGroup(); - $value = $userGroup->notDefined; - self::fail('Succeeded getting non existing property'); - } catch (PropertyNotFound $e) { - } - } - - /** - * Test setting read only property. - * - * @covers \eZ\Publish\API\Repository\Values\User\User::__set - * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__set - */ - public function testReadOnlyProperty() - { - try { - $user = new User(); - $user->login = 'user'; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - - try { - $userGroup = new UserGroup(); - $userGroup->parentId = 42; - self::fail('Succeeded setting read only property'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test if property exists. - * - * @covers \eZ\Publish\API\Repository\Values\User\User::__isset - * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__isset - */ - public function testIsPropertySet() - { - $user = new User(); - $value = isset($user->notDefined); - self::assertEquals(false, $value); - - $value = isset($user->login); - self::assertEquals(true, $value); - - $userGroup = new UserGroup(); - $value = isset($userGroup->notDefined); - self::assertEquals(false, $value); - - $value = isset($userGroup->parentId); - self::assertEquals(true, $value); - } - - /** - * Test unsetting a property. - * - * @covers \eZ\Publish\API\Repository\Values\User\User::__unset - * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__unset - */ - public function testUnsetProperty() - { - $user = new User(array('login' => 'admin')); - try { - unset($user->login); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - - $userGroup = new UserGroup(array('parentId' => 1)); - try { - unset($userGroup->parentId); - self::fail('Unsetting read-only property succeeded'); - } catch (PropertyReadOnlyException $e) { - } - } - - /** - * Test creating new user group. - * - * @covers \eZ\Publish\API\Repository\UserService::createUserGroup - */ - public function testCreateUserGroup() - { - $userService = $this->repository->getUserService(); - - $parentGroup = $userService->loadUserGroup(4); - $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB'); - $userGroupCreateStruct->ownerId = 14; - $userGroupCreateStruct->sectionId = 1; - $userGroupCreateStruct->setField('name', 'New group'); - $userGroupCreateStruct->setField('description', 'This is a new group'); - - $newGroup = $userService->createUserGroup($userGroupCreateStruct, $parentGroup); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup', $newGroup); - } - - /** - * Test creating new user group throwing ContentFieldValidationException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - * @covers \eZ\Publish\API\Repository\UserService::createUserGroup - */ - public function testCreateUserGroupRequiredFieldEmpty() - { - $userService = $this->repository->getUserService(); - - $parentGroup = $userService->loadUserGroup(4); - $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB'); - $userGroupCreateStruct->ownerId = 14; - $userGroupCreateStruct->sectionId = 1; - $userGroupCreateStruct->setField('name', ''); - - $userService->createUserGroup($userGroupCreateStruct, $parentGroup); - } - - /** - * Test creating new user group throwing ContentFieldValidationException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - * @covers \eZ\Publish\API\Repository\UserService::createUserGroup - */ - public function testCreateUserGroupRequiredFieldMissing() - { - $userService = $this->repository->getUserService(); - - $parentGroup = $userService->loadUserGroup(4); - $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB'); - - $userService->createUserGroup($userGroupCreateStruct, $parentGroup); - } - - /** - * Test loading a group. - * - * @covers \eZ\Publish\API\Repository\UserService::loadUserGroup - */ - public function testLoadUserGroup() - { - $userService = $this->repository->getUserService(); - $userGroup = $userService->loadUserGroup(4); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup', $userGroup); - } - - /** - * Test loading a group throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::loadUserGroup - */ - public function testLoadUserGroupThrowsNotFoundException() - { - $userService = $this->repository->getUserService(); - $userService->loadUserGroup(APIBaseTest::DB_INT_MAX); - } - - /** - * Test loading sub groups. - * - * @covers \eZ\Publish\API\Repository\UserService::loadSubUserGroups - */ - public function testLoadSubUserGroups() - { - $userService = $this->repository->getUserService(); - - $parentGroup = $userService->loadUserGroup(4); - $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB'); - $userGroupCreateStruct->ownerId = 14; - $userGroupCreateStruct->sectionId = 1; - $userGroupCreateStruct->setField('name', 'New group'); - $userGroupCreateStruct->setField('description', 'This is a new group'); - - $userService->createUserGroup($userGroupCreateStruct, $parentGroup); - - $subGroups = $userService->loadSubUserGroups($parentGroup); - - self::assertInternalType('array', $subGroups); - self::assertNotEmpty($subGroups); - } - - /** - * Test loading sub groups throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::loadSubUserGroups - */ - public function testLoadSubUserGroupsThrowsNotFoundException() - { - $userService = $this->repository->getUserService(); - - $parentGroup = new UserGroup( - array( - 'content' => new Content( - array( - 'versionInfo' => new VersionInfo( - array('contentInfo' => new ContentInfo(array('id' => APIBaseTest::DB_INT_MAX))) - ), - 'internalFields' => array(), - ) - ), - ) - ); - $userService->loadSubUserGroups($parentGroup); - } - - /** - * Test deleting user group. - * - * @covers \eZ\Publish\API\Repository\UserService::deleteUserGroup - */ - public function testDeleteUserGroup() - { - $userService = $this->repository->getUserService(); - - $userGroup = $userService->loadUserGroup(12); - $userService->deleteUserGroup($userGroup); - - try { - $userService->loadUserGroup($userGroup->id); - self::fail('Succeeded loading deleted user group'); - } catch (NotFoundException $e) { - } - } - - /** - * Test deleting user group throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::deleteUserGroup - */ - public function testDeleteUserGroupThrowsNotFoundException() - { - $userService = $this->repository->getUserService(); - - $userGroup = new UserGroup( - array( - 'content' => new Content( - array( - 'versionInfo' => new VersionInfo( - array('contentInfo' => new ContentInfo(array('id' => APIBaseTest::DB_INT_MAX))) - ), - 'internalFields' => array(), - ) - ), - ) - ); - $userService->deleteUserGroup($userGroup); - } - - /** - * Test moving a user group below another group. - * - * @covers \eZ\Publish\API\Repository\UserService::moveUserGroup - */ - public function testMoveUserGroup() - { - $userService = $this->repository->getUserService(); - $locationService = $this->repository->getLocationService(); - - $userGroupToMove = $userService->loadUserGroup(42); - $parentUserGroup = $userService->loadUserGroup(12); - $userService->moveUserGroup($userGroupToMove, $parentUserGroup); - - $movedUserGroup = $userService->loadUserGroup($userGroupToMove->id); - - $newMainLocation = $locationService->loadLocation($movedUserGroup->getVersionInfo()->getContentInfo()->mainLocationId); - self::assertEquals( - $parentUserGroup->getVersionInfo()->getContentInfo()->mainLocationId, - $newMainLocation->parentLocationId - ); - } - - /** - * Test moving a user group below another group throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::moveUserGroup - */ - public function testMoveUserGroupThrowsNotFoundException() - { - $userService = $this->repository->getUserService(); - - $userGroupToMove = new UserGroup( - array( - 'content' => new Content( - array( - 'versionInfo' => new VersionInfo( - array('contentInfo' => new ContentInfo(array('id' => APIBaseTest::DB_INT_MAX))) - ), - 'internalFields' => array(), - ) - ), - ) - ); - $parentUserGroup = new UserGroup( - array( - 'content' => new Content( - array( - 'versionInfo' => new VersionInfo( - array('contentInfo' => new ContentInfo(array('id' => APIBaseTest::DB_INT_MAX))) - ), - 'internalFields' => array(), - ) - ), - ) - ); - $userService->moveUserGroup($userGroupToMove, $parentUserGroup); - } - - /** - * Test updating a user group. - * - * @covers \eZ\Publish\API\Repository\UserService::updateUserGroup - */ - public function testUpdateUserGroup() - { - $userService = $this->repository->getUserService(); - $contentService = $this->repository->getContentService(); - - $userGroupUpdateStruct = $userService->newUserGroupUpdateStruct(); - $userGroupUpdateStruct->contentUpdateStruct = $contentService->newContentUpdateStruct(); - $userGroupUpdateStruct->contentUpdateStruct->setField('name', 'New anonymous group', 'eng-US'); - - $userGroup = $userService->loadUserGroup(42); - - $updatedUserGroup = $userService->updateUserGroup($userGroup, $userGroupUpdateStruct); - self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup', $updatedUserGroup); - self::assertEquals( - $userGroupUpdateStruct->contentUpdateStruct->fields[0]->value, - $updatedUserGroup->getFieldValue('name') - ); - } - - /** - * Test updating a user group throwing ContentFieldValidationException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - * @covers \eZ\Publish\API\Repository\UserService::updateUserGroup - */ - public function testUpdateUserGroupRequiredFieldEmpty() - { - $userService = $this->repository->getUserService(); - $contentService = $this->repository->getContentService(); - - $userGroup = $userService->loadUserGroup(42); - $userGroupUpdateStruct = $userService->newUserGroupUpdateStruct(); - $userGroupUpdateStruct->contentUpdateStruct = $contentService->newContentUpdateStruct(); - $userGroupUpdateStruct->contentUpdateStruct->setField('name', '', 'eng-US'); - - $userService->updateUserGroup($userGroup, $userGroupUpdateStruct); - } - - /** - * Test creating a user. - * - * @covers \eZ\Publish\API\Repository\UserService::createUser - */ - public function testCreateUser() - { - $userService = $this->repository->getUserService(); - - $userCreateStruct = $userService->newUserCreateStruct('new_user', 'new_user@ez.no', 'password', 'eng-GB'); - $userCreateStruct->setField('first_name', 'New', 'eng-GB'); - $userCreateStruct->setField('last_name', 'User', 'eng-GB'); - - $parentGroup = $userService->loadUserGroup(42); - $createdUser = $userService->createUser($userCreateStruct, array($parentGroup)); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\User', $createdUser); - self::assertEquals('New', $createdUser->getFieldValue('first_name')); - self::assertEquals('User', $createdUser->getFieldValue('last_name')); - self::assertEquals($userCreateStruct->login, $createdUser->login); - self::assertEquals($userCreateStruct->email, $createdUser->email); - } - - /** - * Test creating a user throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::createUser - */ - public function testCreateUserThrowsNotFoundException() - { - $userService = $this->repository->getUserService(); - - $userCreateStruct = $userService->newUserCreateStruct('new_user', 'new_user@ez.no', 'password', 'eng-GB'); - $userCreateStruct->setField('first_name', 'New'); - $userCreateStruct->setField('last_name', 'User'); - - $parentGroup = new UserGroup( - array( - 'content' => new Content( - array( - 'versionInfo' => new VersionInfo( - array( - 'contentInfo' => new ContentInfo(array('id' => APIBaseTest::DB_INT_MAX)), - ) - ), - 'internalFields' => array(), - ) - ), - ) - ); - $userService->createUser($userCreateStruct, array($parentGroup)); - } - - /** - * Test creating a user throwing ContentFieldValidationException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException - * @covers \eZ\Publish\API\Repository\UserService::createUser - */ - public function testCreateUserRequiredFieldsEmpty() - { - $userService = $this->repository->getUserService(); - - $userCreateStruct = $userService->newUserCreateStruct('new_user', 'new_user@ez.no', 'password', 'eng-GB'); - $userCreateStruct->setField('first_name', '', 'eng-GB'); - $userCreateStruct->setField('last_name', '', 'eng-GB'); - - $parentGroup = $userService->loadUserGroup(12); - $userService->createUser($userCreateStruct, array($parentGroup)); - } - - /** - * Test creating a user throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\UserService::createUser - */ - public function testCreateUserThrowsInvalidArgumentException() - { - $userService = $this->repository->getUserService(); - - $userCreateStruct = $userService->newUserCreateStruct('admin', 'new_user@ez.no', 'password', 'eng-GB'); - $userCreateStruct->setField('first_name', '', 'eng-GB'); - $userCreateStruct->setField('last_name', '', 'eng-GB'); - - $parentGroup = $userService->loadUserGroup(12); - $userService->createUser($userCreateStruct, array($parentGroup)); - } - - /** - * Test loading a user. - * - * @covers \eZ\Publish\API\Repository\UserService::loadUser - */ - public function testLoadUser() - { - $userService = $this->repository->getUserService(); - - $loadedUser = $userService->loadUser(14); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\User', $loadedUser); - self::assertEquals(14, $loadedUser->id); - } - - /** - * Test loading a user throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::loadUser - */ - public function testLoadUserThrowsNotFoundException() - { - $userService = $this->repository->getUserService(); - - $userService->loadUser(APIBaseTest::DB_INT_MAX); - } - - /** - * Test loading anonymous user. - * - * @covers \eZ\Publish\API\Repository\UserService::loadAnonymousUser - */ - public function testLoadAnonymousUser() - { - $userService = $this->repository->getUserService(); - - $loadedUser = $userService->loadAnonymousUser(); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\User', $loadedUser); - self::assertEquals(10, $loadedUser->id); - } - - /** - * Test loading a user by credentials. - * - * @covers \eZ\Publish\API\Repository\UserService::loadUserByCredentials - */ - public function testLoadUserByCredentials() - { - $userService = $this->repository->getUserService(); - - $loadedUser = $userService->loadUserByCredentials('admin', 'publish'); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\User', $loadedUser); - - $this->assertPropertiesCorrect( - array( - 'id' => 14, - 'login' => 'admin', - 'email' => 'spam@ez.no', - 'passwordHash' => 'c78e3b0f3d9244ed8c6d1c29464bdff9', - 'hashAlgorithm' => User::PASSWORD_HASH_MD5_USER, - 'enabled' => true, - 'maxLogin' => 10, - ), - $loadedUser - ); - } - - /** - * Test loading a user by credentials throwing NotFoundException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::loadUser - */ - public function testLoadUserByCredentialsThrowsNotFoundException() - { - $userService = $this->repository->getUserService(); - - $userService->loadUserByCredentials('non_existing_user', 'invalid_password'); - } - - /** - * Test loading a user by credentials throwing NotFoundException because of bad password. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @covers \eZ\Publish\API\Repository\UserService::loadUser - */ - public function testLoadUserByCredentialsThrowsNotFoundExceptionBadPassword() - { - $userService = $this->repository->getUserService(); - - $userService->loadUserByCredentials('admin', 'some_password'); - } - - /** - * Test updating a user. - * - * @covers \eZ\Publish\API\Repository\UserService::updateUser - */ - public function testUpdateUser() - { - $userService = $this->repository->getUserService(); - - $userUpdateStruct = $userService->newUserUpdateStruct(); - $userUpdateStruct->contentUpdateStruct = $this->repository->getContentService()->newContentUpdateStruct(); - $userUpdateStruct->contentUpdateStruct->setField('first_name', 'New first name', 'eng-US'); - $userUpdateStruct->contentUpdateStruct->setField('last_name', 'New last name', 'eng-US'); - - $user = $userService->loadUser(14); - - $userService->updateUser($user, $userUpdateStruct); - $updatedUser = $userService->loadUser($user->id); - - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\User', $updatedUser); - self::assertEquals( - 'New first name', - $updatedUser->getFieldValue('first_name') - ); - - self::assertEquals( - 'New last name', - $updatedUser->getFieldValue('last_name') - ); - } - - /** - * Test updating a user throwing ContentValidationException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException - * @covers \eZ\Publish\API\Repository\UserService::updateUser - */ - public function testUpdateUserThrowsContentValidationException() - { - $userService = $this->repository->getUserService(); - $contentService = $this->repository->getContentService(); - - $user = $userService->loadUser(14); - $userUpdateStruct = $userService->newUserUpdateStruct(); - $userUpdateStruct->contentUpdateStruct = $contentService->newContentUpdateStruct(); - $userUpdateStruct->contentUpdateStruct->setField('name', '', 'eng-US'); - - $userService->updateUser($user, $userUpdateStruct); - } - - /** - * Test assigning a user group to user. - * - * @covers \eZ\Publish\API\Repository\UserService::assignUserToUserGroup - */ - public function testAssignUserToUserGroup() - { - $userService = $this->repository->getUserService(); - $locationService = $this->repository->getLocationService(); - - $user = $userService->loadUser(14); - $userGroup = $userService->loadUserGroup(42); - - $userService->assignUserToUserGroup($user, $userGroup); - - $userLocations = $locationService->loadLocations($user->getVersionInfo()->getContentInfo()); - - if (!is_array($userLocations) || empty($userLocations)) { - self::fail('Failed assigning user to user group'); - } - - $hasAddedLocation = false; - foreach ($userLocations as $location) { - if ($location->parentLocationId == $userGroup->getVersionInfo()->getContentInfo()->mainLocationId) { - $hasAddedLocation = true; - break; - } - } - - if (!$hasAddedLocation) { - self::fail('Failed assigning user to user group'); - } - } - - /** - * Test assigning a user group to user throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\UserService::assignUserToUserGroup - */ - public function testAssignUserToUserGroupThrowsInvalidArgumentException() - { - $userService = $this->repository->getUserService(); - - $user = $userService->loadUser(14); - $userGroup = $userService->loadUserGroup(12); - $userService->assignUserToUserGroup($user, $userGroup); - } - - /** - * Test removing a user from user group. - * - * @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup - * @depends testAssignUserToUserGroup - */ - public function testUnAssignUserFromUserGroup() - { - $userService = $this->repository->getUserService(); - $locationService = $this->repository->getLocationService(); - - $user = $userService->loadUser(14); - $userGroup = $userService->loadUserGroup(12); - - // first assign another user group as we can't remove all users groups - $userGroup = $userService->loadUserGroup(42); - $userService->assignUserToUserGroup($user, $userGroup); - - // un-assign original group - $userService->unAssignUserFromUserGroup($user, $userGroup); - - try { - $user = $userService->loadUser(14); - } catch (NotFoundException $e) { - // user was deleted because the group we assigned him from was his last location - return; - } - - $userLocations = $locationService->loadLocations($user->getVersionInfo()->getContentInfo()); - - if (is_array($userLocations) && !empty($userLocations)) { - $hasRemovedLocation = false; - foreach ($userLocations as $location) { - if ($location->parentLocationId == $userGroup->getVersionInfo()->getContentInfo()->mainLocationId) { - $hasRemovedLocation = true; - break; - } - } - - if ($hasRemovedLocation) { - self::fail('Failed removing a user from user group'); - } - } - } - - /** - * Test removing a user from user group throwing BadState for removing last group. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException - * @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup - */ - public function testUnAssignUserFromUserGroupThrowsBadStateException() - { - $userService = $this->repository->getUserService(); - $user = $userService->loadUser(14); - $userGroup = $userService->loadUserGroup(12); - - // un-assign original group, should throw BadState - $userService->unAssignUserFromUserGroup($user, $userGroup); - } - - /** - * Test removing a user from user group throwing InvalidArgumentException. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException - * @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup - */ - public function testUnAssignUserFromUserGroupThrowsInvalidArgumentException() - { - $userService = $this->repository->getUserService(); - - $user = $userService->loadUser(14); - $userGroup = $userService->loadUserGroup(42); - $userService->unAssignUserFromUserGroup($user, $userGroup); - } - - /** - * Test loading user groups the user belongs to. - * - * @covers \eZ\Publish\API\Repository\UserService::loadUserGroupsOfUser - */ - public function testLoadUserGroupsOfUser() - { - $userService = $this->repository->getUserService(); - $locationService = $this->repository->getLocationService(); - - $user = $userService->loadUser(14); - $userLocations = $locationService->loadLocations( - $user->getVersionInfo()->getContentInfo() - ); - - $groupLocationIds = array(); - foreach ($userLocations as $userLocation) { - if ($userLocation->parentLocationId !== null) { - $groupLocationIds[] = $userLocation->parentLocationId; - } - } - - $userGroups = $userService->loadUserGroupsOfUser($user); - - foreach ($userGroups as $userGroup) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup', $userGroup); - self::assertContains( - $userGroup->getVersionInfo()->getContentInfo()->mainLocationId, - $groupLocationIds - ); - } - } - - /** - * Test loading user groups the user belongs to. - * - * @covers \eZ\Publish\API\Repository\UserService::loadUsersOfUserGroup - */ - public function testLoadUsersOfUserGroup() - { - $userService = $this->repository->getUserService(); - $locationService = $this->repository->getLocationService(); - - $userGroup = $userService->loadUserGroup(12); - $users = $userService->loadUsersOfUserGroup($userGroup); - - self::assertInternalType('array', $users); - self::assertNotEmpty($users); - - foreach ($users as $user) { - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\User', $user); - - $userLocation = $locationService->loadLocation($user->getVersionInfo()->getContentInfo()->mainLocationId); - - self::assertEquals( - $userGroup->getVersionInfo()->getContentInfo()->mainLocationId, - $userLocation->parentLocationId - ); - } - } - - /** - * Test creating new UserCreateStruct. - * - * @covers \eZ\Publish\API\Repository\UserService::newUserCreateStruct - */ - public function testNewUserCreateStruct() - { - $userService = $this->repository->getUserService(); - - $userCreateStruct = $userService->newUserCreateStruct('admin', 'admin@ez.no', 'password', 'eng-GB'); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserCreateStruct', $userCreateStruct); - - $this->assertPropertiesCorrect( - array( - 'mainLanguageCode' => 'eng-GB', - 'login' => 'admin', - 'email' => 'admin@ez.no', - 'password' => 'password', - 'enabled' => true, - 'fields' => array(), - ), - $userCreateStruct - ); - } - - /** - * Test creating new UserGroupCreateStruct. - * - * @covers \eZ\Publish\API\Repository\UserService::newUserGroupCreateStruct - */ - public function testNewUserGroupCreateStruct() - { - $userService = $this->repository->getUserService(); - - $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB'); - self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupCreateStruct', $userGroupCreateStruct); - self::assertEquals('eng-GB', $userGroupCreateStruct->mainLanguageCode); - } - - /** - * Test creating new UserUpdateStruct. - * - * @covers \eZ\Publish\API\Repository\UserService::newUserUpdateStruct - */ - public function testNewUserUpdateStruct() - { - $userService = $this->repository->getUserService(); - - $userUpdateStruct = $userService->newUserUpdateStruct(); - - self::assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserUpdateStruct', - $userUpdateStruct - ); - - self::assertNull($userUpdateStruct->contentUpdateStruct); - self::assertNull($userUpdateStruct->contentMetadataUpdateStruct); - - $this->assertPropertiesCorrect( - array( - 'email' => null, - 'password' => null, - 'enabled' => null, - 'maxLogin' => null, - ), - $userUpdateStruct - ); - } - - /** - * Test creating new UserGroupUpdateStruct. - * - * @covers \eZ\Publish\API\Repository\UserService::newUserGroupUpdateStruct - */ - public function testNewUserGroupUpdateStruct() - { - $userService = $this->repository->getUserService(); - - $userGroupUpdateStruct = $userService->newUserGroupUpdateStruct(); - - self::assertInstanceOf( - '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupUpdateStruct', - $userGroupUpdateStruct - ); - - self::assertNull($userGroupUpdateStruct->contentUpdateStruct); - self::assertNull($userGroupUpdateStruct->contentMetadataUpdateStruct); - } -}