FieldUiTableTest.php

Same filename in other branches
  1. 9 core/modules/field_ui/tests/src/Unit/FieldUiTableTest.php
  2. 10 core/modules/field_ui/tests/src/Unit/FieldUiTableTest.php

Namespace

Drupal\Tests\field_ui\Unit

File

core/modules/field_ui/tests/src/Unit/FieldUiTableTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\field_ui\Unit;

use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\field_ui\Element\FieldUiTable
 *
 * @group field_ui
 */
class FieldUiTableTest extends UnitTestCase {
    
    /**
     * @covers ::reduceOrder
     *
     * @dataProvider providerTestReduceOrder
     */
    public function testReduceOrder($array, $expected) : void {
        $this->assertSame($expected, array_reduce($array, [
            'Drupal\\field_ui\\Element\\FieldUiTable',
            'reduceOrder',
        ]));
    }
    
    /**
     * Provides test data for testReduceOrder().
     */
    public static function providerTestReduceOrder() {
        return [
            'Flat' => [
                'array' => [
                    [
                        'name' => 'foo',
                    ],
                    [
                        'name' => 'bar',
                    ],
                    [
                        'name' => 'baz',
                    ],
                ],
                'expected' => [
                    'foo',
                    'bar',
                    'baz',
                ],
            ],
            'Nested' => [
                'array' => [
                    [
                        'name' => 'foo',
                        'children' => [
                            [
                                'name' => 'bar',
                                'weight' => 0,
                            ],
                            [
                                'name' => 'baz',
                                'weight' => -1,
                            ],
                        ],
                    ],
                    [
                        'name' => 'biz',
                    ],
                ],
                'expected' => [
                    'foo',
                    'baz',
                    'bar',
                    'biz',
                ],
            ],
            'Nested no name key' => [
                'array' => [
                    [
                        'children' => [
                            [
                                'name' => 'foo',
                                'weight' => -1,
                            ],
                            [
                                'name' => 'bar',
                                'weight' => 1,
                            ],
                            [
                                'name' => 'baz',
                                'weight' => 0,
                            ],
                        ],
                    ],
                    [
                        'name' => 'biz',
                    ],
                ],
                'expected' => [
                    'foo',
                    'baz',
                    'bar',
                    'biz',
                ],
            ],
        ];
    }

}

Classes

Title Deprecated Summary
FieldUiTableTest @coversDefaultClass \Drupal\field_ui\Element\FieldUiTable

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.