From 80651966a73e377afb978a48407fe24168a86113 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 12 Feb 2020 01:28:54 +0000 Subject: [PATCH] Add post import script --- web/export.json | 1585 +++++++++++++++++++++++++++++++++++++++++++++++ web/import.php | 44 ++ 2 files changed, 1629 insertions(+) create mode 100644 web/export.json create mode 100644 web/import.php diff --git a/web/export.json b/web/export.json new file mode 100644 index 0000000..703e435 --- /dev/null +++ b/web/export.json @@ -0,0 +1,1585 @@ +{ + "articles": [ + { + "title": "Testing Workshop at DrupalCamp London 2020", + "path": "/articles/drupalcamp-london-testing-workshop", + "is_draft": "false", + "created": "1580860800", + "excerpt": "This year, I\u2019m teaching a workshop at DrupalCamp London.", + "body": "

\"\"<\/p>\n\n

This year, I\u2019m teaching a workshop at DrupalCamp London.<\/p>\n\n

The subject will be automated testing and test driven development in Drupal 8, and it will be on Friday 13th March 2020, between 9am and 1pm.<\/p>\n\n

In the workshop, I\u2019ll cover the methodology, approaches and terminology involved with automated testing, look at some examples and work through some exercises, and then take a test driven development approach to creating a new Drupal module.<\/p>\n\n

There are also other workshops on topics including Composer, Drupal Commerce, profiling, and chatbots.<\/p>\n\n

For more information and to register, go to the DrupalCamp London website<\/a>.<\/p>\n", + "tags": ["drupal" + ,"drupalcamp" + ,"testing" + ] + }, { + "title": "Using PSR-4 Autoloading for your Drupal 7 Test Cases", + "path": "/articles/psr4-autoloading-test-cases-drupal-7", + "is_draft": "false", + "created": "1580774400", + "excerpt": "How to use the PSR-4 autoloading standard for Drupal 7 Simpletest test cases.", + "body": "

How to use the PSR-4 autoloading standard for Drupal 7 Simpletest test cases.<\/p>\n\n

The Traditional Way<\/h2>\n\n

The typical way of including test cases in Drupal 7 is to add one or more classes within a .test<\/code> file - e.g. opdavies.test<\/code>.\nThis would typically include all of the different test cases for that module, and would be placed in the root of the module\u2019s directory alongside the .info<\/code> and .module<\/code> files.<\/p>\n\n

In order to load the files, each file would need to be declared within the .info<\/code> file for the module.<\/p>\n\n

There is a convention that if you have multiple tests for your project, these can be split into different files and grouped within a tests<\/code> directory.<\/p>\n\n

; Load a test file at the root of the module\nfiles[] = opdavies.test\n\n; Load a test file from within a subdirectory\nfiles[] = tests\/foo.test\nfiles[] = tests\/bar.test\n<\/code><\/pre>\n\n

Using the xautoload Module<\/h2>\n\n

Whilst splitting tests into separate files makes things more organised, each file needs to be loaded separately.\nThis can be made simpler by using the Xautoload module<\/a>, which supports wildcards when declaring files.<\/p>\n\n

files[] = tests\/**\/*.test\n<\/code><\/pre>\n\n

This would load all of the .test<\/code> files within the tests directory.<\/p>\n\n

Using PSR-4 Autoloading<\/h2>\n\n

Another option is to use PSR-4 (or PSR-0) autoloading.<\/p>\n\n

This should be a lot more familiar to those who have worked with Drupal 8, Symfony etc, and means that each test case is in its own file which is cleaner, files have the .php<\/code> extension which is more standard, and the name of the file matches the name of the test class for consistency.<\/p>\n\n

To do this, create a src\/Tests<\/code> (PSR-4) or lib\/Drupal\/{module_name}\/Tests<\/code> (PSR-0) directory within your module, and then add or move your test cases there.\nAdd the appropriate namespace for your module, and ensure that DrupalWebTestCase<\/code> or DrupalUnitTestCase<\/code> is also namespaced.<\/p>\n\n

\/\/ src\/Tests\/Functional\/OliverDaviesTest.php\n\nnamespace Drupal\\opdavies\\Tests\\Functional;\n\nclass OliverDaviesTest extends \\DrupalWebTestCase {\n  \/\/ ...\n}\n<\/code><\/pre>\n\n

This also supports subdirectories, so you can group classes within Functional<\/code> and Unit<\/code> directories if you like.<\/p>\n\n

If you want to see an real-world example, see the Drupal 7 branch of the Override Node Options module<\/a>.<\/p>\n\n

Digging into the simpletest_test_get_all function<\/h3>\n\n

This is the code within simpletest.module<\/code> that makes this work:<\/p>\n\n

\/\/ simpletest_test_get_all()\n\n\/\/ ...\n\n$module_dir = DRUPAL_ROOT . '\/' . dirname($filename);\n\n\/\/ Search both the 'lib\/Drupal\/mymodule' directory (for PSR-0 classes)\n\/\/ and the 'src' directory (for PSR-4 classes).\nforeach (array(\n  'lib\/Drupal\/' . $name,\n  'src',\n) as $subdir) {\n\n  \/\/ Build directory in which the test files would reside.\n  $tests_dir = $module_dir . '\/' . $subdir . '\/Tests';\n\n  \/\/ Scan it for test files if it exists.\n  if (is_dir($tests_dir)) {\n    $files = file_scan_directory($tests_dir, '\/.*\\\\.php\/');\n    if (!empty($files)) {\n      foreach ($files as $file) {\n\n        \/\/ Convert the file name into the namespaced class name.\n        $replacements = array(\n          '\/' => '\\\\',\n          $module_dir . '\/' => '',\n          'lib\/' => '',\n          'src\/' => 'Drupal\\\\' . $name . '\\\\',\n          '.php' => '',\n        );\n        $classes[] = strtr($file->uri, $replacements);\n      }\n    }\n  }\n}\n<\/code><\/pre>\n\n

It looks for a the tests directory (src\/Tests<\/code> or lib\/Drupal\/{module_name}\/Tests<\/code>) within the module, and then finds any .php<\/code> files within it. It then converts the file name into the fully qualified (namespaced) class name and loads it automatically.<\/p>\n\n

Running the Tests<\/h3>\n\n

You can still run the tests from within the Simpletest UI, or from the command line using run-tests.sh<\/code>.<\/p>\n\n

If you want to run a specific test case using the --class<\/code> option, you will now need to include the fully qualified name.<\/p>\n\n

php scripts\/run-tests.sh --class Drupal\\\\opdavies\\\\Tests\\\\Functional\\\\OliverDaviesTest\n<\/code><\/pre>\n",
+                "tags": ["drupal"
+                        ,"drupal-planet"
+                        ,"drupal-7"
+                        ,"testing"
+                        ,"simpletest"
+                        ,"php"
+                        ,"psr"
+                        ]
+            },            {
+                "title": "Live Blogging From SymfonyLive London 2019",
+                "path": "/articles/live-blogging-symfonylive-london",
+                "is_draft": "false",
+                "created": "1568332800",
+                "excerpt": "",
+                "body": "

Inspired by Matt Stauffer<\/a>'s live blogging of the keynote<\/a> at Laracon US, I\u2019m going to do the same for the sessions that I\u2019m attending at SymfonyLive London 2019<\/a>...<\/p>\n\n

Keynote (Back to the basics)<\/h2>\n\n

Embrace the Linux philosophy<\/strong><\/p>\n\n