summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit/tests/query
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/tests/query')
-rw-r--r--tests/phpunit/tests/query/conditionals.php40
-rw-r--r--tests/phpunit/tests/query/postStatus.php6
-rw-r--r--tests/phpunit/tests/query/setupPostdata.php12
3 files changed, 39 insertions, 19 deletions
diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php
index 05278ffd7a..4b47317889 100644
--- a/tests/phpunit/tests/query/conditionals.php
+++ b/tests/phpunit/tests/query/conditionals.php
@@ -14,6 +14,22 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
protected $page_ids;
protected $post_ids;
+ /**
+ * ID of the user-a.
+ *
+ * @var int
+ */
+ public static $user_a_id;
+
+ /**
+ * Set up the shared fixture.
+ *
+ * @param WP_UnitTest_Factory $factory Factory instance.
+ */
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$user_a_id = $factory->user->create( array( 'user_login' => 'user-a' ) );
+ }
+
public function set_up() {
parent::set_up();
@@ -588,7 +604,6 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
// 'author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
// 'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
public function test_author_feed() {
- self::factory()->user->create( array( 'user_login' => 'user-a' ) );
// Check the long form.
$types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
foreach ( $types as $type ) {
@@ -607,7 +622,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
// 'author/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]',
public function test_author_paged() {
update_option( 'posts_per_page', 2 );
- $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
+ $user_id = self::$user_a_id;
self::factory()->post->create_many( 3, array( 'post_author' => $user_id ) );
$this->go_to( '/author/user-a/page/2/' );
$this->assertQueryTrue( 'is_archive', 'is_author', 'is_paged' );
@@ -615,14 +630,13 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
// 'author/([^/]+)/?$' => 'index.php?author_name=$matches[1]',
public function test_author() {
- $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
+ $user_id = self::$user_a_id;
self::factory()->post->create( array( 'post_author' => $user_id ) );
$this->go_to( '/author/user-a/' );
$this->assertQueryTrue( 'is_archive', 'is_author' );
}
public function test_author_with_no_posts() {
- $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
$this->go_to( '/author/user-a/' );
$this->assertQueryTrue( 'is_archive', 'is_author' );
}
@@ -1122,7 +1136,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
* @ticket 24674
*/
public function test_is_author_with_nicename_that_begins_with_a_number_that_clashes_with_another_author_id() {
- $u1 = self::factory()->user->create();
+ $u1 = self::$user_a_id;
$u2_name = $u1 . '_user';
$u2 = self::factory()->user->create(
@@ -1279,7 +1293,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
global $wpdb;
// We need a non-post that shares an ID with a post assigned a template.
- $user_id = self::factory()->user->create();
+ $user_id = self::$user_a_id;
if ( ! get_post( $user_id ) ) {
$post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
$wpdb->update( $wpdb->posts, array( 'ID' => $user_id ), array( 'ID' => $post_id ), array( '%d' ) );
@@ -1352,12 +1366,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
* @ticket 35902
*/
public function test_is_author_should_not_match_numeric_id_to_nickname_beginning_with_id() {
- $u1 = self::factory()->user->create(
- array(
- 'nickname' => 'Foo',
- 'user_nicename' => 'foo',
- )
- );
+ $u1 = self::$user_a_id;
$u2 = self::factory()->user->create(
array(
'nickname' => "$u1 Foo",
@@ -1375,12 +1384,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
* @ticket 35902
*/
public function test_is_author_should_not_match_numeric_id_to_user_nicename_beginning_with_id() {
- $u1 = self::factory()->user->create(
- array(
- 'nickname' => 'Foo',
- 'user_nicename' => 'foo',
- )
- );
+ $u1 = self::$user_a_id;
$u2 = self::factory()->user->create(
array(
'nickname' => 'Foo',
diff --git a/tests/phpunit/tests/query/postStatus.php b/tests/phpunit/tests/query/postStatus.php
index 238551b524..95e7968951 100644
--- a/tests/phpunit/tests/query/postStatus.php
+++ b/tests/phpunit/tests/query/postStatus.php
@@ -240,7 +240,11 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
)
);
- foreach ( get_post_stati( array( 'public' => true ) ) as $status ) {
+ $stati = get_post_stati( array( 'public' => true ) );
+
+ $this->assertNotEmpty( $stati );
+
+ foreach ( $stati as $status ) {
$this->assertStringContainsString( "post_status = '$status'", $q->request );
}
}
diff --git a/tests/phpunit/tests/query/setupPostdata.php b/tests/phpunit/tests/query/setupPostdata.php
index 985ae06f7a..ef6b3479d8 100644
--- a/tests/phpunit/tests/query/setupPostdata.php
+++ b/tests/phpunit/tests/query/setupPostdata.php
@@ -121,6 +121,9 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
'posts_per_page' => 1,
)
);
+
+ $this->assertTrue( $q->have_posts() );
+
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
@@ -221,6 +224,9 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
'post__in' => array( $post2 ),
)
);
+
+ $this->assertTrue( $q->have_posts() );
+
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
@@ -281,6 +287,9 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
'posts_per_page' => 1,
)
);
+
+ $this->assertTrue( $q->have_posts() );
+
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
@@ -367,6 +376,9 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
'posts_per_page' => 1,
)
);
+
+ $this->assertTrue( $q->have_posts() );
+
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();