Dev Docs
  • Disciple.Tools Technical Documentation
  • Theme Core
    • API - Posts
      • List of Endpoints
      • Fields Format
      • Get Post
      • Create Post
      • Update Post
      • Post Comments
      • Post Activity
      • List Query
      • Global Search
      • Posts in Typeaheads
      • Post-Sharing
      • Get Following
      • Settings
    • API - Other
      • Users
      • Locations
      • Settings
    • Hooks
      • Record Page Hooks
      • API-Hooks
      • Public settings
      • Adding menu navigation links
    • Customization
      • Fields
      • Custom Post Types
      • Post Type Modules
      • Adding Fields and Tiles.
    • Authentication
      • JWT-Authentication-for-the-mobile-app
      • Site-to-Site-Link
      • Easy-Example
    • Permissions
    • Roles and Permissions
    • Database Tables
      • Activity Table
    • Disciple.Tools Translation
    • Revisions
      • v1.0.0-dev-changes
      • v1.0
  • Hosting
    • 404 Errors on new install
    • CRON
    • Hosting on WPEngine
    • Backups
    • Single Site or MultiSite
  • Disciple.Tools Development Setup
    • LocalWP
    • Mobile App Setup
    • Unit Tests
    • Cypress Tests
    • D.T on Docker Setup
    • Gulp - CSS and JS
  • Code Contribution
    • Theme Contribution Guidelines
    • How to Correctly Contribute to the Disciple Tools Repository
    • How to Translate Your Plugin
  • Style Guide
  • Disciple.Tools Code of Conduct
Powered by GitBook
On this page
  • Setup testing environment
  • Running the tests
  • Writing tests

Was this helpful?

Edit on Git
  1. Disciple.Tools Development Setup

Unit Tests

Setup testing environment

In the theme root within your environment (localWP: "Open site shell" option) run:

./tests/install-wp-tests.sh <db-name> <db-user> <db-pass> [db-host]
  • <db-name> is the name of the db you want the run the tests in. We suggest creating a separate db form your dev db for testing.

  • <db-user> Database username

  • <db-pass> Database password

  • [db-host] Database url and port. For localWP get the port from the url when opening Adminer.

Note for localWP on linux the command looks like this for localWP: ./tests/install-wp-tests.sh local-test root root localhost:10063

Notes:

  • On localWP, make sure you are running from the "Open site shell" menu option, so the environment is loaded

  • On localWP, remove --protocal=tcp on line #141 of ./tests/install-wp-tests.sh

  • On localWP, you can get the database port from the browser url after opening adminer

  • You may need to install svn: sudo apt install subversion

  • If you get an error that looks like: Could not find /{path}/wordpress-tests-lib /includes/functions.php, have you run tests/install-wp-tests.sh ? delete the temp folder and run the install again.

Running the tests

Install phpunit and phpunit-polyfills form the theme root.

composer require "phpunit/phpunit=7.5.*"
composer require "yoast/phpunit-polyfills"

Run ./vendor/bin/phpunit

The tests need phpunit v7. v8 and above currently don't work.

Writing tests

  • tests are located in the theme ./tests folder

  • unit test files need to start with 'unit-test'

  • unit test function need to start with 'test_'

PreviousMobile App SetupNextCypress Tests

Last updated 3 years ago

Was this helpful?

phpunit documentation

assertions:

https://phpunit.readthedocs.io/en/7.5
https://phpunit.readthedocs.io/en/7.5/assertions.html