/**
  * @test
  */
 public function machine_name_is_title_converted_to_lower_case_and_hyphens()
 {
     $category = new Category();
     // 'foo' => 'foo'
     $category->setTitle('foo');
     $this->assertEquals('foo', $category->getMachineName());
     // 'FooBar' => 'foobar'
     $category->setTitle('FooBar');
     $this->assertEquals('foobar', $category->getMachineName());
     // 'Foo Bar Baz' => 'foo-bar-baz'
     $category->setTitle('Foo Bar Baz');
     $this->assertEquals('foo-bar-baz', $category->getMachineName());
 }
 /**
  * @Route("/create", name="create_objects")
  *
  * @Rest\View()
  *
  * @return Response
  */
 public function createAction()
 {
     // We need an entity manager here
     $em = $this->getDoctrine()->getManager();
     // First, we try to create a post
     $post = new Post();
     $post->setTitle('Hello World');
     $post->setContent('This is a hello world post');
     $post->setCreated(new \DateTime());
     $em->persist($post);
     // Create new post log object
     $postLog = new PostLog();
     $postLog->setMessage('A new post was created');
     $postLog->setCreated(new \DateTime());
     $postLog->setParent($post);
     $em->persist($postLog);
     // Try to create a category
     $category = new Category();
     $category->setTitle('A Category');
     $category->setDescription('A category to created');
     $em->persist($category);
     // Create new category log object
     $categoryLog = new CategoryLog();
     $categoryLog->setMessage('A new category was created');
     $categoryLog->setCreated(new \DateTime());
     $categoryLog->setParent($category);
     $em->persist($categoryLog);
     // Actually store all the entities to the database
     // to get id of the post and the category
     $em->flush();
     return ['Done'];
 }
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function throws_an_exception_when_adding_a_category_whose_name_already_exists_in_the_activity()
 {
     $defaultCategory = (new Category())->setTitle('default');
     $activity = new Activity($defaultCategory);
     $duplicateCategory = new Category();
     $duplicateCategory->setTitle('default');
     $activity->addCategory($duplicateCategory);
 }
 public function testSubmitValidData()
 {
     $formData = array('title' => 'Test title');
     $form = $this->factory->create(CategoryType::class);
     $object = new Category();
     $object->setTitle('Test title');
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($object, $form->getData());
     $view = $form->createView();
     $children = $view->children;
     foreach (array_keys($formData) as $key) {
         $this->assertArrayHasKey($key, $children);
     }
 }
 public function load(ObjectManager $manager)
 {
     $category = new Category();
     $category->setTitle('Дома');
     $this->setReference("houses", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle('Квартиры');
     $this->setReference("flats", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle('Участки');
     $this->setReference("steads", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle('Аренда жилья');
     $this->setReference("rent", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle('Коммерция');
     $this->setReference("commerce", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Дома в городе");
     //$category->setUrl("{{ path('show_category', {'slug': link.title}) }}");
     $category->setParent($this->getReference("houses"));
     $this->setReference("category6", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Дома за городом");
     $category->setParent($this->getReference("houses"));
     $this->setReference("category7", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Комната");
     $category->setParent($this->getReference("flats"));
     $this->setReference("category1", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Однокомнатные квартиры");
     $category->setParent($this->getReference("flats"));
     $this->setReference("category2", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Двокомнатные квартиры");
     $category->setParent($this->getReference("flats"));
     $this->setReference("category3", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Трьохкомнатные квартиры");
     $category->setParent($this->getReference("flats"));
     $this->setReference("category4", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Многокомнатные");
     $category->setParent($this->getReference("flats"));
     $this->setReference("category5", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Дачные участки");
     $category->setParent($this->getReference("steads"));
     $this->setReference("category8", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Участки в городе");
     $category->setParent($this->getReference("steads"));
     $this->setReference("category9", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Участки за городом");
     $category->setParent($this->getReference("steads"));
     $this->setReference("category10", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Аренда коммерции");
     $category->setParent($this->getReference("commerce"));
     $this->setReference("category11", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Продажа коммерции");
     $category->setParent($this->getReference("commerce"));
     $this->setReference("category12", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Дома в аренду");
     $category->setParent($this->getReference("rent"));
     $this->setReference("category13", $category);
     $manager->persist($category);
     $category = new Category();
     $category->setTitle("Квартиры в аренду");
     $category->setParent($this->getReference("rent"));
     $this->setReference("category14", $category);
     $manager->persist($category);
     $manager->flush();
 }