parent
95a3187186
commit
45fda0fed1
|
@ -32,16 +32,23 @@ abstract class TalksTestBase extends EntityKernelTestBase {
|
|||
'custom_test',
|
||||
];
|
||||
|
||||
protected function createEvent(string $eventDateToFormat): ParagraphInterface {
|
||||
/** @var \Drupal\paragraphs\ParagraphInterface $event */
|
||||
$event = Paragraph::create([
|
||||
'field_date' => $eventDateToFormat,
|
||||
protected function createEvent(array $overrides = []): ParagraphInterface {
|
||||
$event = Paragraph::create(array_merge([
|
||||
'type' => 'event',
|
||||
]);
|
||||
], $overrides));
|
||||
|
||||
return tap($event)->save();
|
||||
}
|
||||
|
||||
protected function createTalk(array $overrides = []): EntityInterface {
|
||||
$talk = Node::create(array_merge([
|
||||
'title' => 'Test Driven Drupal',
|
||||
'type' => 'talk',
|
||||
], $overrides));
|
||||
|
||||
return tap($talk)->save();
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
@ -51,21 +58,4 @@ abstract class TalksTestBase extends EntityKernelTestBase {
|
|||
$this->installConfig(['custom_test']);
|
||||
}
|
||||
|
||||
protected function createTalk(?string $eventDateToFormat = NULL): EntityInterface {
|
||||
if ($eventDateToFormat) {
|
||||
$event = $this->createEvent($eventDateToFormat);
|
||||
}
|
||||
|
||||
$talk = Node::create([
|
||||
'title' => 'TDD - Test Driven Drupal',
|
||||
'type' => 'talk',
|
||||
]);
|
||||
|
||||
if (isset($event)) {
|
||||
$talk->set('field_events', [$event]);
|
||||
}
|
||||
|
||||
return tap($talk)->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,27 +11,31 @@ final class UpdatesTalkCreatedDateTest extends TalksTestBase {
|
|||
|
||||
public function testCreatingNode() {
|
||||
$eventDate = Carbon::today()->addWeek();
|
||||
$eventDateToFormat = $eventDate->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
|
||||
$eventDateToTimestamp = $eventDate->getTimestamp();
|
||||
$eventDateFormat = $eventDate->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
|
||||
$eventDateTimestamp = $eventDate->getTimestamp();
|
||||
|
||||
$talk = $this->createTalk($eventDateToFormat);
|
||||
$talk = $this->createTalk([
|
||||
'field_events' => [
|
||||
$this->createEvent(['field_date' => $eventDateFormat]),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEqual($eventDateToTimestamp, $talk->get('created')
|
||||
$this->assertEqual($eventDateTimestamp, $talk->get('created')
|
||||
->getString());
|
||||
}
|
||||
|
||||
public function testUpdatingNode() {
|
||||
$talk = $this->createTalk();
|
||||
|
||||
$eventDate = Carbon::today()->addWeek();
|
||||
$eventDateToFormat = $eventDate->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
|
||||
$eventDateToTimestamp = $eventDate->getTimestamp();
|
||||
$eventDateFormat = $eventDate->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
|
||||
$eventDateTimestamp = $eventDate->getTimestamp();
|
||||
|
||||
$event = $this->createEvent($eventDateToFormat);
|
||||
$talk->set('field_events', [$event]);
|
||||
$talk->save();
|
||||
$talk = $this->createTalk([
|
||||
'field_events' => [
|
||||
$this->createEvent(['field_date' => $eventDateFormat]),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEqual($eventDateToTimestamp, $talk->get('created')
|
||||
$this->assertEqual($eventDateTimestamp, $talk->get('created')
|
||||
->getString());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue