Skip to content

Instantly share code, notes, and snippets.

@rickard2
Created July 18, 2012 11:26
Show Gist options
  • Save rickard2/3135689 to your computer and use it in GitHub Desktop.
Save rickard2/3135689 to your computer and use it in GitHub Desktop.
WordPress tests with wpdb
<?php
class testWPDB extends wpdb {
function prepare( $query, $arguments )
{
return vsprintf( $query, $arguments );
}
}
class UTCW_Test_Data extends WP_UnitTestCase {
protected $utcw;
function setUp()
{
$this->utcw = UTCW_Plugin::get_instance();
}
function getWPDBMock()
{
return $this->getMock( 'testWPDB', array( 'get_results' ), array(), '', false );
}
function test_author()
{
$instance[ 'authors' ] = array( 1, 2, 3 );
$config = new UTCW_Config( $instance, $this->utcw );
$db = $this->getWPDBMock( 'get_results' );
$db->expects( $this->once() )
->method( 'get_results' )
->with( $this->stringContains( 'post_author IN (1,2,3)' ) );
$data = new UTCW_Data( $config, $db );
$data->get_terms();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment