-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from naogify/test-register-post-type
geolonia_gis_load_textdomain と register_post_type_maps にユニットテストを追加
- Loading branch information
Showing
9 changed files
with
200 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ node_modules/ | |
*.tar.gz | ||
*.zip | ||
vendor/ | ||
.phpunit.result.cache |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Class TestLoadTextdomain | ||
*/ | ||
|
||
class Test_LoadTextdomain extends WP_UnitTestCase { | ||
protected static $user_id; | ||
|
||
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | ||
self::$user_id = $factory->user->create( | ||
array( | ||
'role' => 'administrator', | ||
'locale' => 'ja', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @covers ::geolonia_gis_load_textdomain | ||
*/ | ||
public function test_load_textdomain() { | ||
|
||
add_filter('locale', function() { | ||
return 'ja'; | ||
}); | ||
$this->assertTrue( geolonia_gis_load_textdomain() ); | ||
} | ||
|
||
/** | ||
* @covers ::geolonia_gis_load_textdomain | ||
*/ | ||
public function test_load_textdomain_by_plugin_locale() { | ||
add_filter('plugin_locale', function() { | ||
return 'ja'; | ||
}); | ||
$this->assertTrue( geolonia_gis_load_textdomain() ); | ||
} | ||
|
||
/** | ||
* @covers ::geolonia_gis_load_textdomain | ||
*/ | ||
public function test_load_textdomain_when_locale_is_english() { | ||
add_filter('locale', function() { | ||
return 'en_US'; | ||
}); | ||
$this->assertFalse( geolonia_gis_load_textdomain() ); | ||
} | ||
|
||
/** | ||
* @covers ::geolonia_gis_load_textdomain | ||
*/ | ||
public function test_load_textdomain_plugin_locale_is_english() { | ||
add_filter('plugin_locale', function() { | ||
return 'en_US'; | ||
}); | ||
$this->assertFalse( geolonia_gis_load_textdomain() ); | ||
} | ||
|
||
/** | ||
* @covers ::geolonia_gis_load_textdomain | ||
*/ | ||
public function test_load_textdomain_user_locale_is_japanese() { | ||
|
||
add_filter('locale', function() { | ||
return 'en_US'; | ||
}); | ||
|
||
set_current_screen( 'dashboard' ); | ||
wp_set_current_user( self::$user_id ); | ||
|
||
$this->assertTrue( geolonia_gis_load_textdomain() ); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
class Test_Register_Post_Type_Maps extends WP_UnitTestCase { | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
|
||
unregister_post_type( 'maps' ); | ||
} | ||
|
||
/** | ||
* @covers ::register_post_type_maps | ||
*/ | ||
public function test_maps_post_type_registered() { | ||
|
||
$this->assertNull( get_post_type_object( 'maps' ) ); | ||
|
||
register_post_type_maps(); | ||
|
||
$maps_object = get_post_type_object( 'maps' ); | ||
|
||
$this->assertInstanceOf( 'WP_Post_Type', $maps_object ); | ||
$this->assertSame( 'maps', $maps_object->name ); | ||
} | ||
|
||
/** | ||
* @covers ::register_post_type_maps | ||
*/ | ||
public function test_maps_post_type_options() { | ||
|
||
$this->assertNull( get_post_type_object( 'maps' ) ); | ||
|
||
register_post_type_maps(); | ||
|
||
$maps_object = get_post_type_object( 'maps' ); | ||
|
||
// labels の設定値を確認 | ||
$this->assertSame( 'Map', $maps_object->label ); | ||
|
||
// public の設定値を確認 | ||
$this->assertTrue( $maps_object->public ); | ||
|
||
// hierarchical の設定値を確認 | ||
$this->assertFalse( $maps_object->hierarchical ); | ||
|
||
// show_ui の設定値を確認 | ||
$this->assertTrue( $maps_object->show_ui ); | ||
|
||
// show_in_menu の設定値を確認 | ||
$this->assertTrue( $maps_object->show_in_nav_menus ); | ||
|
||
// カスタム投稿タイプの supports に title が含まれているか確認 | ||
$this->assertTrue( post_type_supports( 'maps', 'title' ), 'Title support is enabled' ); | ||
|
||
// カスタム投稿タイプの supports に editor が含まれているか確認 | ||
$this->assertTrue( post_type_supports( 'maps', 'editor' ), 'Editor support is enabled' ); | ||
|
||
// カスタム投稿タイプの supports に author が含まれているか確認 | ||
$this->assertTrue( post_type_supports( 'maps', 'revisions' ), 'Revisions support is enabled' ); | ||
|
||
// カスタム投稿タイプの supports に excerpt が含まれているか確認 | ||
$this->assertTrue( post_type_supports( 'maps', 'excerpt' ), 'Excerpt support is enabled' ); | ||
|
||
// archive の設定値を確認 | ||
$this->assertFalse( $maps_object->has_archive ); | ||
|
||
// rewrite の設定値を確認 | ||
$this->assertSame( array('slug' => 'maps'), $maps_object->rewrite ); | ||
|
||
// query_var の設定値を確認 | ||
$this->assertSame( 'maps', $maps_object->query_var ); | ||
|
||
// menu_icon の設定値を確認 | ||
$this->assertSame( 'dashicons-location', $maps_object->menu_icon ); | ||
|
||
// show_in_rest の設定値を確認 | ||
$this->assertTrue( $maps_object->show_in_rest ); | ||
|
||
// rest_base の設定値を確認 | ||
$this->assertSame( GEOLONIA_GIS_POST_TYPE, $maps_object->rest_base ); | ||
|
||
// rest_controller_class の設定値を確認 | ||
$this->assertSame( 'WP_REST_Posts_Controller', $maps_object->rest_controller_class ); | ||
|
||
// taxonomies の設定値を確認 | ||
$this->assertSame( array( 'map_tag' ), $maps_object->taxonomies ); | ||
|
||
// capability_type の設定値を確認 | ||
$this->assertSame( 'map', $maps_object->capability_type ); | ||
|
||
// map_meta_cap の設定値を確認 | ||
$this->assertTrue( $maps_object->map_meta_cap ); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.