function FieldDateTest::assertRenderedDatesEqual

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php \Drupal\Tests\views\Kernel\Handler\FieldDateTest::assertRenderedDatesEqual()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php \Drupal\Tests\views\Kernel\Handler\FieldDateTest::assertRenderedDatesEqual()
  3. 10 core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php \Drupal\Tests\views\Kernel\Handler\FieldDateTest::assertRenderedDatesEqual()

Asserts properly formatted display against 'created' field in view.

@internal

Parameters

\Drupal\views\ViewExecutable $view: View to be tested.

array $map: Data map.

string|null $timezone: Optional timezone.

1 call to FieldDateTest::assertRenderedDatesEqual()
FieldDateTest::testFieldDate in core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php
Sets up functional test of the views date field.

File

core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php, line 158

Class

FieldDateTest
Tests the core Drupal\views\Plugin\views\field\Date handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function assertRenderedDatesEqual(ViewExecutable $view, array $map, ?string $timezone = NULL) : void {
    foreach ($map as $date_format => $expected_result) {
        $view->field['created']->options['date_format'] = $date_format;
        if (isset($timezone)) {
            $message = "{$date_format} format for timezone {$timezone} matches.";
            $view->field['created']->options['timezone'] = $timezone;
        }
        else {
            $message = "{$date_format} format matches.";
        }
        $actual_result = (string) $view->field['created']
            ->advancedRender($view->result[0]);
        $this->assertEquals($expected_result, strip_tags($actual_result), $message);
    }
}

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