/** * Create a new category * * @param int $i * @param Category $parent * @return Category */ protected function createCategory($i, Category $parent) { $cat = new Category(); $cat->setTranslatableLocale('en'); $cat->setName('Category ' . $i); $cat->setParent($parent); $cat->setDescription('test category number ' . $i); return $cat; }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { $listenerManager = $this->container->get('doctrine_extensions.listener_manager'); $listenerManager->addAllListeners($this->container->get('doctrine.orm.entity_manager')); // Generating groups $output->writeln('Generating groups'); $groupManager = $this->container->get('fos_user.group_manager'); // Admin $adminGroup = $groupManager->findGroupByName('Admin'); if ($adminGroup === null) { $adminGroup = $groupManager->createGroup('Admin'); $adminGroup->addRole('ROLE_ADMIN'); $groupManager->updateGroup($adminGroup); if ($output->getVerbosity() == Output::VERBOSITY_VERBOSE) { $output->writeln(sprintf('Created group <comment>%s</comment>', $adminGroup->getName())); } } // Moderator $moderatorGroup = $groupManager->findGroupByName('Moderator'); if ($moderatorGroup === null) { $moderatorGroup = $groupManager->createGroup('Moderator'); $moderatorGroup->addRole('ROLE_MODERATOR'); $groupManager->updateGroup($moderatorGroup); if ($output->getVerbosity() == Output::VERBOSITY_VERBOSE) { $output->writeln(sprintf('Created group <comment>%s</comment>', $moderatorGroup->getName())); } } // Special user $output->writeln('Generating special user'); $userManager = $this->container->get('fos_user.user_manager'); if (null === $userManager->findUserByUsername($this->container->getParameter('yrch.special_user.username'))) { $specialUser = $userManager->createUser(); $specialUser->setUsername($this->container->getParameter('yrch.special_user.username')); $specialUser->setNick($this->container->getParameter('yrch.special_user.nick')); $specialUser->setEmail($this->container->getParameter('yrch.special_user.email')); $specialUser->setPreferedLocale($this->container->getParameter('session.default_locale')); $specialUser->setPassword(md5(uniqid() . rand(100000, 999999))); $specialUser->setEnabled(true); $specialUser->setLocked(true); $userManager->updateUser($specialUser); if ($output->getVerbosity() == Output::VERBOSITY_VERBOSE) { $output->writeln(sprintf('Created user <comment>%s</comment>', $specialUser->getNick())); } } // Generating root category $output->writeln('Generating the root category'); $em = $this->container->get('doctrine.orm.entity_manager'); $categoryRepo = $em->getRepository('Application\\YrchBundle\\Entity\\Category'); $rootnodes = $categoryRepo->children(null, true); if (!$rootnodes) { $category = new Category(); $category->setName('Yrch!'); $category->setDescription(''); $em->persist($category); $em->flush(); if ($output->getVerbosity() == Output::VERBOSITY_VERBOSE) { $output->writeln(sprintf('Created category <comment>%s</comment>', $category->getName())); } } }
public function testDescription() { $this->assertNull($this->category->getDescription()); $this->category->setDescription('test description'); $this->assertEquals('test description', $this->category->getDescription()); }