Last active
May 5, 2016 07:38
-
-
Save s-hiroshi/d9055485db782bf6d9c8ff059a847fb8 to your computer and use it in GitHub Desktop.
WordPressのPHPUnitによる単体テストのサンプルです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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