From 97d1f11263e900513bf2181c820b2d5341b7f723 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 8 Nov 2017 06:56:37 +0000 Subject: [PATCH] Update slides --- tdd-test-driven-drupal/slides.md | 56 ++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/tdd-test-driven-drupal/slides.md b/tdd-test-driven-drupal/slides.md index 0966284..7a14e1f 100644 --- a/tdd-test-driven-drupal/slides.md +++ b/tdd-test-driven-drupal/slides.md @@ -8,6 +8,8 @@ theme: next, 9 --- +[.build-lists: false] + - PHP code - Mixture of D7 and D8 - SimpleTest (D7) @@ -24,7 +26,12 @@ theme: next, 9 - @opdavies - oliverdavies.uk -![right](../../me-phpnw.png) +![right](../me-phpnw.png) + +--- + +## I write and release contrib modules for the community.

+## I write custom modules for client projects. --- @@ -54,15 +61,6 @@ ONO merge conflict --- -## Why Not Test? - -- Don't know how -- No time/budget to write tests - -^ "I'd love to write tests, but I don't have the time to learn." - ---- - ## Core Testing Gate New features should be accompanied by automated tests. @@ -338,6 +336,15 @@ $this->drupalLogout(); --- +## Assertions + +- `assertText` + `assertSession()->pageTextContains()` +- `assertNoText` + `assertSession()->pageTextNotContains()` + +--- + ## [fit] Running Tests --- @@ -904,13 +911,29 @@ public function testOnlyPublishedPagesAreShown() { --- +```php +public function testOnlyPublishedPagesAreShown() { + ... + + $this->drupalGet('pages'); + + $this->assertSession() + ->pageTextContains($nodeA->label()); + + $this->assertSession() + ->pageTextNotContains($nodeB->label()); +} +``` + +--- + ```php public function testOnlyPublishedPagesAreShown() { ... $results = views_get_view_result('pages'); - $nids = collect($results)->pluck('nid')->all(); + $nids = array_column($results, 'nid'); // [1, 3] // I should only see the published pages. @@ -925,7 +948,7 @@ public function testOnlyPublishedPagesAreShown() { $results = views_get_view_result('pages'); - $nids = collect($results)->pluck('nid')->all(); + $nids = array_column($results, 'nid'); // [1, 3] $this->assertEquals([1], $nids); @@ -1014,7 +1037,7 @@ public function testPagesAreOrderedAlphabetically() { $results = views_get_view_result('pages'); - $nids = collect($results)->pluck('nid')->all(); + $nids = array_column($results, 'nid'); $this->assertEquals([1, 3, 4, 2], $nids); } @@ -1114,6 +1137,13 @@ Manual testing is still important --- +## Resources + +- https://github.com/opdavies/tdd_dublin +- https://oliverdavies.uk/blog/tdd-test-driven-drupal + +--- + ## Thanks! # Questions? ### @opdavies