Inheritance: extends Sulu\Bundle\CoreBundle\Entity\ApiEntity, implements Sulu\Component\Persistence\Model\AuditableInterface
Example #1
0
 private function createTag($name)
 {
     $tag = new Tag();
     $tag->setName($name);
     $this->em->persist($tag);
     return $tag;
 }
Example #2
0
 protected function setUpMedia()
 {
     // Create Media Type
     $documentType = new MediaType();
     $documentType->setName('document');
     $documentType->setDescription('This is a document');
     $imageType = new MediaType();
     $imageType->setName('image');
     $imageType->setDescription('This is an image');
     $videoType = new MediaType();
     $videoType->setName('video');
     $videoType->setDescription('This is a video');
     $this->mediaTypes['image'] = $imageType;
     $this->mediaTypes['video'] = $videoType;
     // create some tags
     $tag1 = new Tag();
     $tag1->setName('Tag 1');
     $tag2 = new Tag();
     $tag2->setName('Tag 2');
     $this->em->persist($tag1);
     $this->em->persist($tag2);
     $this->em->persist($documentType);
     $this->em->persist($imageType);
     $this->em->persist($videoType);
     $this->em->flush();
 }
Example #3
0
 /**
  * @Given the following tags exist:
  */
 public function givenTheFollowingTagsExist(TableNode $node)
 {
     foreach ($node as $row) {
         $tag = new Tag();
         $tag->setName($row['name']);
         $this->getEntityManager()->persist($tag);
     }
     $this->getEntityManager()->flush();
 }
Example #4
0
 /**
  * @dataProvider getProvider
  */
 public function testGetTags($tagData)
 {
     $tags = [];
     foreach ($tagData as $tagItem) {
         $tag = new Tag();
         $tag->setName($tagItem['name']);
         $tags[] = $tag;
     }
     $tagManager = $this->prophesize(TagManagerInterface::class);
     $tagManager->findAll()->shouldBeCalled()->willReturn($tags);
     $serializer = $this->prophesize(SerializerInterface::class);
     $serializer->serialize($tags, 'array', Argument::type(SerializationContext::class))->shouldBeCalled()->willReturn($tagData);
     $tagRequestHandler = $this->prophesize(TagRequestHandlerInterface::class);
     $tagExtension = new TagTwigExtension($tagManager->reveal(), $tagRequestHandler->reveal(), $serializer->reveal(), $this->getMemoizeCache());
     $this->assertEquals($tagData, $tagExtension->getTagsFunction());
 }
 public function testGetItemsTags()
 {
     $client = $this->createAuthenticatedClient();
     $client->request('GET', '/api/items?webspace=sulu_io&locale=en&dataSource=' . $this->team->getUuid() . '&provider=content&excluded=' . $this->team->getUuid() . '&limitResult=2&tags[]=' . $this->tag1->getName());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $result = json_decode($client->getResponse()->getContent(), true);
     $this->assertEquals(['id' => $this->team->getUuid(), 'title' => 'Team', 'path' => '/team'], $result['datasource']);
     $this->assertEquals([['id' => $this->johannes->getUuid(), 'title' => 'Johannes']], $result['_embedded']['items']);
 }
Example #6
0
 protected function initOrm()
 {
     $this->purgeDatabase();
     $tag1 = new Tag();
     $tag1->setName('tag1');
     $this->em->persist($tag1);
     $this->em->flush();
     $tag2 = new Tag();
     $tag2->setName('tag2');
     $this->em->persist($tag2);
     $this->em->flush();
     $tag3 = new Tag();
     $tag3->setName('tag3');
     $this->em->persist($tag3);
     $this->em->flush();
     $tag4 = new Tag();
     $tag4->setName('tag4');
     $this->em->persist($tag4);
     $this->em->flush();
 }
 public function testTagsBoth()
 {
     $root = $this->sessionManager->getContentNode('sulu_io');
     list($nodes, $t1, $t2, $t1t2) = $this->tagsProvider();
     $builder = new SmartContentQueryBuilder($this->structureManager, $this->webspaceManager, $this->sessionManager, $this->languageNamespace);
     $builder->init(['config' => ['dataSource' => $root->getIdentifier(), 'tags' => [$this->tag1->getId()], 'tagOperator' => 'and', 'websiteTags' => [$this->tag2->getId()], 'websiteTagsOperator' => 'and']]);
     $result = $this->contentQuery->execute('sulu_io', ['en'], $builder);
     $this->assertEquals($t1t2, count($result));
     $builder->init(['config' => ['dataSource' => $root->getIdentifier(), 'tags' => [$this->tag1->getId()], 'tagOperator' => 'and', 'websiteTags' => [$this->tag1->getId(), $this->tag2->getId()], 'websiteTagsOperator' => 'OR']]);
     $result = $this->contentQuery->execute('sulu_io', ['en'], $builder);
     $this->assertEquals($t1t2 + $t2, count($result));
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function save($data, $userId, $id = null)
 {
     $name = $data['name'];
     try {
         // load existing tag if id is given and create a new one otherwise
         if ($id) {
             $tag = $this->tagRepository->findTagById($id);
             if (!$tag) {
                 throw new TagNotFoundException($id);
             }
         } else {
             $tag = new Tag();
         }
         $user = $this->userRepository->findUserById($userId);
         // update data
         $tag->setName($name);
         $tag->setChanger($user);
         if (!$id) {
             $tag->setCreator($user);
             $this->em->persist($tag);
         }
         $this->em->flush();
         return $tag;
     } catch (DBALException $exc) {
         if ($exc->getPrevious()->getCode() == 23000) {
             // Check if unique constraint fails
             throw new TagAlreadyExistsException($name);
         } else {
             throw $exc;
         }
     }
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function save($data, $userId, $id = null)
 {
     $name = $data['name'];
     try {
         // load existing tag if id is given and create a new one otherwise
         if ($id) {
             $tag = $this->tagRepository->findTagById($id);
             if (!$tag) {
                 throw new TagNotFoundException($id);
             }
         } else {
             $tag = new Tag();
         }
         $user = $this->userRepository->findUserById($userId);
         // update data
         $tag->setName($name);
         $tag->setChanger($user);
         if (!$id) {
             $tag->setCreator($user);
             $this->em->persist($tag);
         }
         $this->em->flush();
         return $tag;
     } catch (UniqueConstraintViolationException $exc) {
         throw new TagAlreadyExistsException($name);
     }
 }
Example #10
0
 public function testMerge()
 {
     $tag3 = new Tag();
     $tag3->setName('tag3');
     $this->em->persist($tag3);
     $tag4 = new Tag();
     $tag4->setName('tag4');
     $this->em->persist($tag4);
     $this->em->flush();
     $mockedEventListener = $this->getMock('stdClass', ['onMerge']);
     $mockedEventListener->expects($this->once())->method('onMerge');
     $client = $this->createAuthenticatedClient();
     $client->getContainer()->get('event_dispatcher')->addListener('sulu.tag.merge', [$mockedEventListener, 'onMerge']);
     $client->request('POST', '/api/tags/merge', ['src' => implode(',', [$this->tag2->getId(), $tag3->getId(), $tag4->getId()]), 'dest' => $this->tag1->getId()]);
     $this->assertEquals(303, $client->getResponse()->getStatusCode());
     $this->assertEquals('/admin/api/tags/' . $this->tag1->getId(), $client->getResponse()->headers->get('location'));
     $client->request('GET', '/api/tags/' . $this->tag1->getId());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $client->request('GET', '/api/tags/' . $this->tag2->getId());
     $this->assertEquals(404, $client->getResponse()->getStatusCode());
     $client->request('GET', '/api/tags/' . $tag3->getId());
     $this->assertEquals(404, $client->getResponse()->getStatusCode());
     $client->request('GET', '/api/tags/' . $tag4->getId());
     $this->assertEquals(404, $client->getResponse()->getStatusCode());
 }
Example #11
0
 protected function initOrm()
 {
     $this->purgeDatabase();
     $contact = new Contact();
     $contact->setFirstName('Max');
     $contact->setLastName('Mustermann');
     $this->em->persist($contact);
     $this->em->flush();
     $emailType = new EmailType();
     $emailType->setName('Private');
     $this->em->persist($emailType);
     $this->em->flush();
     $email = new Email();
     $email->setEmail('*****@*****.**');
     $email->setEmailType($emailType);
     $this->em->persist($email);
     $this->em->flush();
     $role1 = new Role();
     $role1->setName('Role1');
     $role1->setSystem('Sulu');
     $this->em->persist($role1);
     $this->em->flush();
     $user = new User();
     $user->setUsername('admin');
     $user->setPassword('securepassword');
     $user->setSalt('salt');
     $user->setLocale('de');
     $user->setContact($contact);
     $this->em->persist($user);
     $this->em->flush();
     $userRole1 = new UserRole();
     $userRole1->setRole($role1);
     $userRole1->setUser($user);
     $userRole1->setLocale(json_encode(['de', 'en']));
     $this->em->persist($userRole1);
     $this->em->flush();
     $permission1 = new Permission();
     $permission1->setPermissions(122);
     $permission1->setRole($role1);
     $permission1->setContext('Context 1');
     $this->em->persist($permission1);
     $this->em->flush();
     $tag1 = new Tag();
     $tag1->setName('tag1');
     $this->em->persist($tag1);
     $this->em->flush();
     $tag2 = new Tag();
     $tag2->setName('tag2');
     $this->em->persist($tag2);
     $this->em->flush();
     $tag3 = new Tag();
     $tag3->setName('tag3');
     $this->em->persist($tag3);
     $this->em->flush();
     $tag4 = new Tag();
     $tag4->setName('tag4');
     $this->em->persist($tag4);
     $this->em->flush();
 }