Returns a post ID after creating a post for the testing.
int $this->factory->post->create( array $post[, array $generation_definitions] );
Returns a post ID after creating a post for the testing.
(array) (required) An array representing the elements that make up a post.
Key | Description | Example value |
---|---|---|
post_content | The full text of the post. | Hello World! |
post_name | The name (slug) for your post | hello-world |
post_title | The title of your post. | Hello World! |
post_status | The status of the post. | publish |
post_type | The post type. | post |
post_author | The user ID number of the author. | 1 |
post_excerpt | For all your post excerpt needs. | Hello World! |
post_date | The time post was made. | 2014-11-11 23:45:30 |
There are other parameters, see codex.
(array) (optional) The Generation definitions of the post.
$this->default_generation_definitions = array(
'post_status' => 'publish',
'post_title' => new WP_UnitTest_Generator_Sequence( 'Post title %s' ),
'post_content' => new WP_UnitTest_Generator_Sequence( 'Post content %s' ),
'post_excerpt' => new WP_UnitTest_Generator_Sequence( 'Post excerpt %s' ),
'post_type' => 'post'
);
(int) The ID of the post.
<?php
class SampleTest extends WP_UnitTestCase {
function testSample() {
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello!' ) );
$this->assertEquals( 'Hello!', get_the_title( $post_id ) );
}
}
$this->factory->post->create_and_get();
$this->factory->post->create_many();
$this->factory->attachment->create();
$this->factory->attachment->create_and_get();
Returns a user ID after creating a new user for the testing.
int $this->factory->user->create( array $userdata[, array $generation_definitions] );
(mixed) (required) An array of user data, stdClass or WP_User object. Default: None
Field Name | Description | Example value |
---|---|---|
user_login | A string that contains the user’s username for logging in. | user1 |
user_nicename | A string that contains a URL-friendly name for the user. The default is the user’s username. | userone |
user_url | A string containing the user’s URL for the user’s web site. | http://example.com |
user_email | A string containing the user’s email address. | hoge@example.com |
display_name | A string that will be shown on the site. Defaults to user’s username. It is likely that you will want to change this, for both appearance and security through obscurity (that is if you dont use and delete the default admin user). | John Doe |
first_name | The user’s first name. | John |
last_name | The user’s last name. | Doe |
There are other parameters, see codex.
(array) (optional) The Generation definitions of the user.
$this->default_generation_definitions = array(
'user_login' => new WP_UnitTest_Generator_Sequence( 'User %s' ),
'user_pass' => 'password',
'user_email' => new WP_UnitTest_Generator_Sequence( 'user_%s@example.org' ),
);