Changeset 36077 for trunk/tests/phpunit/tests/link.php
- Timestamp:
- 12/23/2015 07:38:29 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/link.php
r35497 r36077 99 99 100 100 /** 101 * @ticket 17807102 */103 function test_get_adjacent_post() {104 // Need some sample posts to test adjacency105 $post_one = self::factory()->post->create_and_get( array(106 'post_title' => 'First',107 'post_date' => '2012-01-01 12:00:00'108 ) );109 110 $post_two = self::factory()->post->create_and_get( array(111 'post_title' => 'Second',112 'post_date' => '2012-02-01 12:00:00'113 ) );114 115 $post_three = self::factory()->post->create_and_get( array(116 'post_title' => 'Third',117 'post_date' => '2012-03-01 12:00:00'118 ) );119 120 $post_four = self::factory()->post->create_and_get( array(121 'post_title' => 'Fourth',122 'post_date' => '2012-04-01 12:00:00'123 ) );124 125 // Assign some terms126 wp_set_object_terms( $post_one->ID, 'wordpress', 'category', false );127 wp_set_object_terms( $post_three->ID, 'wordpress', 'category', false );128 129 wp_set_object_terms( $post_two->ID, 'plugins', 'post_tag', false );130 wp_set_object_terms( $post_four->ID, 'plugins', 'post_tag', false );131 132 // Test normal post adjacency133 $this->go_to( get_permalink( $post_two->ID ) );134 135 $this->assertEquals( $post_one, get_adjacent_post( false, '', true ) );136 $this->assertEquals( $post_three, get_adjacent_post( false, '', false ) );137 138 $this->assertNotEquals( $post_two, get_adjacent_post( false, '', true ) );139 $this->assertNotEquals( $post_two, get_adjacent_post( false, '', false ) );140 141 // Test category adjacency142 $this->go_to( get_permalink( $post_one->ID ) );143 144 $this->assertEquals( '', get_adjacent_post( true, '', true, 'category' ) );145 $this->assertEquals( $post_three, get_adjacent_post( true, '', false, 'category' ) );146 147 // Test tag adjacency148 $this->go_to( get_permalink( $post_two->ID ) );149 150 $this->assertEquals( '', get_adjacent_post( true, '', true, 'post_tag' ) );151 $this->assertEquals( $post_four, get_adjacent_post( true, '', false, 'post_tag' ) );152 153 // Test normal boundary post154 $this->go_to( get_permalink( $post_two->ID ) );155 156 $this->assertEquals( array( $post_one ), get_boundary_post( false, '', true ) );157 $this->assertEquals( array( $post_four ), get_boundary_post( false, '', false ) );158 159 // Test category boundary post160 $this->go_to( get_permalink( $post_one->ID ) );161 162 $this->assertEquals( array( $post_one ), get_boundary_post( true, '', true, 'category' ) );163 $this->assertEquals( array( $post_three ), get_boundary_post( true, '', false, 'category' ) );164 165 // Test tag boundary post166 $this->go_to( get_permalink( $post_two->ID ) );167 168 $this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) );169 $this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );170 }171 172 /**173 * @ticket 22112174 */175 function test_get_adjacent_post_exclude_self_term() {176 // Bump term_taxonomy to mimic shared term offsets.177 global $wpdb;178 $wpdb->insert( $wpdb->term_taxonomy, array( 'taxonomy' => 'foo', 'term_id' => 12345, 'description' => '' ) );179 180 $include = self::factory()->term->create( array(181 'taxonomy' => 'category',182 'name' => 'Include',183 ) );184 $exclude = self::factory()->category->create();185 186 $one = self::factory()->post->create_and_get( array(187 'post_date' => '2012-01-01 12:00:00',188 'post_category' => array( $include, $exclude ),189 ) );190 191 $two = self::factory()->post->create_and_get( array(192 'post_date' => '2012-01-02 12:00:00',193 'post_category' => array(),194 ) );195 196 $three = self::factory()->post->create_and_get( array(197 'post_date' => '2012-01-03 12:00:00',198 'post_category' => array( $include, $exclude ),199 ) );200 201 $four = self::factory()->post->create_and_get( array(202 'post_date' => '2012-01-04 12:00:00',203 'post_category' => array( $include ),204 ) );205 206 $five = self::factory()->post->create_and_get( array(207 'post_date' => '2012-01-05 12:00:00',208 'post_category' => array( $include, $exclude ),209 ) );210 211 // First post212 $this->go_to( get_permalink( $one ) );213 $this->assertEquals( $two, get_adjacent_post( false, array(), false ) );214 $this->assertEquals( $three, get_adjacent_post( true, array(), false ) );215 $this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), false ) );216 $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), false ) );217 $this->assertEmpty( get_adjacent_post( false, array(), true ) );218 219 // Fourth post220 $this->go_to( get_permalink( $four ) );221 $this->assertEquals( $five, get_adjacent_post( false, array(), false ) );222 $this->assertEquals( $five, get_adjacent_post( true, array(), false ) );223 $this->assertEmpty( get_adjacent_post( false, array( $exclude ), false ) );224 $this->assertEmpty( get_adjacent_post( true, array( $exclude ), false ) );225 226 $this->assertEquals( $three, get_adjacent_post( false, array(), true ) );227 $this->assertEquals( $three, get_adjacent_post( true, array(), true ) );228 $this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), true ) );229 $this->assertEmpty( get_adjacent_post( true, array( $exclude ), true ) );230 231 // Last post232 $this->go_to( get_permalink( $five ) );233 $this->assertEquals( $four, get_adjacent_post( false, array(), true ) );234 $this->assertEquals( $four, get_adjacent_post( true, array(), true ) );235 $this->assertEquals( $four, get_adjacent_post( false, array( $exclude ), true ) );236 $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), true ) );237 $this->assertEmpty( get_adjacent_post( false, array(), false ) );238 }239 240 /**241 * @ticket 32833242 */243 public function test_get_adjacent_post_excluded_terms() {244 register_taxonomy( 'wptests_tax', 'post' );245 246 $t = self::factory()->term->create( array(247 'taxonomy' => 'wptests_tax',248 ) );249 250 $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );251 $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );252 $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );253 254 wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );255 256 // Fake current page.257 $_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;258 $GLOBALS['post'] = get_post( $p1 );259 260 $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );261 262 if ( ! is_null( $_post ) ) {263 $GLOBALS['post'] = $_post;264 } else {265 unset( $GLOBALS['post'] );266 }267 268 // Should skip $p2, which belongs to $t.269 $this->assertEquals( $p3, $found->ID );270 }271 272 /**273 * @ticket 32833274 */275 public function test_get_adjacent_post_excluded_terms_should_not_require_posts_to_have_terms_in_any_taxonomy() {276 register_taxonomy( 'wptests_tax', 'post' );277 278 $t = self::factory()->term->create( array(279 'taxonomy' => 'wptests_tax',280 ) );281 282 $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );283 $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );284 $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );285 286 wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );287 288 // Make sure that $p3 doesn't have the 'Uncategorized' category.289 wp_delete_object_term_relationships( $p3, 'category' );290 291 // Fake current page.292 $_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;293 $GLOBALS['post'] = get_post( $p1 );294 295 $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );296 297 if ( ! is_null( $_post ) ) {298 $GLOBALS['post'] = $_post;299 } else {300 unset( $GLOBALS['post'] );301 }302 303 // Should skip $p2, which belongs to $t.304 $this->assertEquals( $p3, $found->ID );305 }306 307 /**308 101 * @ticket 30910 309 102 */
Note: See TracChangeset
for help on using the changeset viewer.