Blame view

tests/integration/Comment/CreateComment/NewBornManyCommentTest.php 1.94 KB
e77200db5   nologostudio.ru   Initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  <?php
  
  namespace FootyRoom\Tests;
  
  use Illuminate\Database\Connection;
  
  class NewBornManyCommentTest extends TestCase
  {
      use SetsUpFixtures;
  
      public function setup()
      {
          parent::setup();
          $this->faker = \Faker\Factory::create();
          $this->mysql = $this->app->make(Connection::class);
  
          for ($i = 1; $i <= 5; $i++) {
              $comments[] = [
                  'user_id' => 2,
                  'content' => $this->faker->sentence(),
                  'datetime' => $this->faker->date('Y-m-d H:i:s', '-1 week'),
              ];
          }
  
          $this->mysql->table('comments')->insert($comments);
      }
  
      public function testNewBornCanCreateCommentAfterTooManyCommentBeyond24Hours()
      {
          $data = [
              'postId' => 1,
              'content' => $this->faker->paragraph(),
          ];
  
          $user = factory('FootyRoom\User\User')->make(['user_id' => 2]);
          $response = $this->actingAs($user)->call('POST', '/forum/comments', $data);
          $this->assertEquals(200, $response->status());
      }
  
      public function testNewBornCanNotCreateCommentAfterTooManyCommentWithin24Hours()
      {
          for ($i = 1; $i <= 5; $i++) {
              $comments[] = [
                  'discussion_id' => 'post:1',
                  'user_id' => 2,
                  'content' => $this->faker->sentence(),
                  'datetime' => date('Y-m-d H:i:s'),
              ];
          }
  
          $this->mysql->table('comments')->insert($comments);
  
          $data = [
              'postId' => 1,
              'content' => $this->faker->paragraph(),
          ];
  
          $user = factory('FootyRoom\User\User')->make(['user_id' => 2]);
          $response = $this->actingAs($user)->call('POST', '/forum/comments', $data);
          $this->assertEquals(500, $response->status());
          $this->assertContains('New members can comment/post 5 times per day. You have already made 5 comments/posts today. Please wait until tomorrow.', $response->getContent());
      }
  }