Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Last active May 5, 2016 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiroshi/d9055485db782bf6d9c8ff059a847fb8 to your computer and use it in GitHub Desktop.
Save s-hiroshi/d9055485db782bf6d9c8ff059a847fb8 to your computer and use it in GitHub Desktop.
WordPressのPHPUnitによる単体テストのサンプルです。
<?php
/**
* WP_UnitTestCaseのサンプル
*
* @package InfoTown
* @author Hiroshi Sawai <info@info-town.jp>
* @copyright Hiroshi Sawai
*/
class Sample_Test extends WP_UnitTestCase {
/**
* 単一ページテスト
*
* @link http://qiita.com/miya0001/items/8f1a777b455a8bdcbd62
*/
public function test_the_title() {
$post = $this->post_ids = $this->factory->post->create_and_get( [
'post_title' => 'Sample Post!',
] );
$this->go_to( '/?p=' . $post->ID );
$this->assertTrue( is_single() );
$this->expectOutputString( "Sample Post!" );
the_title();
}
/**
* アーカイブテスト
*/
public function test_single_cat_title() {
$cat = $this->factory->category->create_and_get( [ 'name' => 'Sample Category' ] );
$this->factory->post->create( [ 'post_category' => [ $cat->term_id ] ] );
$this->go_to( '/?cat=' . $cat->term_id );
$this->assertTrue( is_archive() );
$this->assertFalse( is_single() );
$this->expectOutputString( "Sample Category" );
single_cat_title();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment