function ManageFieldsFunctionalTest::manageFieldsPage

Same name in other branches
  1. 8.9.x 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 = [
        'Label',
        'Machine name',
        'Field type',
        'Operations',
    ];
    foreach ($table_headers as $table_header) {
        // We check that the label appear in the table headings.
        $this->assertSession()
            ->responseContains($table_header . '</th>');
    }
    // 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->assertSame($url, $link->getAttribute('href'));
                $number_of_links_found++;
                break;
            case 'Edit storage settings.':
                $this->assertSame("{$url}/storage", $link->getAttribute('href'));
                $number_of_links_found++;
                break;
            case 'Delete field.':
                $this->assertSame("{$url}/delete", $link->getAttribute('href'));
                $number_of_links_found++;
                break;
        }
    }
    $this->assertEquals($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.