localgovdrupal / localgov_microsites_group

LocalGov Drupal Microsites Group integration
1 stars 2 forks source link

Add phpunit tests to cover enabling and disabling content types for a given microsite. #464

Closed finnlewis closed 3 months ago

finnlewis commented 6 months ago

To get to a stable release, @ekes suggested that we should add phpunit tests to confirm that the content type options are being respected.

As a microsites controller,

I want to enable or disable content types for a given microsite

So that I can restrict the content types available to a microsite content designer.

As a 'trusted editor'

I want to only be able; to create see the content types that are enabled.

So that I don't create illegal content types

So we want some phpunit tests as follows.

  1. Create a microsite (micsrosite 1) as a user with the 'microsites controller' role.
  2. Disable all optional content types on the microsite (group/1/domain-settings)
  3. Create a user 'editor 1' and assign that user to microsite 1.
  4. Log into microsite 1 as editor 1
  5. Confirm I cannot create News, Webform, Events, Directories, Blogs
    1. As controller 1 user, enable Webform content for microsite 1
  6. As editor 1 on microsite 1, confirm I can create Webform content.
  7. As controller 1 user, enable news content for microsite 1
  8. As editor 1 on microsite 1, confirm I can create news content.
  9. As controller 1 user, enable events content for microsite 1
  10. As editor 1 on microsite 1, confirm I can create events content.
  11. As controller 1 user, enable Directories content for microsite 1
  12. As editor 1 on microsite 1, confirm I can create Directories content.
  13. As controller 1 user, enable blogs content for microsite 1
  14. As editor 1 on microsite 1, confirm I can create blog content.
finnlewis commented 6 months ago

@opdavies is going to take a look at adding some tests.

Then, hopefully we can review the other issues on https://github.com/localgovdrupal/localgov_microsites/issues/378 and release 4.0.0

ekes commented 6 months ago

Once the tests are there it would be nice to move the code from the present route/form based approach to using the permissions in the variation cache by domain. But I think having the tests there is the safeguard we need.

opdavies commented 6 months ago

I've started looking at this, and have begun to write a new functional test based on GroupAdminAccessTest.

My first observation is that it's very slow to run, taking 2 or 3 minutes to run the single test, although it uses the same setUp() contents as GroupAdminAccessTest.

I also get these errors intermittently, which are happening for other tests, too, and not just the one I'm writing:

There was 1 risky test:

1) Drupal\Tests\localgov_microsites_directories\Functional\MicrositeDirectoryContentTest::testMicrositeDirectoryContent
This test did not perform any assertions

/var/www/html/web/core/tests/Drupal/Tests/Listeners/DrupalListener.php:62
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:453
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:685
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:685
/var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
/var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php:146
/var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php:99
1) Drupal\Tests\localgov_microsites_group\Functional\DisablingContentTypesTest::test_a
Drupal\Core\Config\ConfigValueException: The hostname (web) is already registered.

Are either of these known issues that have been experienced whilst writing the existing tests?

opdavies commented 6 months ago

This test did not perform any assertions seems to happen when I add localgov_microsites_events to the $modules list, but I can work around it by creating the required localgov_event content type manually within the test.

opdavies commented 6 months ago

I'm currently getting this error:

1) Drupal\Tests\localgov_microsites_group\Functional\DisablingContentTypesTest::test_a Invalid permission create group_node:localgov_event entity.

This permission name matches the format used in other modules, and the group, gnode and localgov_microsites_group modules are enabled.

Before trying to add the permission, I received a 403 response code for http://group-1.web//group/1/content/create/group_node:localgov_event instead of the expected 200.

/node/add/localgov_event is accessible whether the content type is enabled or not so I can't test that path.

I suspect there is further configuration to do in the test between the content type and the group type.

ekes commented 6 months ago

Ach ignore me... updated.

ekes commented 5 months ago

Added a WIP with tasks to do on #469

finnlewis commented 5 months ago

@ekes am I right in thinking that https://github.com/localgovdrupal/localgov_microsites_group/pull/469 aims to take care of this issue ?

ekes commented 5 months ago

469 is a set of tests for this issue, now pretty complete I think. So complete a couple will fail (so could be commented out).

470 is 469 with additional code to fix the failing tests.