diff --git a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php index da9ebaa..c717820 100644 --- a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php @@ -5,9 +5,10 @@ * Contains \Drupal\Tests\Core\Datetime\DateTest. */ -namespace Drupal\Tests\Core\Datetime; +namespace Drupal\Tests\Core\Datetime { use Drupal\Core\Datetime\DateFormatter; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; /** @@ -45,6 +46,7 @@ class DateTest extends UnitTestCase { protected $dateFormatter; protected function setUp() { + parent::setUp(); $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface'); $this->stringTranslation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface'); @@ -128,4 +130,37 @@ public function testFormatIntervalZeroSecond() { $this->assertEquals('0 sec', $result); } + /** + * Tests the getSampleDateFormats method. + * + * @see \Drupal\Core\Datetime\DateFormatter::getSampleDateFormats() + */ + public function testGetSampleDateFormats() { + include_once $this->root . '/core/includes/common.inc'; + $ts = strtotime('2015-03-22 14:23:00'); + $this->dateFormatter->setCountryCode('GB'); + $expected = $this->dateFormatter->getSampleDateFormats('en', $ts, 'Europe/London'); + + // Removed characters related to timezone 'e' and 'T', as test does not have + // timezone set. + $date_characters = 'dDjlNSwzWFmMntLoYyaABgGhHisuIOPZcrU'; + $date_chars = str_split($date_characters); + + foreach ($date_chars as $val) { + $this->assertEquals($expected[$val], date($val, $ts)); + } + } + +} + +} + +namespace { + use Drupal\Component\Utility\String; + + if (!function_exists('t')) { + function t($string, array $args = []) { + return String::format($string, $args); + } + } }