| 1357 | /** |
| 1358 | * Test that setting void category for CPT associated with 'category' taxonomy has default category. |
| 1359 | * |
| 1360 | * @ticket 43516 |
| 1361 | */ |
| 1362 | function test_set_post_category_cpt_default_category () { |
| 1363 | add_filter( 'default_category_post_types', array( $this, 'filter_default_category_post_types' ) ); |
| 1364 | |
| 1365 | $term = wp_insert_term( 'Foo', 'category' ); |
| 1366 | |
| 1367 | $post_id = wp_insert_post( array( 'post_title' => 'Foo', 'post_category' => array( $term['term_id'] ) ) ); |
| 1368 | $post = get_post( $post_id ); |
| 1369 | $this->assertInternalType( 'array', $post->post_category ); |
| 1370 | $this->assertEquals( $term['term_id'], $post->post_category[0] ); |
| 1371 | |
| 1372 | // Reset categories |
| 1373 | wp_set_post_categories( $post_id, array() ); |
| 1374 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1375 | |
| 1376 | register_post_type( 'cpt', array( 'taxonomies' => array( 'category' ) ) ); |
| 1377 | $post_id = wp_insert_post( array( 'post_title' => 'Foo', 'post_type' => 'cpt', 'post_category' => array( $term['term_id'] ) ) ); |
| 1378 | $post = get_post( $post_id ); |
| 1379 | |
| 1380 | // Reset categories |
| 1381 | wp_set_post_categories( $post_id, array() ); |
| 1382 | $this->assertInternalType( 'array', $post->post_category ); |
| 1383 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1384 | |
| 1385 | remove_filter( 'default_category_post_types', array( $this, 'filter_default_category_post_types' ) ); |
| 1386 | } |
| 1387 | |
| 1388 | /** |
| 1389 | * Test that new 'post' and CPT associated with 'category' taxonomy has default category. |
| 1390 | * |
| 1391 | * @ticket 43516 |
| 1392 | */ |
| 1393 | function test_insert_post_cpt_default_category () { |
| 1394 | add_filter( 'default_category_post_types', array( $this, 'filter_default_category_post_types' ) ); |
| 1395 | |
| 1396 | $post_id = wp_insert_post( array( 'post_title' => 'Foo' ) ); |
| 1397 | $post = get_post( $post_id ); |
| 1398 | $this->assertInternalType( 'array', $post->post_category ); |
| 1399 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1400 | |
| 1401 | register_post_type( 'cpt', array( 'taxonomies' => array( 'category' ) ) ); |
| 1402 | $post_id = wp_insert_post( array( 'post_title' => 'Foo', 'post_type' => 'cpt' ) ); |
| 1403 | $post = get_post( $post_id ); |
| 1404 | $this->assertInternalType( 'array', $post->post_category ); |
| 1405 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1406 | |
| 1407 | remove_filter( 'default_category_post_types', array( $this, 'filter_default_category_post_types' ) ); |
| 1408 | } |
| 1409 | |
| 1410 | function filter_default_category_post_types ( $post_types ) { |
| 1411 | $post_types[] = 'cpt'; |
| 1412 | return $post_types; |
| 1413 | } |