Make WordPress Core

Ticket #38157: 38157.diff

File 38157.diff, 4.6 KB (added by swissspidy, 8 years ago)
  • new file tests/phpunit/tests/post/getPostTypeLabels.php

    diff --git tests/phpunit/tests/post/getPostTypeLabels.php tests/phpunit/tests/post/getPostTypeLabels.php
    new file mode 100644
    index 0000000..c0d0cfb
    - +  
     1<?php
     2
     3/**
     4 * @group post
     5 */
     6class Tests_Get_Post_Type_Labels extends WP_UnitTestCase {
     7        public function test_returns_an_object() {
     8                $this->assertInternalType( 'object', get_post_type_labels( (object) array(
     9                        'name'         => 'foo',
     10                        'labels'       => array(),
     11                        'hierarchical' => false,
     12                ) ) );
     13        }
     14
     15        public function test_returns_hierachical_labels() {
     16                $labels = get_post_type_labels( (object) array(
     17                        'name'         => 'foo',
     18                        'labels'       => array(),
     19                        'hierarchical' => true,
     20                ) );
     21
     22                $this->assertSame( 'Pages', $labels->name );
     23        }
     24
     25        public function test_existing_labels_are_not_overridden() {
     26                $labels = get_post_type_labels( (object) array(
     27                        'name'         => 'foo',
     28                        'labels'       => array(
     29                                'singular_name' => 'Foo',
     30                        ),
     31                        'hierarchical' => false,
     32                ) );
     33
     34                $this->assertSame( 'Foo', $labels->singular_name );
     35        }
     36
     37        public function test_name_admin_bar_label_should_fall_back_to_singular_name() {
     38                $labels = get_post_type_labels( (object) array(
     39                        'name'         => 'foo',
     40                        'labels'       => array(
     41                                'singular_name' => 'Foo',
     42                        ),
     43                        'hierarchical' => false,
     44                ) );
     45
     46                $this->assertSame( 'Foo', $labels->name_admin_bar );
     47        }
     48
     49
     50        public function test_name_admin_bar_label_should_fall_back_to_post_type_name() {
     51                $labels = get_post_type_labels( (object) array(
     52                        'name'         => 'bar',
     53                        'labels'       => array(),
     54                        'hierarchical' => false,
     55                ) );
     56
     57                $this->assertSame( 'bar', $labels->name_admin_bar );
     58        }
     59
     60        public function test_menu_name_should_fall_back_to_name() {
     61                $labels = get_post_type_labels( (object) array(
     62                        'name'         => 'foo',
     63                        'labels'       => array(
     64                                'name' => 'Bar',
     65                        ),
     66                        'hierarchical' => false,
     67                ) );
     68
     69                $this->assertSame( 'Bar', $labels->menu_name );
     70        }
     71
     72        public function test_labels_should_be_added_when_registering_a_post_type() {
     73                $post_type_object = register_post_type( 'foo', array(
     74                        'labels' => array(
     75                                'singular_name' => 'bar',
     76                        ),
     77                ) );
     78
     79                unregister_post_type( 'foo' );
     80
     81                $this->assertObjectHasAttribute( 'labels', $post_type_object );
     82                $this->assertObjectHasAttribute( 'label', $post_type_object );
     83                $this->assertObjectHasAttribute( 'not_found_in_trash', $post_type_object->labels );
     84        }
     85
     86        public function test_label_should_be_derived_from_labels_when_registering_a_post_type() {
     87                $post_type_object = register_post_type( 'foo', array(
     88                        'labels' => array(
     89                                'name' => 'bar',
     90                        ),
     91                ) );
     92
     93                $this->assertSame( 'bar', $post_type_object->label );
     94
     95                unregister_post_type( 'foo' );
     96        }
     97
     98        /**
     99         * @ticket 33543
     100         */
     101        public function test_should_fall_back_on_defaults_when_filtered_labels_do_not_contain_the_keys() {
     102                add_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
     103                register_post_type( 'foo' );
     104
     105                $this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels );
     106                $this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels );
     107
     108                unregister_post_type( 'foo' );
     109                remove_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
     110        }
     111
     112        public function filter_post_type_labels( $labels ) {
     113                unset( $labels->featured_image );
     114                unset( $labels->set_featured_image );
     115
     116                return $labels;
     117        }
     118}
  • tests/phpunit/tests/post/types.php

    diff --git tests/phpunit/tests/post/types.php tests/phpunit/tests/post/types.php
    index e7dcf84..31a51c2 100644
    class Tests_Post_Types extends WP_UnitTestCase { 
    220220        }
    221221
    222222        /**
    223          * @ticket 33543
    224          */
    225         function test_get_post_type_labels_should_fall_back_on_defaults_when_filtered_labels_do_not_contain_the_keys() {
    226                 add_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
    227                 register_post_type( 'foo' );
    228 
    229                 $this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels );
    230                 $this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels );
    231 
    232                 _unregister_post_type( 'foo' );
    233                 remove_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
    234         }
    235 
    236         public function filter_post_type_labels( $labels ) {
    237                 unset( $labels->featured_image );
    238                 unset( $labels->set_featured_image );
    239                 return $labels;
    240         }
    241 
    242 
    243         /**
    244223         * @ticket 30013
    245224         */
    246225        public function test_get_post_type_object_with_non_scalar_values() {