public function test_create_method_creates_new_post()
 {
     $user = new User();
     $date = new \DateTime("now");
     $post = Post::create("title", "content", "excerpt", $user);
     $this->assertEquals("title", $post->getTitle());
     $this->assertEquals("excerpt", $post->getExcerpt());
     $this->assertEquals("content", $post->getContent());
     $this->assertSame($user, $post->getUser());
     $this->assertEquals($date, $post->getDate());
 }
Beispiel #2
0
<?php

use Domain\Entities;
use Presentation\Models\Input;
use Infrastructure\Persistence\Doctrine\PostRepository;
$authService->addRoute('/^\\/admin.*/');
$postRepo = new PostRepository();
$app->get('/admin/post', function () use($app, $postRepo, $authService) {
    $app->render('add_post.phtml', ['user_posts' => $postRepo->getBy(['user' => $authService->getLoggedInUser('superblorg')])]);
});
$app->post('/admin/post', function () use($app, $authService, $postRepo) {
    $input = new Input\Post($app->request()->post('post'));
    $user = $authService->getLoggedInUser('superblorg');
    $post = Entities\Post::create($input->title, $input->content, $input->excerpt, $user);
    if ($input->isValid()) {
        $postRepo->store($post);
    }
    $app->render('add_post.phtml', ['post' => $input, 'user_posts' => $postRepo->getBy(['user' => $user]), 'saved' => $post]);
});