<?php
use App\Cms;
class CmsTest extends TestCase
{
    /**
     * Test to check get cms
     *
     * @return void
     */
    public function testCms()
    {
       $response = $this->call('GET', 'api/v1/cms/');
       $this->assertEquals(200, $response->status());
    }
    
    /**
     * Test to check get cms by id
     *
     * @return void
     */
    public function testGetCms()
    {
       $response = $this->call('GET', 'api/v1/cms/about');
       $this->assertEquals(200, $response->status());
       
       $this->get('api/v1/cms/qqq')
             ->seeJson([
                'status' => 'fail',
             ]);
    }
 
    
    /**
     * Test to check save cms
     *
     * @return void
     */
    public function testSaveCms()
    {
       $slug = str_random(20); 
       $this->post('api/v1/cms/', ['title' => 'test', 'description' => 'lorem', 'slug' => $slug])
             ->seeJson([
                'status' => 'success',
             ]);
       
       $response1 = $this->call('POST', 'api/v1/cms/', ['title' => 'test', 'description' => 'lorem', 'slug' => 'about']); 
       $this->assertNotEquals(200, $response1->status());
    }
    
    
    /**
     * Test to check update cms
     *
     * @return void
     */
    public function testUpdateCms()
    {

        $slug = str_random(20); 
        $cms           = new Cms();
        $cms->title = 'test title';
        $cms->slug = $slug;
        $cms->description = 'testing description';
        
        $date               = new \DateTime();
        $ddf                = $date->format('Y-m-d');
        $cms->created  = $ddf;
        $cms->save();

        $lastId = $cms->id;

       $response1 = $this->call('PUT', "api/v1/cms/$lastId", ['title' => 'test', 'description' => 'lorem']); 
       $this->assertEquals(200, $response1->status());
       $this->put('api/v1/cms/8121', ['title' => 'test', 'description' => 'lorem'])
             ->seeJson([
                'status' => 'fail',
             ]);
       Cms::destroy($lastId);      

    }
    

    /**
     * Test to check save branch
     *
     * @return void
     */
    public function testDeleteCms()
    {
        $slug = str_random(20); 
        $cms           = new Cms();
        $cms->title = 'test title';
        $cms->slug = $slug;
        $cms->description = 'testing description';
        
        $date               = new \DateTime();
        $ddf                = $date->format('Y-m-d');
        $cms->created  = $ddf;
        $cms->save();

        $lastId = $cms->id;

       $this->delete("api/v1/cms/$lastId")
             ->seeJson([
                'status' => 'success',
             ]);
    }
    
}
