View source
<?php
namespace Drupal\system\Tests\System;
use Drupal\Component\Utility\Unicode;
use Drupal\simpletest\WebTestBase;
class DateFormatsMachineNameTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$admin = $this
->drupalCreateUser(array(
'administer site configuration',
));
$this
->drupalLogin($admin);
}
public function testDateFormatsMachineNameAllowedValues() {
$edit = array(
'label' => 'Something Not Allowed',
'id' => 'something.bad',
'date_format_pattern' => 'Y-m-d',
);
$this
->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
$this
->assertText(t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'), 'It is not possible to create a date format with the machine name that has any character other than lowercase letters, digits or underscore.');
$edit = array(
'label' => 'Custom',
'id' => 'custom',
'date_format_pattern' => 'Y-m-d',
);
$this
->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
$this
->assertText(t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'), 'It is not possible to create a date format with the machine name "custom".');
$edit = array(
'label' => 'Fallback',
'id' => 'fallback',
'date_format_pattern' => 'j/m/Y',
);
$this
->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
$this
->assertText(t('The machine-readable name is already in use. It must be unique.'), 'It is not possible to create a date format with the machine name "fallback". It is a built-in format that already exists.');
$id = Unicode::strtolower($this
->randomMachineName(16));
$edit = array(
'label' => $this
->randomMachineName(16),
'id' => $id,
'date_format_pattern' => 'd/m/Y',
);
$this
->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
$this
->assertText(t('Custom date format added.'), 'It is possible to create a date format with a new machine name.');
$edit = array(
'label' => $this
->randomMachineName(16),
'id' => $id,
'date_format_pattern' => 'd-m-Y',
);
$this
->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
$this
->assertText(t('The machine-readable name is already in use. It must be unique.'), 'It is not possible to create a new date format with an existing machine name.');
}
}