/** * @covers \eZ\Publish\Core\Persistence\InMemory\ObjectStateHandler::create */ public function testCreateInEmptyGroup() { $createdGroup = $this->handler->createGroup($this->getInputStructFixture()); $createdState = $this->handler->create($createdGroup->id, $this->getInputStructFixture()); $this->assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState', $createdState); $this->assertEquals(3, $createdState->id); $this->assertEquals($createdGroup->id, $createdState->groupId); $this->assertEquals('test', $createdState->identifier); $this->assertEquals('eng-US', $createdState->defaultLanguage); $this->assertEquals(array('eng-US'), $createdState->languageCodes); $this->assertEquals(array('eng-US' => 'Test'), $createdState->name); $this->assertEquals(array('eng-US' => 'Test description'), $createdState->description); $this->assertEquals(0, $createdState->priority); $this->assertEquals($this->handler->getContentCount(1), $this->handler->getContentCount($createdState->id)); }
/** * Creates a new object state group. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create an object state group * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state group with provided identifier already exists * * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct $objectStateGroupCreateStruct * * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup */ public function createObjectStateGroup(ObjectStateGroupCreateStruct $objectStateGroupCreateStruct) { if ($this->repository->hasAccess('state', 'administrate') !== true) { throw new UnauthorizedException('state', 'administrate'); } $inputStruct = $this->buildCreateInputStruct($objectStateGroupCreateStruct->identifier, $objectStateGroupCreateStruct->defaultLanguageCode, $objectStateGroupCreateStruct->names, $objectStateGroupCreateStruct->descriptions); try { $this->objectStateHandler->loadGroupByIdentifier($inputStruct->identifier); throw new InvalidArgumentException('objectStateGroupCreateStruct', 'Object state group with provided identifier already exists'); } catch (APINotFoundException $e) { // Do nothing } $this->repository->beginTransaction(); try { $spiObjectStateGroup = $this->objectStateHandler->createGroup($inputStruct); $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } return $this->buildDomainObjectStateGroupObject($spiObjectStateGroup); }