Giter Site home page Giter Site logo

wp-codeception's Introduction

WP Codeception

This is a WordPress Plugin which integrates with the Codeception PHP testing framework and allows you to write and run Codeception tests for WordPress via WP CLI.

Support Level

We're working towards supporting all of Codeceptions commands. If you find one we haven't included yet, please submit a Pull Request!

Installation

Download the latest version and extract, or clone the repository with Git into a new directory wp-content/plugins/wp-codeception in your WordPress install.

Install required node modules and composer dependencies

We'll run our commands from within VVV because WP CLI, Node, and Composer are already installed for us there.

$ vagrant up
$ vagrant ssh
$ sudo apt-get install openjdk-7-jre-headless
$ cd /srv/www/yoursite/htdocs/wp-content/plugins/wp-codeception
$ composer install
$ wp plugin activate wp-codeception

Afterwards you'll have a new vendor directory within your plugins/wp-codeception directory which contains all the code libraries we're dependant on.

Install as a composer dependency

There is an alternative way to install this plugin. You can add it as a composer dependency for your project. To do it, run following command in your terminal:

$ composer require 10up/wp-codeception

This command will install the plugin and all its dependencies for your project. Please, pay attention that if you already use composer/installers dependency in your project, then wp-codeception will be installed into <PROJECT_DIR>/wp-content/plugins/wp-codeception/ folder. It happens, because wp-codeception has wordpress-plugin type and will be processed by composer/installers accordingly (read its documentation for more details).

If you want to add it as a dependency to your plugin or theme, you will need to update your composer.json file and tell it where to install wp-codeception. You can achieve it by providing installer-paths instructions like in the snippet below.

{
    ...,
    "extra": {
        "installer-paths": {
            "vendor/{$name}/": ["type:wordpress-plugin"]
        }
    },
    ...
}

Now composer/installers will know to install wordpress plugins into vendor folder. The final step which you need to do is to update your autoload section and add wp-codeception.php file to the autoload files list.

{
    ...,
    "autoload": {
        "psr-X": {
            ...
        },
        "files": [
            ...,
            "vendor/wp-codeception/wp-codeception.php"
        ]
    },
    ...
}

Install the test suite

See the Codeception bootstrapping documentation for further information.

# You'll create the test suite in your own plugin or theme directory..
$ cd /srv/www/yoursite/htdocs/wp-content/{your plugin or theme directory}
$ wp codeception bootstrap

Afterwards you'll have a new tests directory within your plugin or theme directory. This is your new test suite, and where you'll write all your tests.

Writing Tests

You can write tests using any of the three Codeception testing frameworks: Acceptance, Functional and Unit testing. If you look within the new tests directory you'll see three config files; one for each test framework (acceptance.suite.yml, functional.suite.yml, unit.suite.yml). Edit these files as you wish.

Generate your first test

# You should be in the plugin or theme directory where you ran the bootstrap
$ wp codeception generate-(cept|cest) (acceptance|functional|unit) MyTestName

# Example
$ wp codeception generate-cept acceptance LoginTest

Afterwards you'll have a new file in your plugin or theme directory tests/acceptance/LoginTest.php, where you can write your first test. Remember, any Codeception test will work here! For example, you could run any of the acceptance test examples mentioned in the Codeception documentation. Likewise, the same goes for Functional and Unit tests.

Example: Writing a Login Acceptance Test

<?php

// Make sure you've added your site URL to acceptance.suite.yml
// @see http://codeception.com/docs/03-AcceptanceTests#PHP-Browser
$I = new AcceptanceTester( $scenario );
$I->wantTo( 'Ensure WordPress Login Works' );

// Let's start on the login page
$I->amOnPage( wp_login_url() );

// Populate the login form's user id field
$I->fillField( 'input#user_login', 'YourUsername' );

// Popupate the login form's password field
$I->fillField( 'input#user_pass', 'YourPassword' );

// Submit the login form
$I->click( 'Log In' );

// Validate the successful loading of the Dashboard
$I->see( 'Dashboard' );

Running Your Tests

Now you've written some tests, it's time to run them! But first..

Selenium

If you've created any browser automation/acceptance tests you'll need to turn Selenium on, and likewise, you'll want to stop Selenium after you're through running tests.

# You can run these commands from anywhere in your WordPress install
$ wp selenium start

# Stop Selenium when you're through
$ wp selenium stop

Run

You'll use the run command to execute your tests from within your plugin or theme directory (where you ran the bootstrap). We've implemented most of the Codeception 'run' command arguments, but if you find one we've missed please submit a Pull Request!

# You should be in the plugin or theme directory where you ran the bootstrap
$ wp codeception run

Example: Running our Login Test

# You should be in the plugin or theme directory where you ran the bootstrap
# Let's display verbose output
$ wp codeception run -vvv

Codeception PHP Testing Framework v2.0.11
Powered by PHPUnit 4.5.1 by Sebastian Bergmann and contributors.

  Rebuilding AcceptanceTester...

Acceptance-production Tests (1) ---------------------------------
Modules: WebDriver, WordPress, AcceptanceHelper
-----------------------------------------------------------------
Ensure WordPress Login Works (LoginTest)
Scenario:
* I am on page "http://site.com/wp-login.php"
* I fill field "input#user_login","YourUsername"
* I fill field "input#user_pass","YourPassword"
* I click "Login"
* I see "Dashboard"
 PASSED

Support Level

Archived: This project is no longer maintained by 10up. We are no longer responding to Issues or Pull Requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!

Like what you see?

wp-codeception's People

Contributors

aaronholbrook avatar cmmarslender avatar eugene-manuilov avatar gedex avatar jeffpaul avatar jonathanbardo avatar tlovett1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-codeception's Issues

Add Documentation

This took a bit to get running, I think we could ease that with more documentation

"UnknownServerException" in webdriver after composer update

I get the following UnknownServerException and unable to successfully run tests.

vagrant@vvv:/srv/www/wbu-test/public_html/wp-content/plugins/wbu-newsletters$ wp selenium start
Success: Selenium server started.
vagrant@vvv:/srv/www/wbu-test/public_html/wp-content/plugins/wbu-newsletters$ wp codeception run -vvv
Codeception PHP Testing Framework v2.0.11
Powered by PHPUnit 4.5.1 by Sebastian Bergmann and contributors.


  [UnknownServerException]


Exception trace:
 () at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/facebook/webdriver/lib/WebDriverExceptions.php:79
 WebDriverException::throwException() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/facebook/webdriver/lib/remote/HttpCommandExecutor.php:268
 HttpCommandExecutor->execute() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/facebook/webdriver/lib/remote/RemoteWebDriver.php:81
 RemoteWebDriver::create() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/codeception/codeception/src/Codeception/Module/WebDriver.php:130
 Codeception\Module\WebDriver->_initialize() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/classes/WPCC/SuiteManager.php:65
 WPCC\SuiteManager->initializeModules() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/codeception/codeception/src/Codeception/SuiteManager.php:60
 Codeception\SuiteManager->initialize() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/classes/WPCC/Codecept.php:81
 WPCC\Codecept->runSuite() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/codeception/codeception/src/Codeception/Codecept.php:149
 Codeception\Codecept->run() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/codeception/codeception/src/Codeception/Command/Run.php:262
 Codeception\Command\Run->runSuites() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/classes/WPCC/Command/Run.php:113
 WPCC\Command\Run->execute() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/symfony/console/Command/Command.php:266
 Symfony\Component\Console\Command\Command->run() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/symfony/console/Application.php:856
 Symfony\Component\Console\Application->doRunCommand() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/symfony/console/Application.php:203
 Symfony\Component\Console\Application->doRun() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/vendor/symfony/console/Application.php:127
 Symfony\Component\Console\Application->run() at /srv/www/wbu-test/public_html/wp-content/plugins/wp-codeception/classes/WPCC/CLI/Codeception.php:139
 WPCC\CLI\Codeception->run() at n/a:n/a
 call_user_func() at phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php:81
 WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}() at n/a:n/a
 call_user_func() at phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php:401
 WP_CLI\Dispatcher\Subcommand->invoke() at phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:323
 WP_CLI\Runner->run_command() at phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:330
 WP_CLI\Runner->_run_command() at phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:937
 WP_CLI\Runner->start() at phar:///usr/local/bin/wp/php/WP_CLI/Bootstrap/LaunchRunner.php:23
 WP_CLI\Bootstrap\LaunchRunner->process() at phar:///usr/local/bin/wp/php/bootstrap.php:75
 WP_CLI\bootstrap() at phar:///usr/local/bin/wp/php/wp-cli.php:23
 include() at phar:///usr/local/bin/wp/php/boot-phar.php:8
 include() at /usr/local/bin/wp:4

run [-c|--config CONFIG] [--report] [--html [HTML]] [--xml [XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-sg|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--] [<suite>] [<test>]

Documentation

Hey all.. how 'bout we give these docs some tlc?.. a little.. lovin..

Any thoughts, snippets, examples, suggestions?!?... lay it out here! :) We can work in feature/documentation; starting small and submitting PRs. I'll push some initial stuff to get the ball roll and will try to contribute as much as possible.

License?

Please may the license for this package be clarified?

Use in the wild or documentation

It seems that this project does not line up with Codeception documentation.

Tests work great but I can not figure out how to eliminate redundant code such as login with Cests?

Generating Steps and using --steps just hung with VVV and had to power down. So that did not work.

So my question is how to runs Cest test cases without needing login code in each test or any other redundant action.

Or do you have test cases in a plugin to look at as an example.

npm is throwing a warning because of wrong licence

Hi fellas,

Thank you for this nice plugin :)

While trying to install it, I saw that npm didn't actually start as in some latest update, it changed the way it handles licence.

I believe this can be fixed by adjusting the licence in your package.json to "GPL-2.0+"

Your requirements could not be resolved to an installable set of packages.

After composer install I'm getting
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

followed by Your requirements could not be resolved to an installable set of packages.

So no vendor folder is installed.

Codeception version 2+

Hello to the team and well done for your plugin!

Is there any plans for upgrading codeception to version 2+ or is there any way how we can accomplish it?

Thank you very much in advanced.

Publish plugin on wordpress.org

Hey @tlovett1,

Can we publish this plugin on wordpress.org? If we publish it there, then it will appear on the http://wpackagist.org/ site and everybody will be able to install it via composer as a dependecy. What do you think?

If we go this route, then I will need to prepare a new build which will contain proper composer.json file and dependant libraries.

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.