Commit fbdb75e1 authored by catch's avatar catch
Browse files

Issue #3064890 by danflanagan8, mpp, mottihoresh, scott_euser, peonboyos,...

Issue #3064890 by danflanagan8, mpp, mottihoresh, scott_euser, peonboyos, Kristen Pol, joshmiller: Notice: Undefined index: name in Drupal\field_ui\Element\FieldUiTable::reduceOrder() (line 228 of /var/www/html/docroot/core/modules/field_ui/src/Element/FieldUiTable.php)
parent 45e75ce3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ public static function preRenderRegionRows($elements) {
   */
  public static function reduceOrder($array, $a) {
    $array = !$array ? [] : $array;
    if ($a['name']) {
    if (!empty($a['name'])) {
      $array[] = $a['name'];
    }
    if (!empty($a['children'])) {
+90 −0
Original line number Diff line number Diff line
<?php

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) {
    $this->assertSame($expected, array_reduce($array, ['Drupal\field_ui\Element\FieldUiTable', 'reduceOrder']));
  }

  /**
   * Provides test data for testReduceOrder().
   */
  public 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'],
      ],
    ];
  }

}