diff --git a/data/events.yml b/data/events.yml index 55fdc2ed..f63263d9 100644 --- a/data/events.yml +++ b/data/events.yml @@ -59,7 +59,6 @@ events: nomad_php: name: Nomad PHP - location: Online url: https://nomadphp.com nwdug: diff --git a/source/_partials/talk/events.html.twig b/source/_partials/talk/events.html.twig index 741b804b..3a1b611a 100644 --- a/source/_partials/talk/events.html.twig +++ b/source/_partials/talk/events.html.twig @@ -1,11 +1,21 @@ -{% set talks = getAllTalks([page], site.events) %} -{% if talks is not empty %} +{% if page.events %}
-

Events

+

Presented at

- {% include "talks/table" with { - talks: talks|reverse, - talk_page: true - } %} +
{% endif %} diff --git a/source/_partials/talks/talk.html.twig b/source/_partials/talks/talk.html.twig new file mode 100644 index 00000000..f5e59845 --- /dev/null +++ b/source/_partials/talks/talk.html.twig @@ -0,0 +1,17 @@ +
+

{{ talk.title }}

+ +
+

{{ talk.description }}

+
+ + {% if talk.url %} + + {% endif %} +
diff --git a/source/_talks/building-static-websites-sculpin.md b/source/_talks/building-static-websites-sculpin.md index 99bc91b8..e4e7618f 100644 --- a/source/_talks/building-static-websites-sculpin.md +++ b/source/_talks/building-static-websites-sculpin.md @@ -1,5 +1,6 @@ --- title: Building Static Websites with Sculpin +description: A lightning talk on how to use Sculpin to generate static HTML websites. type: Lightning talk speakerdeck: id: 6c9c4be1a1344f1291ff13a391674a66 diff --git a/source/_talks/configuring-all-the-things-drupal-8.md b/source/_talks/configuring-all-the-things-drupal-8.md index 61d0bdca..8d52f3a3 100644 --- a/source/_talks/configuring-all-the-things-drupal-8.md +++ b/source/_talks/configuring-all-the-things-drupal-8.md @@ -1,5 +1,6 @@ --- title: "Configuring all the Things (in Drupal 8)" +description: A short notice talk on configuration management in Drupal 8, and things I’ve learned working on my current Drupal 8 project. speakerdeck: id: 6de3fe8947a34727b79eb9d9dcc66bf2 ratio: "1.37081659973226" diff --git a/source/_talks/dancing-for-drupal.md b/source/_talks/dancing-for-drupal.md index c4339f2e..3c7324e4 100644 --- a/source/_talks/dancing-for-drupal.md +++ b/source/_talks/dancing-for-drupal.md @@ -1,5 +1,6 @@ --- title: Dancing for Drupal +description: A talk on Drupal, presented alongside others representing Umbraco, Sitecore and Episerver. speakerdeck: id: ffa9b6dea6dc4a8eb207b9982ed6e1bd ratio: '1.33333333333333' diff --git a/source/_talks/deploying-drupal-fabric.md b/source/_talks/deploying-drupal-fabric.md index 1882c0ba..97050688 100644 --- a/source/_talks/deploying-drupal-fabric.md +++ b/source/_talks/deploying-drupal-fabric.md @@ -1,6 +1,6 @@ --- title: 'Deploying Drupal with Fabric' -type: Talk +description: How to use Fabric, a Python command line based library, to deploy your Drupal applications. speakerdeck: id: 40d1eca4bd484afc86295924fff5dd41 ratio: '1.77777777777778' diff --git a/source/_talks/deploying-php-ansible-ansistrano.md b/source/_talks/deploying-php-ansible-ansistrano.md index f87fb104..6c4cb2b8 100644 --- a/source/_talks/deploying-php-ansible-ansistrano.md +++ b/source/_talks/deploying-php-ansible-ansistrano.md @@ -1,5 +1,6 @@ --- title: Deploying PHP applications with Ansible, Ansible Vault and Ansistrano +description: How to use Ansible and Ansistrano to perform robust, secure deployments of your PHP applications. speakerdeck: id: c11fe635ed8f4741b35bf3ebe53e8323 ratio: "1.77777777777778" diff --git a/source/_talks/deploying-php-fabric.md b/source/_talks/deploying-php-fabric.md index 9839ff0b..424451c0 100644 --- a/source/_talks/deploying-php-fabric.md +++ b/source/_talks/deploying-php-fabric.md @@ -1,5 +1,6 @@ --- title: Deploying PHP Applications with Fabric +description: How to use Fabric, a Python command line based library, to deploy your PHP applications. speakerdeck: id: c147618ce07546ca92f92983c52d6a41 ratio: '1.77777777777778' diff --git a/source/_talks/drupal-8-module-development.md b/source/_talks/drupal-8-module-development.md index fbb2e730..bbd1db80 100644 --- a/source/_talks/drupal-8-module-development.md +++ b/source/_talks/drupal-8-module-development.md @@ -1,5 +1,6 @@ --- title: Getting Started with Drupal 8 Module Development +description: How to build your first module for Drupal 8. tags: [conference, php, drupal, drupalcamp, drupal-8] tweets: yes code: https://github.com/opdavies/dclondon16-d8-module diff --git a/source/_talks/drupal-8-php-libraries-drupalorg-api.md b/source/_talks/drupal-8-php-libraries-drupalorg-api.md index 66868c76..fb17b539 100644 --- a/source/_talks/drupal-8-php-libraries-drupalorg-api.md +++ b/source/_talks/drupal-8-php-libraries-drupalorg-api.md @@ -1,5 +1,6 @@ --- title: Having Fun with Drupal 8, PHP libraries and the Drupal.org API +description: A crash course in developing PHP packages and Drupal 8 modules, based on the Drupal.org API. speakerdeck: id: 6e42ae9620bb4e91b3955f8c30d66934 ratio: '1.77777777777778' diff --git a/source/_talks/drupal-8-rejoining-the-herd.md b/source/_talks/drupal-8-rejoining-the-herd.md index 73993a1d..89f2ea96 100644 --- a/source/_talks/drupal-8-rejoining-the-herd.md +++ b/source/_talks/drupal-8-rejoining-the-herd.md @@ -1,5 +1,6 @@ --- title: Drupal 8: Rejoining the Herd +description: A talk highlighting some of the recent technical and non-technical changes in Drupal 8. tags: [conference, php, drupal, drupal-8] speakerdeck: id: 440fd6592f474741bc606c96bc32c104 diff --git a/source/_talks/drupal-8.md b/source/_talks/drupal-8.md index 1a587a61..c3560c8b 100644 --- a/source/_talks/drupal-8.md +++ b/source/_talks/drupal-8.md @@ -1,5 +1,6 @@ --- title: Drupal 8 +description: A lightning talk presented to the PHPSW user group, highlighting some of the relevant changes in Drupal 8. speakerdeck: url: https://speakerdeck.com/opdavies/drupal-8 id: 46ba4ba577d94a32b7abdade610ceb69 diff --git a/source/_talks/drupal-vm-generator.md b/source/_talks/drupal-vm-generator.md index 493bbf85..ff6abc3a 100644 --- a/source/_talks/drupal-vm-generator.md +++ b/source/_talks/drupal-vm-generator.md @@ -1,5 +1,6 @@ --- title: Drupal VM Generator +description: Announcing the Drupal VM Generator CLI tool. type: Lightning talk code: https://github.com/opdavies/drupal-vm-generator tags: [drupal-vm, drupal-vm-generator, meetup, symfony] diff --git a/source/_talks/drupal-vm-meet-symfony-console.md b/source/_talks/drupal-vm-meet-symfony-console.md index c0867387..26db7ea0 100644 --- a/source/_talks/drupal-vm-meet-symfony-console.md +++ b/source/_talks/drupal-vm-meet-symfony-console.md @@ -1,5 +1,6 @@ --- title: Drupal VM, Meet Symfony Console +description: How to develop command line applications using Symfony Console, using the Drupal VM CLI as an example. tags: [conference, php, drupal-vm, symfony] speakerdeck: id: 56c79770f73f4e47a542a30243437c49 diff --git a/source/_talks/drupalorg-2015.md b/source/_talks/drupalorg-2015.md index 0e34007e..d5967272 100644 --- a/source/_talks/drupalorg-2015.md +++ b/source/_talks/drupalorg-2015.md @@ -1,5 +1,6 @@ --- title: Drupal.org in 2015: What's Coming Next +description: A retrospective of the Drupal Association’s work in 2014 and a look forward to what we’ll be working on in 2015. tags: [conference, drupalcamp, drupalcamp-london, drupal-association] speakerdeck: id: 0cf8d7b647c94ae289e9db2b46a9e8f2 diff --git a/source/_talks/drush-make-drupalbristol.md b/source/_talks/drush-make-drupalbristol.md index 63e6a8b3..df46b020 100644 --- a/source/_talks/drush-make-drupalbristol.md +++ b/source/_talks/drush-make-drupalbristol.md @@ -1,5 +1,6 @@ --- title: drush make drupalbristol +description: How to Drush Make to build your Drupal websites. speakerdeck: id: 42605700f102013198de5a5f6f23ab67 ratio: '1.29456384323641' diff --git a/source/_talks/getting-your-data-into-drupal-8.md b/source/_talks/getting-your-data-into-drupal-8.md index dd89dd13..73960230 100644 --- a/source/_talks/getting-your-data-into-drupal-8.md +++ b/source/_talks/getting-your-data-into-drupal-8.md @@ -1,5 +1,6 @@ --- title: Getting (Your Data) Into Drupal 8 +description: An overview of Drupal’s Migrate functionality, and a look at how to write your own migrations. speakerdeck: id: 63e5dfce996e46699e304d50e896477b ratio: '1.77777777777778' diff --git a/source/_talks/git-flow.md b/source/_talks/git-flow.md index 775480a0..66f4cc01 100644 --- a/source/_talks/git-flow.md +++ b/source/_talks/git-flow.md @@ -1,5 +1,6 @@ --- title: Never Commit to Master - An Introduction to Git Flow +description: An introduction to and demonstation of the Git Flow braching model. speakerdeck: id: 201559e0f103013198dd5a5f6f23ab67 ratio: '1.29456384323641' diff --git a/source/_talks/goodbye-drush-make-hello-composer.md b/source/_talks/goodbye-drush-make-hello-composer.md index a8f08bef..9b8d5564 100644 --- a/source/_talks/goodbye-drush-make-hello-composer.md +++ b/source/_talks/goodbye-drush-make-hello-composer.md @@ -1,5 +1,6 @@ --- title: Goodbye Drush Make. Hello Composer! +description: How to use Composer to manage your Drupal applications. tags: ['meetup', 'drupal', 'composer'] speakerdeck: id: 1c1e0e129ab34816bd4c4edb5f6642c2 diff --git a/source/_talks/it-all-started-with-a-patch.md b/source/_talks/it-all-started-with-a-patch.md index 6f095a84..c7edd813 100644 --- a/source/_talks/it-all-started-with-a-patch.md +++ b/source/_talks/it-all-started-with-a-patch.md @@ -1,5 +1,6 @@ --- title: It All Started With A Patch +description: A lightning talk on how and why to get involved with open source. type: Lightning talk tags: [meetup, phpsw, open-source] speakerdeck: diff --git a/source/_talks/modern-drupal-development-with-composer.md b/source/_talks/modern-drupal-development-with-composer.md index 2550dccd..b01f19bf 100644 --- a/source/_talks/modern-drupal-development-with-composer.md +++ b/source/_talks/modern-drupal-development-with-composer.md @@ -1,5 +1,6 @@ --- title: Modern Drupal Development with Composer +description: A lightning talk on how to use Composer to manage your Drupal projects. type: Lightning talk tags: ['meetups', 'phpsw', 'drupal', 'composer'] speakerdeck: diff --git a/source/_talks/so-what-is-this-drupal-thing.md b/source/_talks/so-what-is-this-drupal-thing.md index 27089d3e..a36c8211 100644 --- a/source/_talks/so-what-is-this-drupal-thing.md +++ b/source/_talks/so-what-is-this-drupal-thing.md @@ -1,5 +1,6 @@ --- title: So, what is this Drupal thing? +description: My first talk, where I talk about Drupal, what it is and what it can do. vimeo: id: 49827006 tags: [meetup, drupal, unified-diff] diff --git a/source/_talks/taking-flight-with-tailwind-css.md b/source/_talks/taking-flight-with-tailwind-css.md index 1419e51e..e9f9952c 100644 --- a/source/_talks/taking-flight-with-tailwind-css.md +++ b/source/_talks/taking-flight-with-tailwind-css.md @@ -1,5 +1,6 @@ --- title: Taking Flight with Tailwind CSS +description: An introduction to the utility-first approach to writing CSS with a focus on the Tailwind CSS framework. type: Lightning talk speakerdeck: id: 10ca51f23560443d83b898a92929b4b3 diff --git a/source/_talks/tdd-test-driven-drupal.md b/source/_talks/tdd-test-driven-drupal.md index ddf4d67b..52517cff 100644 --- a/source/_talks/tdd-test-driven-drupal.md +++ b/source/_talks/tdd-test-driven-drupal.md @@ -1,5 +1,6 @@ --- title: TDD - Test Driven Drupal +description: How to write automated tests for Drupal, and how to create a new Drupal module using test driven development. speakerdeck: id: 088cb18033064f5cb18d1079795294a1 ratio: '1.77777777777778' diff --git a/source/_talks/test-drive-twig-with-sculpin.md b/source/_talks/test-drive-twig-with-sculpin.md index 6758c885..abc3aa7a 100644 --- a/source/_talks/test-drive-twig-with-sculpin.md +++ b/source/_talks/test-drive-twig-with-sculpin.md @@ -1,5 +1,6 @@ --- title: Test Drive Twig with Sculpin +description: With Drupal 8 just around the corner, see how you can develop your Twig skills with Sculpin - a static site generator based on Symfony components and Twig. speakerdeck: id: 54589d2e50a3476a9a75aed809e9edf1 ratio: '1.77777777777778' diff --git a/source/_talks/things-you-should-know-about-php.md b/source/_talks/things-you-should-know-about-php.md index e7317342..741a1699 100644 --- a/source/_talks/things-you-should-know-about-php.md +++ b/source/_talks/things-you-should-know-about-php.md @@ -1,5 +1,6 @@ --- title: Things you should know about PHP +description: An introduction to PHP, presented to the Swansea Software Development Community (SSDC) meetup. speakerdeck: id: fe360f1030f34bdb9eb14cdab907bb3c ratio: '1.37081659973226' @@ -14,4 +15,4 @@ events: - event: ssdc date: 2019-01-28 --- -An introduction to PHP, presented to the Swansea Software Development Community (SSDC). +An introduction to PHP, presented to the Swansea Software Development Community (SSDC) meetup. diff --git a/source/_talks/using-laravel-collections-outside-laravel.md b/source/_talks/using-laravel-collections-outside-laravel.md index 516137f5..3e0b7484 100644 --- a/source/_talks/using-laravel-collections-outside-laravel.md +++ b/source/_talks/using-laravel-collections-outside-laravel.md @@ -1,5 +1,6 @@ --- title: Using Laravel Collections... Outside Laravel +description: How to include and use Laravel’s Illuminate Collections in your non-Laravel PHP projects. speakerdeck: id: 76f1718a75a74940b0b028aac8b9f78b ratio: '1.77777777777778' diff --git a/source/talks.html.twig b/source/talks.html.twig index a134d6c4..4f6d42ab 100644 --- a/source/talks.html.twig +++ b/source/talks.html.twig @@ -6,21 +6,26 @@ meta: use: [talks] talks: - title: 'Drupal and the LDAP module' + description: A review and demonstration of some of the recent single sign-on work that I did using Drupal’s LDAP module. events: - event: swdug date: 2013-07-10 + - title: 'About the Drupal Association' + description: An impromptu talk about what the Drupal Association is, and what work I’ve been doing since I joined the Association staff. events: - event: swdug date: 2014-08-19 - title: 'Automated testing with Drupal 8 and PHPUnit' + description: A workshop that I gave to teach others about automated testing in Drupal 8. type: Workshop events: - event: drupal_bristol date: 2018-06-27 - title: 'Episode #175 - Automated Testing' + description: I joined the Talking Drupal team to discuss automated testing. type: Podcast url: http://talkingdrupal.com/175 events: @@ -28,29 +33,27 @@ talks: date: 2018-09-05 --- {% block content %} -
-

I regularly speak at conferences and user groups about a range of subjects including PHP, Drupal, automated testing, Git and systems administration.

-
+
+
+

Upcoming Talks

-
-

Upcoming Talks

+
+ {% for talk in getUpcomingTalks(page.talks|merge(data.talks)) %} + {% include 'talks/talk' %} + {% else %} +

sdf

+ {% endfor %} +
+
- {% set upcoming_talks = getUpcomingTalks(data.talks|merge(page.talks), site.events) %} - {% if not upcoming_talks.empty %} - {% include "talks/table" with { - talks: upcoming_talks, - upcoming: true, - } %} - {% else %} -

Nothing scheduled at the moment.

- {% endif %} -
+
+

Previous Talks

-
-

Previous Talks

- - {% include "talks/table" with { - talks: getPastTalks(data.talks|merge(page.talks), site.events) - } %} +
+ {% for talk in getPastTalks(page.talks|merge(data.talks))|reverse %} + {% include 'talks/talk' %} + {% endfor %} +
+
{% endblock %} diff --git a/src/TalksBundle/TwigExtension/TalksExtension.php b/src/TalksBundle/TwigExtension/TalksExtension.php index 1d1e290f..cd848d0a 100644 --- a/src/TalksBundle/TwigExtension/TalksExtension.php +++ b/src/TalksBundle/TwigExtension/TalksExtension.php @@ -34,77 +34,46 @@ class TalksExtension extends Twig_Extension ]; } - /** - * Get all upcoming and previous talks. - * - * @param ProxySourceCollection|array $talks All talk nodes. - * @param array $eventData Shared event data. - * - * @return Collection A sorted collection of talks. - */ - public function getAll($talks, array $eventData = []) + /** + * Get all upcoming and previous talks. + * + * @param ProxySourceCollection|array $talks All talk nodes. + * + * @return Collection A sorted collection of talks. + */ + public function getAll($talks): Collection { - return $this->format($talks, $eventData)->sortBy('event.date'); + return collect($talks)->sortBy(function ($talk) { + return $this->getLastDate($talk); + }); } /** * Get all upcoming talks. * * @param ProxySourceCollection|array $talks All talk nodes. - * @param array $eventData Shared event data. * * @return Collection A sorted collection of talks. */ - public function getUpcoming($talks, array $eventData = []) + public function getUpcoming($talks): Collection { - return $this->format($talks, $eventData) - ->filter(function ($talk) { - return $talk['event']['date'] >= $this->today; - }) - ->sortBy('event.date'); + return $this->getAll($talks)->filter(function ($talk) { + return $this->getLastDate($talk) >= $this->today; + })->values(); } /** * Get all past talks. * * @param ProxySourceCollection|array $talks All talk nodes. - * @param array $eventData Shared event data. * * @return Collection A sorted collection of talks. */ - public function getPast($talks, array $eventData = []) + public function getPast($talks): Collection { - return $this->format($talks, $eventData) - ->filter(function ($talk) { - return $talk['event']['date'] < $this->today; - }) - ->sortByDesc('event.date'); - } - - /** - * Format the talk data into the required format. - * - * @param ProxySourceCollection|array $talks All talk nodes. - * @param array $eventData Shared event data. - * - * @return Collection The combined event and talk data. - */ - public function format($talks, array $eventData) - { - $eventData = collect($eventData); - - return collect($talks)->flatMap(function ($talk) use ($eventData) { - // Build an associative array with the talk, as well as the - // specified event data (e.g. date and time) as well as the shared - // event data (e.g. event name and website). - return collect($talk['events']) - ->map(function ($event) use ($talk, $eventData) { - $event = collect($event); - $event = $event->merge($eventData->get($event->get('event')))->all(); - - return compact('event', 'talk'); - }); - }); + return $this->getAll($talks)->filter(function ($talk) { + return $this->getLastDate($talk) < $this->today; + })->values(); } /** @@ -114,4 +83,9 @@ class TalksExtension extends Twig_Extension { return 'talks'; } + + private function getLastDate($talk): string + { + return (string) collect($talk['events'])->pluck('date')->sort()->last(); + } } diff --git a/tests/TalksBundle/TwigExtension/FormatTalksTest.php b/tests/TalksBundle/TwigExtension/FormatTalksTest.php deleted file mode 100644 index f4c1baae..00000000 --- a/tests/TalksBundle/TwigExtension/FormatTalksTest.php +++ /dev/null @@ -1,177 +0,0 @@ -extension = new TalksExtension(); - } - - /** @test */ - public function format_events() - { - $event_data = [ - 'event-a' => [ - 'name' => 'Event A', - 'location' => 'Somewhere', - 'website' => 'http://event-a.com', - ], - 'event-b' => [ - 'name' => 'Event B', - 'location' => 'Somewhere else', - 'website' => 'http://event-b.com', - ], - ]; - - $talks = [ - [ - 'title' => 'Talk A', - 'events' => [ - ['event' => 'event-a', 'date' => strtotime('2018-01-01'), 'time' => '09:00'], - ['event' => 'event-b', 'date' => strtotime('2018-01-30'), 'time' => '12:00'], - ], - ], - [ - 'title' => 'Talk B', - 'events' => [ - ['event' => 'event-b', 'date' => strtotime('2018-01-31'), 'time' => '17:00'], - ], - ], - ]; - - $results = $this->extension->format($talks, $event_data); - - $this->assertCount(3, $results); - - tap($results->first(), function ($result) { - $this->assertArrayHasKey('event', $result); - $this->assertArrayHasKey('talk', $result); - - $this->assertEquals([ - 'date' => '1514764800', - 'event' => 'event-a', - 'location' => 'Somewhere', - 'name' => 'Event A', - 'time' => '09:00', - 'website' => 'http://event-a.com', - ], $result['event']); - - $this->assertEquals('Talk A', $result['talk']['title']); - }); - - tap($results->get(1), function ($result) { - $this->assertArrayHasKey('event', $result); - $this->assertArrayHasKey('talk', $result); - - $this->assertEquals([ - 'date' => 1517270400, - 'event' => 'event-b', - 'location' => 'Somewhere else', - 'name' => 'Event B', - 'time' => '12:00', - 'website' => 'http://event-b.com', - ], $result['event']); - - $this->assertEquals('Talk A', $result['talk']['title']); - }); - - tap($results[2], function ($result) { - $this->assertEquals('Talk B', $result['talk']['title']); - }); - } - - /** @test */ - public function get_all_events() - { - $eventA = ['date' => (new DateTime('+1 week'))->getTimestamp()]; - $eventB = ['date' => (new DateTime('-2 weeks'))->getTimestamp()]; - $eventC = ['date' => (new DateTime('today'))->getTimestamp()]; - - $talks = [ - ['events' => [$eventA, $eventB]], - ['events' => [$eventC]], - ]; - - $results = $this->extension->getAll($talks); - - $this->assertCount(3, $results); - - // Earliest events should be returned first. - $this->assertEquals( - [$eventB['date'], $eventC['date'], $eventA['date']], - $this->extractDates($results) - ); - } - - /** @test */ - public function get_upcoming_events() - { - $eventA = ['date' => (new DateTime('+1 week'))->getTimestamp()]; - $eventB = ['date' => (new DateTime('-2 weeks'))->getTimestamp()]; - $eventC = ['date' => (new DateTime('today'))->getTimestamp()]; - $eventD = ['date' => (new DateTime('+1 day'))->getTimestamp()]; - $eventE = ['date' => (new DateTime('+2 weeks'))->getTimestamp()]; - - $talks = [ - ['events' => [$eventA, $eventC]], - ['events' => [$eventB, $eventE]], - ]; - - $results = $this->extension->getUpcoming($talks); - - $this->assertCount(3, $results); - - // Earliest events should be returned first. - $this->assertEquals( - [$eventC['date'], $eventA['date'], $eventE['date']], - $this->extractDates($results) - ); - } - - /** @test */ - public function get_past_events() - { - $eventA = ['date' => (new DateTime('+1 week'))->getTimestamp()]; - $eventB = ['date' => (new DateTime('-2 weeks'))->getTimestamp()]; - $eventC = ['date' => (new DateTime('today'))->getTimestamp()]; - $eventD = ['date' => (new DateTime('+1 day'))->getTimestamp()]; - $eventE = ['date' => (new DateTime('-2 days'))->getTimestamp()]; - $eventF = ['date' => (new DateTime('-2 months'))->getTimestamp()]; - - $talks = [ - ['events' => [$eventD]], - ['events' => [$eventA, $eventB, $eventC]], - ['events' => [$eventF]], - ]; - - $results = $this->extension->getPast($talks); - - $this->assertCount(2, $results); - - // Latest events should be returned first. - $this->assertEquals( - [$eventB['date'], $eventF['date']], - $this->extractDates($results) - ); - } - - private function extractDates(Collection $results) - { - return $results->pluck('event.date')->all(); - } -} diff --git a/tests/TalksBundle/TwigExtension/TalksExtensionTest.php b/tests/TalksBundle/TwigExtension/TalksExtensionTest.php new file mode 100644 index 00000000..90d1c276 --- /dev/null +++ b/tests/TalksBundle/TwigExtension/TalksExtensionTest.php @@ -0,0 +1,144 @@ +extension = new TalksExtension(); + } + + /** @test */ + public function talks_given_multiple_times_are_only_returned_once() + { + $talkA = [ + 'title' => 'Talk A', + 'events' => [ + ['event' => 'event_a', 'date' => (new DateTime('-1 days'))->getTimestamp()], + ['event' => 'event_b', 'date' => (new DateTime('+1 days'))->getTimestamp()], + ], + ]; + + $talkB = [ + 'title' => 'Talk B', + 'events' => [ + ['event' => 'event_a', 'date' => (new DateTime('-3 days'))->getTimestamp()], + ], + ]; + + $this->assertCount(2, $this->extension->getAll([$talkA, $talkB])); + } + + /** @test */ + public function talks_are_ordered_by_the_most_recent_event_date() + { + $talkA = [ + 'title' => 'Talk A', + 'events' => [ + ['event' => 'event_a', 'date' => (new DateTime('-5 days'))->getTimestamp()], + ], + ]; + + $talkB = [ + 'title' => 'Talk B', + 'events' => [ + ['event' => 'event_a', 'date' => (new DateTime('-20 days'))->getTimestamp()], + ], + ]; + + $talkC = [ + 'title' => 'Talk C', + 'events' => [ + ['event' => 'event_a', 'date' => (new DateTime('-3 days'))->getTimestamp()], + ['event' => 'event_b', 'date' => (new DateTime('-10 days'))->getTimestamp()], + ], + ]; + + $unorderedTalks = [$talkC, $talkA, $talkB]; + $orderedTalks = $this->extension->getAll($unorderedTalks); + + $this->assertEquals([$talkC, $talkA, $talkB], $orderedTalks->toArray()); + } + + /** @test */ + public function only_past_talks_can_be_retrieved() + { + $pastTalk = [ + 'title' => 'Past talk', + 'events' => [ + ['date' => (new DateTime('-1 day'))->getTimestamp()], + ] + ]; + + $futureTalk = [ + 'title' => 'Future talk', + 'events' => [ + ['date' => (new DateTime('+1 day'))->getTimestamp()], + ], + ]; + + $result = $this->extension->getPast([$pastTalk, $futureTalk]); + + $this->assertCount(1, $result); + $this->assertSame($pastTalk, $result->first()); + } + + /** @test */ + public function only_current_and_future_talks_can_be_retrieved() + { + $pastTalk = [ + 'title' => 'Past talk', + 'events' => [ + ['date' => (new DateTime('-1 day'))->getTimestamp()], + ] + ]; + + $todayTalk = [ + 'title' => 'A talk that it happening today', + 'events' => [ + ['date' => (new DateTime('now'))->getTimestamp()], + ], + ]; + + $futureTalk = [ + 'title' => 'Future talk', + 'events' => [ + ['date' => (new DateTime('+1 day'))->getTimestamp()], + ], + ]; + + $result = $this->extension->getUpcoming([$pastTalk, $todayTalk, $futureTalk]); + + $this->assertCount(2, $result); + $this->assertSame([$todayTalk, $futureTalk], $result->toArray()); + } + + /** @test */ + public function if_a_talk_is_both_upcoming_and_past_then_it_is_only_shown_as_upcoming() + { + $talk = [ + 'title' => 'An upcoming talk that has been given before', + 'events' => [ + ['date' => (new DateTime('-1 week'))->getTimestamp()], + ['date' => (new DateTime('+1 week'))->getTimestamp()], + ], + ]; + + $this->assertCount(1, $this->extension->getUpcoming([$talk])); + $this->assertEmpty($this->extension->getPast([$talk])); + } +} diff --git a/yarn.lock b/yarn.lock index 4e4a0057..5168d885 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6550,10 +6550,9 @@ tailwindcss-skip-link@^1.0.0: resolved "https://registry.yarnpkg.com/tailwindcss-skip-link/-/tailwindcss-skip-link-1.0.1.tgz#b965624ed0b007ddd33f0326f2719d9a88b857c7" integrity sha512-Hxivkqu7UEluZY+ZPv+aQv4dreqTfYRgniEtux4qb9yJPjyR4dXiHMIWk7LgNqsyCPKpoRL8FJq55uIQN4ms+w== -tailwindcss-spaced-items@^0.1.0: +"tailwindcss-spaced-items@https://github.com/n1kk/tailwindcss-spaced-items#master": version "0.1.0" - resolved "https://registry.yarnpkg.com/tailwindcss-spaced-items/-/tailwindcss-spaced-items-0.1.0.tgz#e7f381e5c780a034bcdbc38a6a2cfb31f828a020" - integrity sha512-YiT1h89fp13r6I+EBM8wS1RWfsTwzHSi4BAnHoTXXQK1GQ53DUCPeFNmiksYSdx2aQLMdp/DTPvErqBVfTALiQ== + resolved "https://github.com/n1kk/tailwindcss-spaced-items#00aeaa1b37b6a6c2614b1f656bd9120b3839a089" tailwindcss-visuallyhidden@^1.0.1: version "1.0.1"