2017 © Pedro Peláez
 

library unholy

Markup testing for WordPress using jQuery-style selectors.

image

danielbachhuber/unholy

Markup testing for WordPress using jQuery-style selectors.

  • Monday, April 11, 2016
  • by danielbachhuber
  • Repository
  • 2 Watchers
  • 9 Stars
  • 2,315 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Unholy

Build Status, (*1)

Markup testing for WordPress using jQuery-style selectors. Uses PHPUnit, the WordPress Unit Test Suite, QueryPath, and HTML5-PHP., (*2)

It's unholy, but it works., (*3)

Installing

These instructions presuppose you're already using PHPUnit and the WordPress Unit Test Suite with your project. If you do, you can:, (*4)

  1. Require Unholy using Composer: composer require danielbachhuber/unholy
  2. Install dependencies using Composer: composer install
  3. Load Unholy into your test suite by appending require dirname( dirname( __FILE__ ) ) . '/vendor/autoload.php'; to the end of your bootstrap.php.

Using

The Unholy_Testcase class extends the WP_UnitTestcase class. Update your project's test classes to extend Unholy_Testcase., (*5)

Extending the Unholy_Testcase class exposes two helper methods: get_permalink_as_dom() and get_feed_as_dom(). These can be used to get a DOMDocument-esque object representing the view. Then, use the qp() function to navigate the object using jQuery-style selectors., (*6)

As an example, here is how you might test the Twenty Fifteen theme for the site title and description in the header:, (*7)

<?php

class Test_TwentyFifteen_Theme extends Unholy_Testcase {

    public function test_header() {
        update_option( 'blogname', 'Unholy Site Title' );
        update_option( 'blogdescription', 'Unholy Site Description' );
        $dom = $this->get_permalink_as_dom( '/' );
        $this->assertEquals( 'Unholy Site Title', qp( $dom, '#masthead .site-title' )->text() );
        $this->assertEquals( 'Unholy Site Description', qp( $dom, '#masthead .site-description' )->text() );
    }

}

And here is how you might test your RSS feed for a post:, (*8)

<?php

class Test_RSS_Feed extends Unholy_Testcase {

    public function test_rss_feed_loads_post() {
        $user_id = $this->factory->user->create( array( 'display_name' => 'Unholy Author' ) );
        $this->factory->post->create( array( 'post_title' => 'Unholy Post Title', 'post_author' => $user_id ) );
        $dom = $this->get_feed_as_dom( '/feed/' );
        $this->assertEquals( 'Unholy Post Title', qp( $dom, 'channel item title' )->eq(0)->text() );
        $this->assertEquals( 'Unholy Author', qp( $dom, 'channel item dc|creator')->eq(0)->text() );
    }

}

The Versions

11/04 2016

dev-master

9999999-dev

Markup testing for WordPress using jQuery-style selectors.

  Sources   Download

MIT

The Requires