/**
  * Creates a new object state in the given group.
  *
  * Note: in current kernel: If it is the first state all content objects will
  * set to this state.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create an object state
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state with provided identifier already exists in the same group
  *
  * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
  * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct $objectStateCreateStruct
  *
  * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectState
  */
 public function createObjectState(APIObjectStateGroup $objectStateGroup, ObjectStateCreateStruct $objectStateCreateStruct)
 {
     if ($this->repository->hasAccess('state', 'administrate') !== true) {
         throw new UnauthorizedException('state', 'administrate');
     }
     $inputStruct = $this->buildCreateInputStruct($objectStateCreateStruct->identifier, $objectStateCreateStruct->defaultLanguageCode, $objectStateCreateStruct->names, $objectStateCreateStruct->descriptions);
     try {
         $this->objectStateHandler->loadByIdentifier($inputStruct->identifier, $objectStateGroup->id);
         throw new InvalidArgumentException('objectStateCreateStruct', 'Object state with provided identifier already exists in provided object state group');
     } catch (APINotFoundException $e) {
         // Do nothing
     }
     $this->repository->beginTransaction();
     try {
         $spiObjectState = $this->objectStateHandler->create($objectStateGroup->id, $inputStruct);
         if (is_int($objectStateCreateStruct->priority)) {
             $this->objectStateHandler->setPriority($spiObjectState->id, $objectStateCreateStruct->priority);
             // Reload the object state to have the updated priority,
             // considering that priorities are always incremental within a group
             $spiObjectState = $this->objectStateHandler->load($spiObjectState->id);
         }
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->buildDomainObjectStateObject($spiObjectState);
 }
 /**
  * @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));
 }