function ManageFieldsFunctionalTest::manageFieldsPage

Same name and namespace in other branches
  1. 9 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::manageFieldsPage()

Tests the manage fields page.

Parameters

string $type: (optional) The name of a content type.

1 call to ManageFieldsFunctionalTest::manageFieldsPage()
ManageFieldsFunctionalTest::testCRUDFields in core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
Runs the field CRUD tests.

File

core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php, line 165

Class

ManageFieldsFunctionalTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function manageFieldsPage($type = '') {
    $type = empty($type) ? $this->contentType : $type;
    $this->drupalGet('admin/structure/types/manage/' . $type . '/fields');
    // Check all table columns.
    $table_headers = [
        t('Label'),
        t('Machine name'),
        t('Field type'),
        t('Operations'),
    ];
    foreach ($table_headers as $table_header) {
        // We check that the label appear in the table headings.
        $this->assertRaw($table_header . '</th>', new FormattableMarkup('%table_header table header was found.', [
            '%table_header' => $table_header,
        ]));
    }
    // Test the "Add field" action link.
    $this->assertSession()
        ->linkExists('Add field');
    // Assert entity operations for all fields.
    $number_of_links = 3;
    $number_of_links_found = 0;
    $operation_links = $this->xpath('//ul[@class = "dropbutton"]/li/a');
    $url = base_path() . "admin/structure/types/manage/{$type}/fields/node.{$type}.body";
    foreach ($operation_links as $link) {
        switch ($link->getAttribute('title')) {
            case 'Edit field settings.':
                $this->assertIdentical($url, $link->getAttribute('href'));
                $number_of_links_found++;
                break;
            case 'Edit storage settings.':
                $this->assertIdentical("{$url}/storage", $link->getAttribute('href'));
                $number_of_links_found++;
                break;
            case 'Delete field.':
                $this->assertIdentical("{$url}/delete", $link->getAttribute('href'));
                $number_of_links_found++;
                break;
        }
    }
    $this->assertEqual($number_of_links, $number_of_links_found);
}

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