PHP code example of nunomaduro / laravel-mojito

1. Go to this page and download the library: Download nunomaduro/laravel-mojito 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/ */

    

nunomaduro / laravel-mojito example snippets


class WelcomeTest extends TestCase
{
    // First, add the `InteractsWithViews` trait to your test case class.
    use InteractsWithViews; 

    public function testDisplaysLaravel()
    {
        // Then, get started with Mojito using the `assertView` method.
        $this->assertView('welcome')->contains('Laravel');
    }
}

class WelcomeTest extends TestCase
{
    public function testDisplaysLaravel()
    {
        $response = $this->get('/');

        $response->assertStatus(200);

        $response->assertView()->contains('Laravel');
    }
}

$this->assertView('button')->contains('Click me');
$this->assertView('button', ['submitText' => 'Cancel'])->contains('Cancel');

$this->assertView('welcome')->in('title')->contains('Laravel');
$this->assertView('welcome')->in('.content')->contains('Nova');

$this->assertView('empty')->in('.empty-div')->empty();

$this->assertView('welcome')->first('.links a')->contains('Docs');

$this->assertView('button')->has('button');

$this->assertView('welcome')->has('head');
$this->assertView('welcome')->in('body')->has('.content');

$this->assertView('button')->hasAttribute('attribute', 'value');
$this->assertView('button')->hasAttribute('data-attribute', 'value');

$this->assertView('welcome')->hasAttribute('lang', 'en');
$this->assertView('welcome')->in('head')->first('meta')->hasAttribute('charset','utf-8');

$this->assertView('button')->hasClass('btn');

$this->assertView('welcome')->in('.content')->at('div > p', 0)->hasClass('title');

$this->assertView('button')->hasLink(route('welcome'));

$this->assertView('welcome')->in('.links')->first('a')->hasLink('https://laravel.com/docs');
$this->assertView('welcome')->in('.links')->at('a', 6)->hasLink('https://vapor.laravel.com');
$this->assertView('welcome')->in('.links')->last('a')->hasLink('https://github.com/laravel/laravel');

$this->assertView('welcome')->in('.links a')->contains('Laracast');

$this->assertView('welcome')->last('.links a')->contains('GitHub');

$response->assertView()->hasMeta(['property' => 'og:title']);
$response->assertView()->hasMeta(['property' => 'og:title', 'content' => 'Laravel']);

use NunoMaduro\LaravelMojito\ViewAssertion;

// Within a service provider:
ViewAssertion::macro('hasCharset', function (string $charset) {
    return $this->in('head')->first('meta')->hasAttribute('charset', $charset);
});

// In your tests:
$this->assertView('welcome')->hasCharset('utf-8');