dev-master
9999999-devMarkup testing for WordPress using jQuery-style selectors.
MIT
The Requires
- php >=5.3.0
- masterminds/html5 ^2.1
- querypath/querypath ^3.0.4
Wallogit.com
2017 © Pedro Peláez
Markup testing for WordPress using jQuery-style selectors.
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)
These instructions presuppose you're already using PHPUnit and the WordPress Unit Test Suite with your project. If you do, you can:, (*4)
composer require danielbachhuber/unholy
composer install
require dirname( dirname( __FILE__ ) ) . '/vendor/autoload.php'; to the end of your bootstrap.php.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() );
}
}
Markup testing for WordPress using jQuery-style selectors.
MIT