Work on my WPBrowser package for Composer goes on and I’ve been busy adding some methods to the WordPress Database Codeception module. The intent is to create a Codeception module that’s both a drop-in replacement for the default one and something that will address my WordPress specific needs in functional and acceptance testing.
A thorough source code snooping into WordPress GitHub repository led me to add the following methods
public function havePostInDatabase($ID, array $data = array());
public function seePostInDatabase(array $criteria);
public function havePageInDatabase($ID, array $data = array());
public function seePageInDatabase(array $criteria);
to the module. The signatures are self-explanatory and a brief use case might be
<?php
$I = new AcceptanceTester($scenario);
$I->am('an admin');
$I->wantTo('create and see posts and pages');
// create a post with an ID of 10
$I->havePostInDatabase(10);
// check for the post in the DB
$I->seePostInDatabase(array('ID' => 10));
// create a page with an ID of 113
$I->havePageInDatabase(113);
// check for the page in the DB
$I->seePageInDatabase(array('ID' => 113));
// post and page creation can get down to the minute detail
$I->havePostInDatabase(11, array(
'post_title' => 'Some event',
'post_content' => 'The content here.',
'post_type' => 'event'
));
// pages are posts
$I->havePostInDatabase(12, array(
'post_title' => 'Some page',
'post_content' => 'The content here.',
'post_type' => 'page'
));
the $criteria
array will support any parameter that would be passed to the wp_insert_post
function.
Next
Since I’ve begun working on it I will implement methods, and accessory classes, for all of test-relevant WordPress tables and I guess the next ones are comments and terms tables.