PHP code example of jcergolj / laravel-view-test-assertions

1. Go to this page and download the library: Download jcergolj/laravel-view-test-assertions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jcergolj / laravel-view-test-assertions example snippets




namespace Tests\Feature;

use Tests\TestCase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function test_example()
    {
        $response = $this->get('/');

        $response->assertStatus(200)
            ->assertViewHasForm() // first form is selected by default
            ->assertViewHasForm(null, 'post', '/users')
            ->assertFormHasField('text', 'first_name')
            ->assertFormHasRadioInput('gender')
            ->assertFormHasRadioInput('gender', 'male')
            ->assertFormHasCSRF()
            ->assertFormHasSubmitButton()
            ->assertFieldHasValidationErrorMsg(trans('validation.alpha', ['attribute' => 'First Name']))
            ->assertFormHasField('select', 'age')
            ->assertFormHasDropdown('age')
            ->assertFormHasCheckboxInput('confirm')
            ->assertFormHasCheckboxInput('confirm', 1)
            ->assertElementHasChild('select[name="age"]', 'option[value="5"]')
            ->assertElementHasChild('select[name="age"]', 'option:contains("5 Years")')
            ->assertElementHasChild('div#parent', 'div.child')
            ->selectFormElement('id="second"')
            ->assertViewHasForm(null, '/post')
            ->assertFormHasTextInput('title');

        // if multiple forms are presented on the page, personally would split assertions;
        $response->assertViewHasForm('id="second"')
            ->assertFormHasTextInput('title[]');
    }
}