Make WordPress Core

Ticket #12133: 12133-tests.diff

File 12133-tests.diff, 2.8 KB (added by welcher, 9 years ago)
  • tests/phpunit/tests/widgets.php

     
    157157
    158158        /**
    159159         * @see WP_Widget::get_field_name()
     160         * @dataProvider data_wp_widget_get_field_name
     161         *
    160162         */
    161         function test_wp_widget_get_field_name() {
     163        function test_wp_widget_get_field_name( $expected, $value_to_test ) {
    162164                $widget = new WP_Widget( 'foo', 'Foo' );
    163165                $widget->_set( 2 );
    164                 $this->assertEquals( 'widget-foo[2][title]', $widget->get_field_name( 'title' ) );
     166                $this->assertEquals( $expected, $widget->get_field_name( $value_to_test ) );
    165167        }
    166168
    167169        /**
     170         * Data provider.
     171         *
     172         * Passes the expected field name and the value to test.
     173         *
     174         * @since 4.4.0
     175         *
     176         * @return array {
     177         *     @type array {
     178         *         @type string $expected      The expected field id to be returned.
     179         *         @type string $value_to_test The value being passed to the get_field_name method.
     180         *     }
     181         * }
     182         */
     183        function data_wp_widget_get_field_name( ) {
     184
     185                return array(
     186                        array(
     187                                'widget-foo[2][title]',
     188                                'title',
     189                        ),
     190                        array(
     191                                'widget-foo[2][posttypes][]',
     192                                'posttypes[]',
     193                        ),
     194                        array(
     195                                'widget-foo[2][posttypes][4]',
     196                                'posttypes[4]',
     197                        ),
     198                        array(
     199                                'widget-foo[2][posttypes][4][]',
     200                                'posttypes[4][]',
     201                        ),
     202                        array(
     203                                'widget-foo[2][posttypes][4][][6]',
     204                                'posttypes[4][][6]',
     205                        ),
     206                );
     207        }
     208
     209        /**
    168210         * @see WP_Widget::get_field_id()
     211         * @dataProvider data_wp_widget_get_field_id
     212         *
    169213         */
    170         function test_wp_widget_get_field_id() {
     214        function test_wp_widget_get_field_id( $expected, $value_to_test ) {
    171215                $widget = new WP_Widget( 'foo', 'Foo' );
    172216                $widget->_set( 2 );
    173                 $this->assertEquals( 'widget-foo-2-title', $widget->get_field_id( 'title' ) );
     217                $this->assertEquals( $expected, $widget->get_field_id( $value_to_test ) );
    174218        }
    175219
     220
    176221        /**
     222         * Data provider.
     223         *
     224         * Passes the expected field id and the value to be used in the tests.
     225         *
     226         * @since 4.4.0
     227         *
     228         * @return array {
     229         *     @type array {
     230         *         @type string $expected      The expected field id to be returned.
     231         *         @type string $value_to_test The value being passed to the get_field_id method.
     232         *     }
     233         * }
     234         */
     235        function data_wp_widget_get_field_id() {
     236                return array(
     237                        array(
     238                                'widget-foo-2-title',
     239                                'title',
     240                        ),
     241                        array(
     242                                'widget-foo-2-posttypes',
     243                                'posttypes[]',
     244                        ),
     245                        array(
     246                                'widget-foo-2-posttypes-4',
     247                                'posttypes[4]',
     248                        ),
     249                        array(
     250                                'widget-foo-2-posttypes-4',
     251                                'posttypes[4][]',
     252                        ),
     253                        array(
     254                                'widget-foo-2-posttypes-4-6',
     255                                'posttypes[4][][6]',
     256                        ),
     257                );
     258        }
     259
     260        /**
    177261         * @see WP_Widget::_register()
    178262         */
    179263        function test_wp_widget__register() {