WordPress.org

Make WordPress Core

Changeset 479 in tests


Ignore:
Timestamp:
11/28/11 21:49:23 (2 years ago)
Author:
nacin
Message:

Unit tests for post type and taxonomy names with pseudo-reserved prefixes and suffixes. see #WP19353.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_admin_includes_screen.php

    r470 r479  
    9393    } 
    9494 
    95     function test_convert_to_screen_with_post_type() { 
     95    function test_post_type_as_hookname() { 
    9696        $screen = convert_to_screen( 'page' ); 
    9797        $this->assertEquals( $screen->post_type, 'page' ); 
     
    9999        $this->assertEquals( $screen->id, 'page' ); 
    100100    } 
     101 
     102    function test_post_type_with_special_suffix_as_hookname() { 
     103        register_post_type( 'value-add' ); 
     104        $screen = convert_to_screen( 'value-add' ); // the -add part is key. 
     105        $this->assertEquals( $screen->post_type, 'value-add' ); 
     106        $this->assertEquals( $screen->base, 'post' ); 
     107        $this->assertEquals( $screen->id, 'value-add' ); 
     108 
     109        $screen = convert_to_screen( 'edit-value-add' ); // the -add part is key. 
     110        $this->assertEquals( $screen->post_type, 'value-add' ); 
     111        $this->assertEquals( $screen->base, 'edit' ); 
     112        $this->assertEquals( $screen->id, 'edit-value-add' ); 
     113    } 
     114 
     115    function test_taxonomy_with_special_suffix_as_hookname() { 
     116        register_taxonomy( 'old-or-new', 'post' ); 
     117        $screen = convert_to_screen( 'edit-old-or-new' ); // the -new part is key. 
     118        $this->assertEquals( $screen->taxonomy, 'old-or-new' ); 
     119        $this->assertEquals( $screen->base, 'edit-tags' ); 
     120        $this->assertEquals( $screen->id, 'edit-old-or-new' ); 
     121 
     122        // convert_to_screen() can work with a taxonomy name, even though it doesn't occur in the wild. 
     123        $screen2 = convert_to_screen( 'old-or-new' ); 
     124        $this->assertEquals( $screen2->taxonomy, 'old-or-new' ); 
     125        $this->assertEquals( $screen2->base, 'edit-tags' ); 
     126        $this->assertEquals( $screen2->id, 'edit-old-or-new' ); 
     127 
     128        // These two convert_to_screen() calls should yield the same WP_Screen. 
     129        $this->assertSame( $screen, $screen2 ); 
     130    } 
     131 
     132    function test_post_type_with_edit_prefix() { 
     133        register_post_type( 'edit-some-thing' ); 
     134        $screen = convert_to_screen( 'edit-some-thing' ); 
     135        $this->assertEquals( $screen->post_type, 'edit-some-thing' ); 
     136        $this->assertEquals( $screen->base, 'post' ); 
     137        $this->assertEquals( $screen->id, 'edit-some-thing' ); 
     138 
     139        $screen = convert_to_screen( 'edit-edit-some-thing' ); 
     140        $this->assertEquals( $screen->post_type, 'edit-some-thing' ); 
     141        $this->assertEquals( $screen->base, 'edit' ); 
     142        $this->assertEquals( $screen->id, 'edit-edit-some-thing' ); 
     143    } 
    101144} 
Note: See TracChangeset for help on using the changeset viewer.