Giter Site home page Giter Site logo

dusk-wordpress's Introduction

dusk-wordpress

Laravel Dusk for WordPress (bedrock -https://roots.io/bedrock/)

Installing

composer require chadanuk/dusk-wordpress
File Structue

We suggest adding the following file structure:

  • phpunit.xml
  • .env.dusk (with test database name in it)
  • Tests
    • Browser
      • console
      • screenshots
        • ExampleTest.php
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/chadanuk/dusk-wordpress/bootstrap.php"
         backupGlobals="false"
         backupStaticAttributes="false"
         colors="true"
         verbose="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Dusk Wordpress Theme Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist>
            <directory suffix=".php">/</directory>
        </whitelist>
    </filter>
    <php>
        <env name="WP_ENV" value="testing"/>
        <env name="DB_NAME" value="database_name"/>
        <env name="DB_USER" value="root"/>
        <env name="DB_PASSWORD" value=""/>
        <env name="WP_THEME" value="theme_name"/>
        <const name="WP_INSTALLING" value="true"/>
    </php>
</phpunit>

Writing Tests

The assertions available to you are documented on the Laravel site (https://laravel.com/docs/5.6/dusk#available-assertions)

ExampleTest.php
<?php
namespace Tests\Browser;

use Chadanuk\DuskWordpressTests\Traits\WordpressPost;
use Chadanuk\DuskWordpressTests\TestCase as TestCase;

class ExampleTest extends TestCase
{
    /**
     * @test
     */
    public function can_see_home_page_title()
    {
        $postFactory = new \WP_UnitTest_Factory_For_Post();
        $postId = $postFactory->create_object([
            'post_title' => 'Home page title',
            'post_type' => 'page',
            'post_name' => 'home'
        ]);

        $this->browse(function ($browser) {
            $browser->visit('/')->screenshot('home')
                ->assertSee('Home page title');
        });
    }
}

Running Tests

vendor/bin/phpunit tests/Browser/ExampleTest.php

dusk-wordpress's People

Contributors

chadanuk avatar dependabot-preview[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.