public function DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceSameDay in Recurring Dates Field 8.2
Same name and namespace in other branches
- 3.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceSameDay()
- 3.0.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceSameDay()
- 3.1.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceSameDay()
Tests setting summary occurrence sample for same day.
File
- tests/
src/ Kernel/ DateRecurBasicFormatterTest.php, line 275
Class
- DateRecurBasicFormatterTest
- Tests date recur formatter.
Namespace
Drupal\Tests\date_recur\KernelCode
public function testFormatterSettingsSummarySampleOccurrenceSameDay() {
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $efm */
$efm = $this->container
->get('entity_field.manager');
$definitions = $efm
->getBaseFieldDefinitions('dr_entity_test');
$dateFormatId = $this->dateFormat
->id();
$options = [
'configuration' => [
'label' => 'above',
'type' => 'date_recur_basic_formatter',
'settings' => [
'format_type' => $dateFormatId,
'occurrence_format_type' => $dateFormatId,
'same_end_date_format_type' => $dateFormatId,
'interpreter' => $this->interpreter
->id(),
'count_per_item' => FALSE,
'separator' => '-',
'show_next' => 10,
],
],
'field_definition' => $definitions['dr'],
'prepare' => TRUE,
'view_mode' => 'full',
];
/** @var \Drupal\Core\Field\FormatterPluginManager $fieldFormatterManager */
$fieldFormatterManager = $this->container
->get('plugin.manager.field.formatter');
$instance = $fieldFormatterManager
->getInstance($options);
$summary = $instance
->settingsSummary();
$start = new \DateTime('today 9am');
$endSameDay = clone $start;
$endSameDay
->setTime(17, 0, 0);
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container
->get('renderer');
$rendered = $renderer
->renderRoot($summary['sample_same_day']);
// Remove newlines from Twig templates.
$rendered = preg_replace('/\\n/', '', $rendered);
$this
->setRawContent($rendered);
$this
->removeWhiteSpace();
$pattern = $this->dateFormat
->getPattern();
$this
->assertEquals(sprintf('Same day range: %s-%s', $start
->format($pattern), $endSameDay
->format($pattern)), $this
->getTextContent());
}