function ContentTranslationHandlerTest::providerTestEntityFormSharedElements

Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest::providerTestEntityFormSharedElements()
  2. 8.9.x core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest::providerTestEntityFormSharedElements()
  3. 10 core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest::providerTestEntityFormSharedElements()

Returns test cases for ::testEntityFormSharedElements().

Return value

array[] An array of test cases, each one containing the element to alter, the form state, and the expected altered element.

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php, line 139

Class

ContentTranslationHandlerTest
Tests the content translation handler.

Namespace

Drupal\Tests\content_translation\Kernel

Code

public static function providerTestEntityFormSharedElements() {
    $tests = [];
    $element = [];
    $tests['empty'] = [
        'element' => $element,
        'default_translation_affected' => TRUE,
        'default_translation' => TRUE,
        'translation_form' => FALSE,
        'expected' => $element,
    ];
    $element = [
        '#type' => 'textfield',
    ];
    $tests['no-children'] = $tests['empty'];
    $tests['no-children']['element'] = $element;
    $tests['no-children']['expected'] = $element;
    $element = [
        'test' => [
            '#type' => 'textfield',
            '#multilingual' => TRUE,
        ],
    ];
    $tests['multilingual'] = $tests['empty'];
    $tests['multilingual']['element'] = $element;
    $tests['multilingual']['expected'] = $element;
    unset($element['test']['#multilingual']);
    $tests['no-title'] = $tests['empty'];
    $tests['no-title']['element'] = $element;
    $tests['no-title']['expected'] = $element;
    $element['test']['#title'] = 'Test';
    $tests['no-translatability-clue'] = $tests['empty'];
    $tests['no-translatability-clue']['element'] = $element;
    $tests['no-translatability-clue']['expected'] = $element;
    $expected = $element;
    $expected['test']['#title'] .= ' <span class="translation-entity-all-languages">(all languages)</span>';
    $tests['translatability-clue'] = $tests['no-translatability-clue'];
    $tests['translatability-clue']['default_translation_affected'] = FALSE;
    $tests['translatability-clue']['expected'] = $expected;
    $ignored_types = [
        'actions',
        'details',
        'hidden',
        'link',
        'token',
        'value',
        'vertical_tabs',
    ];
    foreach ($ignored_types as $ignored_type) {
        $element = [
            'test' => [
                '#type' => $ignored_type,
                '#title' => 'Test',
            ],
        ];
        $tests["ignore-{$ignored_type}"] = $tests['translatability-clue'];
        $tests["ignore-{$ignored_type}"]['element'] = $element;
        $tests["ignore-{$ignored_type}"]['expected'] = $element;
    }
    $tests['unknown-field'] = $tests['no-translatability-clue'];
    $tests['unknown-field']['default_translation'] = FALSE;
    $element = [
        'name' => [
            '#type' => 'textfield',
        ],
        'hidden_fields_warning_message' => [
            '#theme' => 'status_messages',
            '#message_list' => [
                'warning' => [
                    t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.'),
                ],
            ],
            '#weight' => -100,
            '#status_headings' => [
                'warning' => t('Warning message'),
            ],
        ],
    ];
    $expected = $element;
    $expected['name']['#access'] = FALSE;
    $tests['hide-untranslatable'] = $tests['unknown-field'];
    $tests['hide-untranslatable']['element'] = $element;
    $tests['hide-untranslatable']['expected'] = $expected;
    $tests['no-translation-form'] = $tests['no-translatability-clue'];
    $tests['no-translation-form']['translation_form'] = FALSE;
    return $tests;
}

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