In order to give at least the appearance of test-driven development, we should port the existing node_access_example D7 SimpleTest tests to D8.

These tests should be ported as directly as possible, without changing them.

Note that these tests will fail. :-) The point of this exercise is to write tests that fail.

This issue will be marked fixed when they run without fatal code errors.

In order to build the tests, you will also need to generate the file structure of the module.

One thing to keep in mind is that SimpleTest shows you a stack trace for fails, as if they were errors. This is the most annoying part of porting tests; they look like they're broken when they're really not.

Steps to take:

  • Assign the issue to yourself.
  • Generate a module skeleton.
  • Convert tests.
  • Run tests.
  • More conversion if necessary.
  • Submit a patch.

Resources:

A tool to generate a module skeleton: https://drupal.org/sandbox/mile23/2230027

Test conversion notes: https://drupal.org/node/2166895

How to run tests:

Comments

colorfield’s picture

Assigned: Unassigned » colorfield
colorfield’s picture

Looks like the tool mentioned to generate the skeleton provides a lib/Drupal/node_access_example/Tests path for SimpleTest and a tests/Drupal/node_access_example/Tests path for PHPUnit. Let's scaffold using drupal console, that generates a more recent path (src/Tests).
At this point, is it useful to provide a PHPUnit test as well?

colorfield’s picture

Issue tags: +drupaldevdays

assigned ddd tag

colorfield’s picture

Status: Active » Needs review
StatusFileSize
new16.56 KB

Here is a first port. Some changes that prevented fatal errors on testNodeAccessBasic :

  • drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); (due to the permission set to 'create article content')
  • drupalCreateNode as a replacement of drupalPost to create node
  • db_select / drupalGetNodeByTitle as a replacement of db_query

Status: Needs review » Needs work

The last submitted patch, 4: port-d7-tests-to-d8-node-access-example-2277669-4.patch, failed testing.

mile23’s picture

Assigned: colorfield » Unassigned

Generally unassigning issues. Please re-assign yourself as desired.

mile23’s picture

Status: Needs work » Closed (outdated)

Thanks, @colorfield.

Work on the port continues at #2102667: Port node_access_example module to Drupal 11.4