oliverdavies.uk/content/node.0a3bf034-7203-45c2-aae5-74f9211929fa.json
2025-05-14 00:36:23 +01:00

100 lines
No EOL
5.5 KiB
JSON

{
"uuid": [
{
"value": "0a3bf034-7203-45c2-aae5-74f9211929fa"
}
],
"langcode": [
{
"value": "en"
}
],
"type": [
{
"target_id": "daily_email",
"target_type": "node_type",
"target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7"
}
],
"revision_timestamp": [
{
"value": "2025-05-11T09:00:32+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": "What's the simplest test to begin with?\n"
}
],
"created": [
{
"value": "2023-09-07T00:00:00+00:00"
}
],
"changed": [
{
"value": "2025-05-11T09:00:32+00:00"
}
],
"promote": [
{
"value": false
}
],
"sticky": [
{
"value": false
}
],
"default_langcode": [
{
"value": true
}
],
"revision_translation_affected": [
{
"value": true
}
],
"path": [
{
"alias": "\/daily\/2023\/09\/07\/what-s-the-simplest-test-to-begin-with",
"langcode": "en"
}
],
"body": [
{
"value": "\n <p>When giving talks and workshops or coaching on automated testing and test-driven development, some people may not have written tests before and aren't familiar with the structure or know where to begin.<\/p>\n\n<p>In the workshops I ran for DrupalCamp London and DrupalCamp NYC, I wanted to cover this first before writing any implementation code.<\/p>\n\n<p>Where do you put a test class, and what does it contain?<\/p>\n\n<p>How do you run the tests, and how can you make it pass or fail?<\/p>\n\n<h2 id=\"what-we-did\">What we did<\/h2>\n\n<p>To start, we wrote a test for existing functionality within Drupal core - anonymous users can visit the front page.<\/p>\n\n<p>This is the whole test:<\/p>\n\n<pre><code class=\"language-php\">&lt;?php\n\nnamespace Drupal\\Tests\\my_module\\Functional;\n\nuse Drupal\\Tests\\BrowserTestBase;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass MyModuleTest extends BrowserTestBase {\n\n\u00a0 protected $defaultTheme = 'stark';\n\n\u00a0 \/** @test *\/\n\u00a0 public function the_front_page_loads_for_anonymous_users() {\n\u00a0 \u00a0 $this-&gt;drupalGet('&lt;front&gt;');\n\n\u00a0 \u00a0 $this-&gt;assertResponse(Response::HTTP_OK);\n\u00a0 }\n\n}\n<\/code><\/pre>\n\n<p>This is a test someone can write, run and see the test pass.<\/p>\n\n<p>They can then experiment by changing the values to make the test fail in different ways.<\/p>\n\n<h2 id=\"what-next%3F\">What next?<\/h2>\n\n<p>Then, we tested anonymous users cannot access the administration pages, which is also already the case in Drupal core, and then authenticated users with the correct permissions could access them.<\/p>\n\n<p>People were getting the idea by now, and we moved on to writing and testing some of our own code.<\/p>\n\n ",
"format": "full_html",
"processed": "\n <p>When giving talks and workshops or coaching on automated testing and test-driven development, some people may not have written tests before and aren't familiar with the structure or know where to begin.<\/p>\n\n<p>In the workshops I ran for DrupalCamp London and DrupalCamp NYC, I wanted to cover this first before writing any implementation code.<\/p>\n\n<p>Where do you put a test class, and what does it contain?<\/p>\n\n<p>How do you run the tests, and how can you make it pass or fail?<\/p>\n\n<h2 id=\"what-we-did\">What we did<\/h2>\n\n<p>To start, we wrote a test for existing functionality within Drupal core - anonymous users can visit the front page.<\/p>\n\n<p>This is the whole test:<\/p>\n\n<pre><code class=\"language-php\">&lt;?php\n\nnamespace Drupal\\Tests\\my_module\\Functional;\n\nuse Drupal\\Tests\\BrowserTestBase;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass MyModuleTest extends BrowserTestBase {\n\n&nbsp; protected $defaultTheme = 'stark';\n\n&nbsp; \/** @test *\/\n&nbsp; public function the_front_page_loads_for_anonymous_users() {\n&nbsp; &nbsp; $this-&gt;drupalGet('&lt;front&gt;');\n\n&nbsp; &nbsp; $this-&gt;assertResponse(Response::HTTP_OK);\n&nbsp; }\n\n}\n<\/code><\/pre>\n\n<p>This is a test someone can write, run and see the test pass.<\/p>\n\n<p>They can then experiment by changing the values to make the test fail in different ways.<\/p>\n\n<h2 id=\"what-next%3F\">What next?<\/h2>\n\n<p>Then, we tested anonymous users cannot access the administration pages, which is also already the case in Drupal core, and then authenticated users with the correct permissions could access them.<\/p>\n\n<p>People were getting the idea by now, and we moved on to writing and testing some of our own code.<\/p>\n\n ",
"summary": null
}
],
"feeds_item": [
{
"imported": "1970-01-01T00:33:45+00:00",
"guid": null,
"hash": "af41a18ab3e2e252ab86e7243333ad9f",
"target_type": "feeds_feed",
"target_uuid": "90c85284-7ca8-4074-9178-97ff8384fe76"
}
]
}