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