/** * @Route("/") * @Method("post") */ public function indexPostAction(Request $request) { $form = $this->form_factory->create('blog_article'); $form->handleRequest($request); if ($form->isValid()) { $this->service->add($form->getData()); return $this->redirect($this->generateUrl('app_admin_blogpost_complete')); } return $this->render('Admin/Blog/index.html.twig', ['form' => $form->createView()]); }
/** * @test */ public function getAllPostsSuccess() { $blogs = new ArrayCollection(); $blog_article = new BlogArticle(); $blog_article->setId(1); $blog_article->setTitle('test'); $blog_article->setContent('content'); $blog_article->setCategory($this->createCategory(1)); $blogs->add($blog_article); $blog_article = new BlogArticle(); $blog_article->setId(2); $blog_article->setTitle('test_2'); $blog_article->setContent('content_2'); $blog_article->setCategory($this->createCategory(1)); $blogs->add($blog_article); $this->repository->expects($this->once())->method('findAll')->will($this->returnValue($blogs)); $posts = $this->blog_service->getAllPosts(); $post = $posts->first(); $this->assertCount(2, $posts->toArray()); $this->assertInstanceOf('AppBundle\\Entity\\BlogArticle', $post); $this->assertEquals(1, $post->getId()); }
/** * @Route("/", name="admin_blog_list") * @Method("get") */ public function indexAction() { $blogs = $this->service->getAllPosts(); return $this->render('Admin/index.html.twig', ['blogs' => $blogs]); }