Esempio n. 1
0
 /**
  * ダミーの投稿(\Tinitter\Model\Post)を指定数だけ生成保存する
  * @param $num 生成する数
  */
 public static function farmingPost($num)
 {
     $faker = \Faker\Factory::create();
     for ($i = 0; $i < $num; $i++) {
         $post = new M_Post();
         $post->nickname = $faker->firstName;
         $post->body = $faker->paragraph(2);
         $post->save();
     }
 }
Esempio n. 2
0
 public function commit()
 {
     $app = \Slim\Slim::getInstance();
     $params = $app->request->params();
     $error_list = V_Post::byArray($params);
     if (empty($error_list)) {
         $post = new M_Post();
         $post->nickname = $params['nickname'];
         $post->body = $params['body'];
         $post->save();
         $app->redirect('/');
     } else {
         $app->render('Post/form.twig', ['params' => $params, 'error_list' => $error_list]);
     }
 }
Esempio n. 3
0
 /**
  * ページ指定で取得できるか
  */
 public function testGetByPage()
 {
     \Tinitter\Test\Farming::farmingPost(35);
     list($post_list, $next_page_is_exist) = M_Post::getByPage(10, 1);
     $this->assertCount(10, $post_list);
     $this->assertTrue($next_page_is_exist);
     list($post_list, $next_page_is_exist) = M_Post::getByPage(10, 4);
     $this->assertCount(5, $post_list);
     $this->assertFalse($next_page_is_exist);
     list($post_list, $next_page_is_exist) = M_Post::getByPage(10, 5);
     $this->assertCount(0, $post_list);
     $this->assertFalse($next_page_is_exist);
 }
Esempio n. 4
0
 /**
  * 投稿が保存されるか
  */
 public function testAddPost()
 {
     // CSRF対策のトークンを事前取得
     $this->req('/');
     $csrf_token = $_SESSION['csrf_token'];
     // テストデータ生成
     $test_name = 'testname';
     $test_body = 'testbody';
     $input = http_build_query(['nickname' => $test_name, 'body' => $test_body, 'csrf_token' => $csrf_token]);
     // データを送信
     $this->req('/post/commit', 'POST', $input);
     // DBに保存されたかを確認
     $post = \Tinitter\Model\Post::find(1);
     $this->assertEquals($test_name, $post->nickname);
     $this->assertEquals($test_body, $post->body);
     // 投稿がページに表示されているか確認
     $dom = $this->req_dom('/page/1');
     $this->assertEquals($test_name, $dom->find('.postcell .nickname', 0)->text);
     $this->assertEquals($test_body, $dom->find('.postcell .body', 0)->text);
 }
Esempio n. 5
0
 public function show($page_num = 1)
 {
     $app = \Slim\Slim::getInstance();
     list($post_list, $next_page_is_exist) = M_Post::getByPage(10, $page_num);
     $app->render('TimeLine/show.twig', ['post_list' => $post_list, 'page_num' => $page_num, 'next_page_is_exist' => $next_page_is_exist]);
 }