function TaxonomyTermUpdatePathTest::testStatusCheckbox

Tests that the taxonomy_term entity form has the status checkbox.

See also

taxonomy_post_update_configure_status_field_widget()

File

core/modules/taxonomy/tests/src/Functional/Update/TaxonomyTermUpdatePathTest.php, line 301

Class

TaxonomyTermUpdatePathTest
Tests the upgrade path for taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional\Update

Code

public function testStatusCheckbox() {
    $ids = \Drupal::entityQuery('entity_form_display')->condition('targetEntityType', 'taxonomy_term')
        ->execute();
    // Make sure we have the expected values before the update.
    $config_keys = [];
    foreach ($ids as $id) {
        $config_keys[] = 'core.entity_form_display.' . $id;
    }
    
    /* @var \Drupal\Core\Config\ImmutableConfig[] $form_display_configs */
    $form_display_configs = $this->container
        ->get('config.factory')
        ->loadMultiple($config_keys);
    foreach ($form_display_configs as $config) {
        $status_config = $config->get('content.status');
        if ($config->getName() == 'core.entity_form_display.taxonomy_term.tags.default') {
            $this->assertNotNull($status_config);
            $this->assertEquals([
                'display_label' => FALSE,
            ], $status_config['settings']);
        }
        else {
            $this->assertNull($status_config);
        }
    }
    // Run updates.
    $this->runUpdates();
    
    /* @var \Drupal\Core\Entity\Display\EntityDisplayInterface[] $form_displays */
    $form_displays = EntityFormDisplay::loadMultiple($ids);
    foreach ($form_displays as $form_display) {
        $component = $form_display->getComponent('status');
        if ($form_display->id() == 'taxonomy_term.tags.default') {
            // Display label should not have been set to TRUE by the upgrade path.
            $this->assertEquals([
                'display_label' => FALSE,
            ], $component['settings']);
        }
        else {
            $this->assertEquals('boolean_checkbox', $component['type']);
            $this->assertEquals([
                'display_label' => TRUE,
            ], $component['settings']);
        }
    }
}

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