From 4e559f80eb5b1d341177218141b334fa950cc5d8 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 15 Jul 2025 22:33:45 +0100 Subject: [PATCH] Add daily email --- content/meta/index.json | 7 + ...e.2e8662f9-eab9-41a9-ae4a-7145b7931bea.yml | 123 ++++++++++++++++++ ...s.bb4475a3-d279-415f-a52f-82fc5ca77c08.yml | 10 ++ 3 files changed, 140 insertions(+) create mode 100644 content/node.2e8662f9-eab9-41a9-ae4a-7145b7931bea.yml create mode 100644 content/path_alias.bb4475a3-d279-415f-a52f-82fc5ca77c08.yml diff --git a/content/meta/index.json b/content/meta/index.json index 93be95065..19bcdf0e1 100644 --- a/content/meta/index.json +++ b/content/meta/index.json @@ -7095,5 +7095,12 @@ ], "path_alias.c0009260-e116-4e4b-8638-f46658a1b955": [ "node.5a77f50e-a593-4a7f-b2b2-1a39114e9668" + ], + "node.2e8662f9-eab9-41a9-ae4a-7145b7931bea": [ + "user.b8966985-d4b2-42a7-a319-2e94ccfbb849", + "node.e3f6c728-7855-4804-8614-e2a0c08c368f" + ], + "path_alias.bb4475a3-d279-415f-a52f-82fc5ca77c08": [ + "node.2e8662f9-eab9-41a9-ae4a-7145b7931bea" ] } \ No newline at end of file diff --git a/content/node.2e8662f9-eab9-41a9-ae4a-7145b7931bea.yml b/content/node.2e8662f9-eab9-41a9-ae4a-7145b7931bea.yml new file mode 100644 index 000000000..43fa0f47e --- /dev/null +++ b/content/node.2e8662f9-eab9-41a9-ae4a-7145b7931bea.yml @@ -0,0 +1,123 @@ +uuid: + - value: 2e8662f9-eab9-41a9-ae4a-7145b7931bea +langcode: + - value: en +type: + - target_id: daily_email + target_type: node_type + target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7 +revision_timestamp: + - value: '2025-07-15T21:42:41+00:00' +revision_uid: + - target_type: user + target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 +revision_log: { } +status: + - value: true +uid: + - target_type: user + target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 +title: + - value: 'The downside to testing existing sites' +created: + - value: '2025-07-14T21:24:24+00:00' +changed: + - value: '2025-07-15T21:42:41+00:00' +promote: + - value: false +sticky: + - value: false +default_langcode: + - value: true +revision_translation_affected: + - value: true +path: + - alias: /daily/2025/07/14/downside-testing-existing-sites + langcode: en +body: + - value: |- + Whilst [experimenting with Drupal Test Traits][1], I've needed to re-think how I've written some tests. + + When writing a test for a Repository class that finds published podcast episode nodes, I can't create three published and two unpublished nodes, get the result and assert exactly three were returned. + + Because I'm testing an existing site, all my existing content is available in each test. + + I already have published podcast episode nodes, so the count is always going to be greater than what I created in the test. + + In a traditional test, everything is re-installed from scratch for every test, so this wouldn't be an issue. + + ## The issue testing existing sites + + If I'm testing an existing site and already have a page with the path of `/available`, this test would pass: + + ```php + drupalGet('/available'); + + $assert = $this->assertSession(); + $assert->statusCodeEquals(Response::HTTP_OK); + $assert->responseContains('Available for Drupal consulting'); + } + ``` + + But, there's nothing in the test to show the page was created. + + The test assumes the page already exists, but how do we know that? + + Can we assume the page will always exist? + + Will it exist on every development environment or in a CI pipeline? + + ## Here's the thing + + Maybe it's against the spirit of testing an existing site, but my advice is to only assert on what you've created in that test. + + It makes the test more readable and easier to understand. + + People don't need to go elsewhere to find how something was created. + + If I'm testing published podcast nodes, I can count how many there are at the start of the test and assert the number has increased by a given amount and get the same result. + + The test just needs to be written slightly differently. + + Or, you can mix and match, and [use traditional test types where appropriate][0]. + + [0]: /daily/2025/07/13/drupal-test-traits-not-replacement-traditional-tests + [1]: /daily/2025/06/18/exploring-drupal-test-traits + format: markdown + processed: | +

Whilst experimenting with Drupal Test Traits, I've needed to re-think how I've written some tests.

+

When writing a test for a Repository class that finds published podcast episode nodes, I can't create three published and two unpublished nodes, get the result and assert exactly three were returned.

+

Because I'm testing an existing site, all my existing content is available in each test.

+

I already have published podcast episode nodes, so the count is always going to be greater than what I created in the test.

+

In a traditional test, everything is re-installed from scratch for every test, so this wouldn't be an issue.

+

The issue testing existing sites

+

If I'm testing an existing site and already have a page with the path of /available, this test would pass:

+
<?php
+
+      /** @test */
+      public function the_available_page_loads(): void {
+        $this->drupalGet('/available');
+
+        $assert = $this->assertSession();
+        $assert->statusCodeEquals(Response::HTTP_OK);
+        $assert->responseContains('Available for Drupal consulting');
+      }
+      

But, there's nothing in the test to show the page was created.

+

The test assumes the page already exists, but how do we know that?

+

Can we assume the page will always exist?

+

Will it exist on every development environment or in a CI pipeline?

+

Here's the thing

+

Maybe it's against the spirit of testing an existing site, but my advice is to only assert on what you've created in that test.

+

It makes the test more readable and easier to understand.

+

People don't need to go elsewhere to find how something was created.

+

If I'm testing published podcast nodes, I can count how many there are at the start of the test and assert the number has increased by a given amount and get the same result.

+

The test just needs to be written slightly differently.

+

Or, you can mix and match, and use traditional test types where appropriate.

+ summary: '' +field_daily_email_cta: + - target_type: node + target_uuid: e3f6c728-7855-4804-8614-e2a0c08c368f diff --git a/content/path_alias.bb4475a3-d279-415f-a52f-82fc5ca77c08.yml b/content/path_alias.bb4475a3-d279-415f-a52f-82fc5ca77c08.yml new file mode 100644 index 000000000..8e54780e8 --- /dev/null +++ b/content/path_alias.bb4475a3-d279-415f-a52f-82fc5ca77c08.yml @@ -0,0 +1,10 @@ +uuid: + - value: bb4475a3-d279-415f-a52f-82fc5ca77c08 +langcode: + - value: en +path: + - value: /node/2e8662f9-eab9-41a9-ae4a-7145b7931bea +alias: + - value: /daily/2025/07/14/downside-testing-existing-sites +status: + - value: true