class FormatDateTest
Same name in this branch
- 9 core/modules/migrate/tests/src/Unit/process/FormatDateTest.php \Drupal\Tests\migrate\Unit\process\FormatDateTest
Same name and namespace in other branches
- 11.x core/modules/migrate/tests/src/Unit/process/FormatDateTest.php \Drupal\Tests\migrate\Unit\process\FormatDateTest
- 11.x core/modules/system/tests/src/Functional/Common/FormatDateTest.php \Drupal\Tests\system\Functional\Common\FormatDateTest
- 10 core/modules/migrate/tests/src/Unit/process/FormatDateTest.php \Drupal\Tests\migrate\Unit\process\FormatDateTest
- 10 core/modules/system/tests/src/Functional/Common/FormatDateTest.php \Drupal\Tests\system\Functional\Common\FormatDateTest
- 8.9.x core/modules/migrate/tests/src/Unit/process/FormatDateTest.php \Drupal\Tests\migrate\Unit\process\FormatDateTest
- 8.9.x core/modules/system/tests/src/Functional/Common/FormatDateTest.php \Drupal\Tests\system\Functional\Common\FormatDateTest
Tests the DateFormatterInterface::format() function.
@group Common
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Common\FormatDateTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of FormatDateTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Common/ FormatDateTest.php, line 12
Namespace
Drupal\Tests\system\Functional\CommonView source
class FormatDateTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests admin-defined formats in DateFormatterInterface::format().
*/
public function testAdminDefinedFormatDate() {
// Create and log in an admin user.
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
]));
// Add new date format.
$edit = [
'id' => 'example_style',
'label' => 'Example Style',
'date_format_pattern' => 'j M y',
];
$this->drupalGet('admin/config/regional/date-time/formats/add');
$this->submitForm($edit, 'Add format');
// Add a second date format with a different case than the first.
$edit = [
'id' => 'example_style_uppercase',
'label' => 'Example Style Uppercase',
'date_format_pattern' => 'j M Y',
];
$this->drupalGet('admin/config/regional/date-time/formats/add');
$this->submitForm($edit, 'Add format');
$this->assertSession()
->pageTextContains('Custom date format added.');
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = $this->container
->get('date.formatter');
$timestamp = strtotime('2007-03-10T00:00:00+00:00');
$this->assertSame($date_formatter->format($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07');
$this->assertSame($date_formatter->format($timestamp, 'example_style_uppercase', '', 'America/Los_Angeles'), '9 Mar 2007');
$this->assertSame($date_formatter->format($timestamp, 'undefined_style'), $date_formatter->format($timestamp, 'fallback'), 'Test DateFormatterInterface::format() defaulting to `fallback` when $type not found.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.