/** * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException * * @covers \Netgen\TagsBundle\Core\Repository\TagsService::addSynonym */ public function testAddSynonymThrowsUnauthorizedException() { $createStruct = $this->tagsService->newSynonymCreateStruct(40, 'eng-GB'); $createStruct->setKeyword('New synonym'); $this->repository->setCurrentUser($this->getStubbedUser(10)); $this->tagsService->addSynonym($createStruct); }
/** * Creates a new synonym. * * @param string $tagPath * @param \Symfony\Component\HttpFoundation\Request $request * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException If there was an error while creating the tag * * @return \Netgen\TagsBundle\Core\REST\Server\Values\CreatedTag */ public function createSynonym($tagPath, Request $request) { $synonymCreateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent())); $synonymCreateStruct->mainTagId = $this->extractTagIdFromPath($tagPath); try { $createdSynonym = $this->tagsService->addSynonym($synonymCreateStruct); } catch (InvalidArgumentException $e) { throw new ForbiddenException($e->getMessage()); } return new Values\CreatedTag(new Values\RestTag($createdSynonym, 0, 0)); }
/** * Creates a synonym for $tag. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to create a synonym * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the target tag is a synonym * * @param \Netgen\TagsBundle\API\Repository\Values\Tags\SynonymCreateStruct $synonymCreateStruct * * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag The created synonym */ public function addSynonym(SynonymCreateStruct $synonymCreateStruct) { $returnValue = $this->service->addSynonym($synonymCreateStruct); $this->signalDispatcher->emit(new AddSynonymSignal(array('tagId' => $returnValue->id, 'mainTagId' => $returnValue->mainTagId, 'keywords' => $returnValue->keywords, 'mainLanguageCode' => $returnValue->mainLanguageCode, 'alwaysAvailable' => $returnValue->alwaysAvailable))); return $returnValue; }