|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Api\V1; |
| 4 | + |
| 5 | +use Tests\TestCase; |
| 6 | +use Illuminate\Foundation\Testing\WithFaker; |
| 7 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 8 | +use Tests\BrowserKitTestCase; |
| 9 | +use App\Models\Access\User\User; |
| 10 | + |
| 11 | +use App\Models\Page\Page; |
| 12 | + |
| 13 | +use JWTAuth; |
| 14 | + |
| 15 | +class PageTest extends TestCase |
| 16 | +{ |
| 17 | + public $token=''; |
| 18 | + public $headers=''; |
| 19 | + public $user=''; |
| 20 | + public function setUp() |
| 21 | + { |
| 22 | + parent::setUp(); |
| 23 | + $this->user = User::find(1); |
| 24 | + |
| 25 | + $this->token = JWTAuth::fromUser($this->user); |
| 26 | + $this->headers = ['Authorization' => "Bearer ".$this->token]; |
| 27 | + } |
| 28 | + /** |
| 29 | + * A basic test example. |
| 30 | + * |
| 31 | + * @return void |
| 32 | + */ |
| 33 | + public function testExample() |
| 34 | + { |
| 35 | + $this->assertTrue(true); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * A basic test to get response form pages api |
| 40 | + * |
| 41 | + * @return void |
| 42 | + */ |
| 43 | + /** @test */ |
| 44 | + public function Get_records_from_pages() |
| 45 | + { |
| 46 | + |
| 47 | + $payload = []; |
| 48 | + $response = $this->json('GET', '/api/v1/pages',$payload, $this->headers); |
| 49 | + $response |
| 50 | + ->assertStatus(200) |
| 51 | + ->assertJsonStructure([ |
| 52 | + 'data'=>[ |
| 53 | + [ |
| 54 | + "id", |
| 55 | + "title", |
| 56 | + "status_label", |
| 57 | + "status", |
| 58 | + "created_at", |
| 59 | + "created_by" |
| 60 | + ] |
| 61 | + ], |
| 62 | + 'links', |
| 63 | + 'meta' |
| 64 | + ]); |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * A basic test to get response form pages api |
| 70 | + * |
| 71 | + * @return void |
| 72 | + */ |
| 73 | + /** @test */ |
| 74 | + public function get_one_created_page_from_db() |
| 75 | + { |
| 76 | + $page = create(Page::class); |
| 77 | + $payload = []; |
| 78 | + $response = $this->json('GET', '/api/v1/pages/'.$page->id, $payload, $this->headers); |
| 79 | + $response |
| 80 | + ->assertStatus(200) |
| 81 | + ->assertJson([ |
| 82 | + "data"=>[ |
| 83 | + "id" => $page->id, |
| 84 | + "title" => $page->title, |
| 85 | + "status_label" => $page->status_label, |
| 86 | + "status" => ($page->isActive()) ? 'Active' :'InActive', |
| 87 | + "created_by" => $page->created_by, |
| 88 | + ], |
| 89 | + ]); |
| 90 | + |
| 91 | + } |
| 92 | + /** |
| 93 | + * Author: Indra Shastri |
| 94 | + * Date:03-03-2018 |
| 95 | + * A basic test to update a page from api |
| 96 | + * |
| 97 | + * |
| 98 | + * @return void |
| 99 | + */ |
| 100 | + /** @test */ |
| 101 | + public function update_a_page_in_db_and_get_response() |
| 102 | + { |
| 103 | + $page = make(Page::class); |
| 104 | + $payload = [ |
| 105 | + "title" => $page->title, |
| 106 | + "description" => $page->description, |
| 107 | + "cannonical_link" => $page->cannonical_link, |
| 108 | + "seo_title" => "some tittle", |
| 109 | + "seo_keyword" => "some keywords", |
| 110 | + "seo_description" => "<p> </p>↵<h1>SEO Description</h1>↵<p>some seco desctription</p>↵<p>askdsaj;ldsjfd</p>", |
| 111 | + "status" => "1", |
| 112 | + ]; |
| 113 | + $response = ""; |
| 114 | + $response = $this->json('PUT', '/api/v1/pages/1', $payload, $this->headers); |
| 115 | + |
| 116 | + $response->assertStatus(200); |
| 117 | + $response->assertJson([ |
| 118 | + "data"=>[ |
| 119 | + "title" => $page->title, |
| 120 | + "status_label" => $page->status_label, |
| 121 | + "status" => ($page->isActive()) ? 'Active' :'InActive', |
| 122 | + "created_by" => "".$this->user->id, |
| 123 | + ], |
| 124 | + ]); |
| 125 | + |
| 126 | + } |
| 127 | + /** |
| 128 | + * Author: Indra Shastri |
| 129 | + * Date:03-03-2018 |
| 130 | + * A basic test to create a page from api |
| 131 | + * |
| 132 | + * @return void |
| 133 | + */ |
| 134 | + /** @test */ |
| 135 | + public function create_a_new_page_in_db_and_get_response() |
| 136 | + { |
| 137 | + |
| 138 | + $page = make(Page::class); |
| 139 | + $payload = [ |
| 140 | + "title" => $page->title, |
| 141 | + "description" => $page->description, |
| 142 | + "cannonical_link" => $page->cannonical_link, |
| 143 | + "seo_title" => "some tittle", |
| 144 | + "seo_keyword" => "some keywords", |
| 145 | + "seo_description" => "<p> </p>↵<h1>SEO Description</h1>↵<p>some seco desctription</p>↵<p>askdsaj;ldsjfd</p>", |
| 146 | + "status" => "1", |
| 147 | + ]; |
| 148 | + $response = ""; |
| 149 | + $response = $this->json('POST', '/api/v1/pages', $payload, $this->headers); |
| 150 | + $response->assertStatus(201); |
| 151 | + $response->assertJson([ |
| 152 | + "data" => [ |
| 153 | + "title" => $page->title, |
| 154 | + "status_label" => $page->status_label, |
| 155 | + "status" => ($page->isActive()) ? 'Active' : 'InActive', |
| 156 | + "created_by" => $this->user->first_name, |
| 157 | + "created_at" => (\Carbon\Carbon::now())->toDateString() |
| 158 | + ], |
| 159 | + ]); |
| 160 | + |
| 161 | + } |
| 162 | + /** |
| 163 | + * Author: Indra Shastri |
| 164 | + * Date:03-03-2018 |
| 165 | + * A basic test to create a page from api |
| 166 | + * |
| 167 | + * @return void |
| 168 | + */ |
| 169 | + /** @test */ |
| 170 | + public function delete_page_in_db_and_get_response(){ |
| 171 | + $page = create(Page::class); |
| 172 | + $payload=[]; |
| 173 | + $response = $this->json('DELETE', '/api/v1/pages/'.$page->id, $payload, $this->headers); |
| 174 | + $response->assertStatus(200) |
| 175 | + ->assertJson([ |
| 176 | + "message"=> "The Page was successfully deleted." |
| 177 | + ]); |
| 178 | + } |
| 179 | +} |
0 commit comments