/** * Create a collection type with given parameter. * * @param int $id * @param string $key * @param string $name * * @return CollectionType */ private function createCollectionType($id, $key, $name) { $collectionType = new CollectionType(); $collectionType->setId($id); $collectionType->setKey($key); $collectionType->setName($name); return $collectionType; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $collectionType = new CollectionType(); $collectionType->setId(1); // force id = 1 $metadata = $manager->getClassMetaData(get_class($collectionType)); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE); $collectionType->setName('collection.default'); $manager->persist($collectionType); $manager->flush(); }
protected function setUpCollection() { $this->collection = new Collection(); $style = ['type' => 'circle', 'color' => '#ffcc00']; $this->collection->setStyle(json_encode($style)); // Create Collection Type $this->collectionType = new CollectionType(); $this->collectionType->setName('Default Collection Type'); $this->collectionType->setDescription('Default Collection Type'); $this->collection->setType($this->collectionType); // Collection Meta 1 $this->collectionMeta = new CollectionMeta(); $this->collectionMeta->setTitle('Test Collection'); $this->collectionMeta->setDescription('This Description is only for testing'); $this->collectionMeta->setLocale('en-gb'); $this->collectionMeta->setCollection($this->collection); $this->collection->addMeta($this->collectionMeta); // Collection Meta 2 $collectionMeta2 = new CollectionMeta(); $collectionMeta2->setTitle('Test Kollektion'); $collectionMeta2->setDescription('Dies ist eine Test Beschreibung'); $collectionMeta2->setLocale('de'); $collectionMeta2->setCollection($this->collection); $this->collection->addMeta($collectionMeta2); $this->em->persist($this->collection); $this->em->persist($this->collectionType); $this->em->persist($this->collectionMeta); $this->em->persist($collectionMeta2); }
public function testPutSystemCollection() { $collection = $this->createCollection($this->collectionType2, ['en' => 'Test'], null, 'system_collections'); $this->em->flush(); $client = $this->createAuthenticatedClient(); $client->request('PUT', '/api/collections/' . $collection->getId(), ['locale' => 'en-gb', 'type' => ['id' => $this->collectionType1->getId()], 'title' => 'Test Collection 2', 'description' => 'This Description 2 is only for testing']); $this->assertEquals(403, $client->getResponse()->getStatusCode()); }
protected function setUp() { parent::setUp(); $this->purgeDatabase(); $this->em = $this->db('ORM')->getOm(); $this->fileVersionMetaRepository = $this->em->getRepository('SuluMediaBundle:FileVersionMeta'); $this->collectionType = new CollectionType(); $this->collectionType->setName('image'); $this->collection = new Collection(); $this->collection->setType($this->collectionType); $this->mediaType = new MediaType(); $this->mediaType->setName('image'); $this->em->persist($this->collectionType); $this->em->persist($this->mediaType); $this->em->persist($this->collection); $this->em->flush(); }
protected function setUp() { parent::setUp(); $this->purgeDatabase(); $this->em = $this->db('ORM')->getOm(); $collectionType = new CollectionType(); $collectionType->setName('Default Type'); $collectionType->setDescription('Default Collection Type'); $this->em->persist($collectionType); foreach ($this->collectionData as $collection) { $this->collections[] = $this->createCollection($collection[0], $collection[1], $collectionType); } $this->em->flush(); /** @var CollectionRepository $repository */ $repository = $this->getContainer()->get('sulu_media.collection_repository'); $repository->recover(); $this->em->flush(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { // set id manually $metadata = $manager->getClassMetaData(CollectionType::class); $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator()); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE); // create or update collectiontype with id 1 $defaultCollectionType = new CollectionType(); $defaultCollectionType->setId(1); $defaultCollectionType = $manager->merge($defaultCollectionType); $defaultCollectionType->setKey('collection.default'); $defaultCollectionType->setName('Default'); // create or update collectiontype with id 2 $systemCollectionType = new CollectionType(); $systemCollectionType->setId(2); $systemCollectionType = $manager->merge($systemCollectionType); $systemCollectionType->setKey(SystemCollectionManagerInterface::COLLECTION_TYPE); $systemCollectionType->setName('System Collections'); $manager->flush(); }
/** * Get or create a collection type. * * @param string $name Name of collection type to get or create * * @return CollectionType */ private function getOrCreateCollectionType($name) { $manager = $this->getEntityManager(); $collectionType = $manager->getRepository('SuluMediaBundle:CollectionType')->findOneByName($name); if (!$collectionType) { $collectionType = new CollectionType(); $collectionType->setName($name); $manager->persist($collectionType); } return $collectionType; }
public function initLogo() { $collectionType = new CollectionType(); $collectionType->setName('My collection type'); $this->em->persist($collectionType); $collection = new Collection(); $collection->setType($collectionType); $this->em->persist($collection); $imageType = new MediaType(); $imageType->setName('image'); $imageType->setDescription('This is an image'); $this->em->persist($imageType); $file = new File(); $file->setVersion(1); $fileVersion = new FileVersion(); $fileVersion->setVersion(1); $fileVersion->setName('logo.jpeg'); $fileVersion->setMimeType('image/jpg'); $fileVersion->setFile($file); $fileVersion->setSize(1124214); $fileVersion->setDownloadCounter(2); $fileVersion->setChanged(new \DateTime('1937-04-20')); $fileVersion->setCreated(new \DateTime('1937-04-20')); $file->addFileVersion($fileVersion); $this->em->persist($fileVersion); $this->logo = new Media(); $this->logo->setType($imageType); $this->logo->setCollection($collection); $this->logo->addFile($file); $file->setMedia($this->logo); $this->em->persist($this->logo); $this->em->persist($file); }
private function createCollection($name, $parent = null) { $collection = new Collection(); $collectionType = new CollectionType(); $collectionType->setName($name); $collectionType->setDescription('Default Collection Type'); $collectionMeta = new CollectionMeta(); $collectionMeta->setTitle('Test Collection'); $collectionMeta->setDescription('This Description is only for testing'); $collectionMeta->setLocale('en-gb'); $collection->setType($collectionType); $collectionMeta->setCollection($collection); $collection->addMeta($collectionMeta); if ($parent !== null) { $collection->setParent($this->collections[$parent]); $this->collections[$parent]->addChildren($collection); } $this->em->persist($collection); $this->em->persist($collectionMeta); $this->em->persist($collectionType); return $collection; }
/** * @description Test PUT action without details */ public function testPutNoDetails() { $client = $this->createAuthenticatedClient(); // Add New Collection Type $collectionType = new CollectionType(); $collectionType->setName('Second Collection Type'); $collectionType->setDescription('Second Collection Type'); $this->em->persist($collectionType); $this->em->flush(); // Test put with only details $client->request('PUT', '/api/collections/' . $this->collection1->getId(), ['style' => ['type' => 'quader', 'color' => '#00ccff'], 'type' => ['id' => $collectionType->getId()]]); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $client->request('GET', '/api/collections/' . $this->collection1->getId() . '?locale=en-gb'); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $style = new \stdClass(); $style->type = 'quader'; $style->color = '#00ccff'; $this->assertEquals($style, $response->style); $this->assertNotNull($response->type->id); }