2020-05-29 02:30:29 +01:00
|
|
|
<?php
|
|
|
|
|
2020-12-17 23:23:00 +00:00
|
|
|
// phpcs:disable Drupal.Commenting.DocComment, Drupal.NamingConventions.ValidFunctionName
|
|
|
|
|
2020-08-24 09:26:44 +01:00
|
|
|
namespace Drupal\Tests\opdavies_talks\Kernel;
|
2020-05-29 02:30:29 +01:00
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Drupal\paragraphs\ParagraphInterface;
|
|
|
|
|
2020-12-17 23:28:55 +00:00
|
|
|
final class ReorderEventsTest extends TalksTestBase {
|
2020-05-29 02:30:29 +01:00
|
|
|
|
2020-12-17 23:23:00 +00:00
|
|
|
/** @test */
|
2020-12-17 23:28:55 +00:00
|
|
|
public function the_events_are_ordered_by_date_when_a_talk_is_created(): void {
|
2020-05-29 02:30:29 +01:00
|
|
|
$events = [
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::today()->addWeeks(2),
|
|
|
|
'field_name' => 'Drupal Bristol',
|
|
|
|
]),
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::yesterday(),
|
|
|
|
'field_name' => 'DrupalCamp London',
|
|
|
|
]),
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::tomorrow(),
|
|
|
|
'field_name' => 'PHP UK conference',
|
|
|
|
]),
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::today()->addMonths(3),
|
|
|
|
'field_name' => 'CMS Philly',
|
|
|
|
]),
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::today()->subYear(),
|
|
|
|
'field_name' => 'PHP South Wales',
|
|
|
|
]),
|
|
|
|
];
|
|
|
|
|
|
|
|
$talk = $this->createTalk([
|
|
|
|
'field_events' => $events,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
[
|
|
|
|
'PHP South Wales',
|
|
|
|
'DrupalCamp London',
|
|
|
|
'PHP UK conference',
|
|
|
|
'Drupal Bristol',
|
|
|
|
'CMS Philly',
|
|
|
|
],
|
|
|
|
$talk->getEvents()
|
|
|
|
->map(fn(ParagraphInterface $event) => $event->get('field_name')
|
|
|
|
->getString())
|
|
|
|
->toArray()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-17 23:23:00 +00:00
|
|
|
/** @test */
|
2020-12-17 23:28:55 +00:00
|
|
|
public function the_events_are_ordered_by_date_when_a_talk_is_updated(): void {
|
2020-05-29 02:30:29 +01:00
|
|
|
$events = [
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::today()->addWeeks(2),
|
|
|
|
'field_name' => 'Drupal Bristol',
|
|
|
|
]),
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::yesterday(),
|
|
|
|
'field_name' => 'DrupalCamp London',
|
|
|
|
]),
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::today()->addMonths(3),
|
|
|
|
'field_name' => 'CMS Philly',
|
|
|
|
]),
|
|
|
|
$this->createEvent([
|
|
|
|
'field_date' => Carbon::today()->subYear(),
|
|
|
|
'field_name' => 'PHP South Wales',
|
|
|
|
]),
|
|
|
|
];
|
|
|
|
|
|
|
|
$talk = $this->createTalk([
|
|
|
|
'field_events' => $events,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
[
|
|
|
|
'PHP South Wales',
|
|
|
|
'DrupalCamp London',
|
|
|
|
'Drupal Bristol',
|
|
|
|
'CMS Philly',
|
|
|
|
],
|
|
|
|
$talk->getEvents()
|
|
|
|
->map(fn(ParagraphInterface $event) => $event->get('field_name')
|
|
|
|
->getString())
|
|
|
|
->toArray()
|
|
|
|
);
|
|
|
|
|
|
|
|
$talk->addEvent($this->createEvent([
|
|
|
|
'field_date' => Carbon::tomorrow(),
|
|
|
|
'field_name' => 'PHP UK conference',
|
|
|
|
]));
|
|
|
|
$talk->save();
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
[
|
|
|
|
'PHP South Wales',
|
|
|
|
'DrupalCamp London',
|
|
|
|
'PHP UK conference',
|
|
|
|
'Drupal Bristol',
|
|
|
|
'CMS Philly',
|
|
|
|
],
|
|
|
|
$talk->getEvents()
|
|
|
|
->map(fn(ParagraphInterface $event) => $event->get('field_name')
|
|
|
|
->getString())
|
|
|
|
->toArray()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|