Problem/Motivation

Permissions for taxonomy terms from an unchecked vocabulary remain active.

Steps to reproduce

1. You should have at least 2 vocabularies created. (For example: Vocabulary A and Vocabulary B)
2. On /admin/permissions-by-term/settings keep all vocabularies unchecked or check all vocabularies (in both cases this means that all are enabled).
3. Ensure that each vocabulary has at least one term with permissions set on its edit page.
4. Create test articles (for each term with permission form step 3).
5. Ensure that access to articles works correctly.
6. Go to the /admin/permissions-by-term/settings and keep checked only Vocabulary B.

Actual result: permission from Vocabulary B is still active, even if the user unchecked it on the settings page.
Expect result: permission from Vocabulary B should be reset and didn't affect access to the node.

Proposed resolution

On the /admin/permissions-by-term/settings page, when a user unchecks a vocabulary in Limit by taxonomy vocabularies, its permissions are reset.
Important: If the user unchecks all vocabularies, permissions are not reset. This means all vocabularies are considered enabled.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gilbertdelyon created an issue. See original summary.

vitaliyb98 made their first commit to this issue’s fork.

vitaliyb98’s picture

Status: Active » Needs review

Provided a function that resets term permission for unchecked vocabulary on /admin/permissions-by-term/settings (except cases when users unchecks all vocabularies which means all vocabularies are allowed)

vitaliyb98’s picture

Issue summary: View changes
vitaliyb98’s picture

Added Kernel and Functional tests for the new functionality.
I would appreciate any help with testing.

jepster_ made their first commit to this issue’s fork.

jepster_’s picture

@vitaly98: I could successfully test this. Thanks!

I slightly modified the form, for not showing the status message above the setting. It looked a bit awkward. The warning is now in the standard help text below the setting checkbox.

I tried to run the unit tests locally. Including web/modules/custom/permissions_by_term/tests/src/Functional/VocabularyResetPermissionsTest.php

Therefor I run the tests from a basic Drupal 11 project with DDEV and the PHPUnit config file from Drupal core (and the PbTs config in doubt):

bin/phpunit -c web/core/phpunit.xml.dist web/modules/custom/permissions_by_term/tests

I got the following error:

HTML output directory sites/simpletest/browser_output is not a writable directory.

PHP Warning: Class "Drupal\TestTools\PhpUnitCompatibility\PhpUnit12\TestCompatibilityTrait" not found in /var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php on line 12

Warning: Class "Drupal\TestTools\PhpUnitCompatibility\PhpUnit12\TestCompatibilityTrait" not found in /var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php on line 12
PHP Fatal error: During class fetch: Uncaught RuntimeException: The autoloader expected class "Drupal\Tests\PhpUnitCompatibilityTrait" to be defined in file "/var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php". The file was found but the class was not in it, the class name or namespace probably has a typo. in /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php:360
Stack trace:
#0 /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php(317): Symfony\Component\ErrorHandler\DebugClassLoader->checkClass()
#1 /var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php(53): Symfony\Component\ErrorHandler\DebugClassLoader->loadClass()
#2 /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php(306): include('...')
#3 /var/www/html/web/modules/custom/permissions_by_term/tests/src/Functional/NodeBatchTest.php(16): Symfony\Component\ErrorHandler\DebugClassLoader->loadClass()
#4 /var/www/html/vendor/phpunit/phpunit/src/Runner/TestSuiteLoader.php(116): require_once('...')
#5 /var/www/html/vendor/phpunit/phpunit/src/Runner/TestSuiteLoader.php(49): PHPUnit\Runner\TestSuiteLoader->loadSuiteClassFile()
#6 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(237): PHPUnit\Runner\TestSuiteLoader->load()
#7 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(258): PHPUnit\Framework\TestSuite->addTestFile()
#8 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(113): PHPUnit\Framework\TestSuite->addTestFiles()
#9 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(58): PHPUnit\TextUI\Configuration\TestSuiteBuilder->testSuiteFromPath()
#10 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(389): PHPUnit\TextUI\Configuration\TestSuiteBuilder->build()
#11 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(196): PHPUnit\TextUI\Application->buildTestSuite()
#12 /var/www/html/vendor/phpunit/phpunit/phpunit(104): PHPUnit\TextUI\Application->run()
#13 /var/www/html/bin/phpunit(122): include('...')
#14 {main} in /var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php on line 53

Fatal error: During class fetch: Uncaught RuntimeException: The autoloader expected class "Drupal\Tests\PhpUnitCompatibilityTrait" to be defined in file "/var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php". The file was found but the class was not in it, the class name or namespace probably has a typo. in /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php:360
Stack trace:
#0 /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php(317): Symfony\Component\ErrorHandler\DebugClassLoader->checkClass()
#1 /var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php(53): Symfony\Component\ErrorHandler\DebugClassLoader->loadClass()
#2 /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php(306): include('...')
#3 /var/www/html/web/modules/custom/permissions_by_term/tests/src/Functional/NodeBatchTest.php(16): Symfony\Component\ErrorHandler\DebugClassLoader->loadClass()
#4 /var/www/html/vendor/phpunit/phpunit/src/Runner/TestSuiteLoader.php(116): require_once('...')
#5 /var/www/html/vendor/phpunit/phpunit/src/Runner/TestSuiteLoader.php(49): PHPUnit\Runner\TestSuiteLoader->loadSuiteClassFile()
#6 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(237): PHPUnit\Runner\TestSuiteLoader->load()
#7 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(258): PHPUnit\Framework\TestSuite->addTestFile()
#8 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(113): PHPUnit\Framework\TestSuite->addTestFiles()
#9 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(58): PHPUnit\TextUI\Configuration\TestSuiteBuilder->testSuiteFromPath()
#10 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(389): PHPUnit\TextUI\Configuration\TestSuiteBuilder->build()
#11 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(196): PHPUnit\TextUI\Application->buildTestSuite()
#12 /var/www/html/vendor/phpunit/phpunit/phpunit(104): PHPUnit\TextUI\Application->run()
#13 /var/www/html/bin/phpunit(122): include('...')
#14 {main} in /var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php on line 53

I made the following directory existing and writeable: web/sites/simpletest/browser_output

This are my installed phpunit packages:

➜ d11-pbt d composer show | grep phpunit
phpspec/prophecy-phpunit 2.4.0 Integrating the Prophecy m...
phpunit/php-code-coverage 12.3.7 Library that provides coll...
phpunit/php-file-iterator 6.0.0 FilterIterator implementat...
phpunit/php-invoker 6.0.0 Invoke callables with a ti...
phpunit/php-text-template 5.0.0 Simple template engine.
phpunit/php-timer 8.0.0 Utility class for timing
phpunit/phpunit 12.3.8 The PHP Unit Testing frame...
symfony/phpunit-bridge 7.3.3 Provides utilities for PHP...
➜ d11-pbt

vitaliyb98’s picture

Hi @jepster_ , for local testing I usually use such command:

ddev exec SIMPLETEST_DB=mysql://db:db@db/db SIMPLETEST_BASE_URL=https://drupal.ddev.site   vendor/bin/phpunit -c core/phpunit.xml   modules/permissions_by_term/tests/src/Kernel/
jepster_’s picture

I have tried to this command, but I do still get this error:

➜ permissions_by_term git:(3408309-remains-access-control) ddev exec SIMPLETEST_DB=mysql://db:db@db/db SIMPLETEST_BASE_URL=https://drupal.ddev.site vendor/bin/phpunit -c web/core/phpunit.xml.dist web/modules/custom/permissions_by_term/tests
HTML output directory sites/simpletest/browser_output is not a writable directory.

PHP Warning: Class "Drupal\TestTools\PhpUnitCompatibility\PhpUnit12\TestCompatibilityTrait" not found in /var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php on line 12

Warning: Class "Drupal\TestTools\PhpUnitCompatibility\PhpUnit12\TestCompatibilityTrait" not found in /var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php on line 12
PHP Fatal error: During class fetch: Uncaught RuntimeException: The autoloader expected class "Drupal\Tests\PhpUnitCompatibilityTrait" to be defined in file "/var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php". The file was found but the class was not in it, the class name or namespace probably has a typo. in /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php:360
Stack trace:

Which PHPUnit version are you using? Please check like this: composer show | grep phpunit. Which Drupal version are you using?

vitaliyb98’s picture

Looks like an issue in the PHPUnit version. My PHPUnit version is 11.5.22. (in the https://git.drupalcode.org/ pipelines 11.5.36).

For experimentation, I tried to run a test on PHPunit version 12.3.8 and received a similar error:
PHP Warning: Class "Drupal\TestTools\PhpUnitCompatibility\PhpUnit12\TestCompatibilityTrait" not found in

jepster_’s picture

Now I do get this error:

7) Drupal\Tests\permissions_by_term\Functional\VocabularyResetPermissionsTest::testKeepOnlyOneVocab
Error: Class "Behat\Mink\Driver\BrowserKitDriver" not found

/var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php:285
/var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php:197
/var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php:348
/var/www/html/web/modules/custom/permissions_by_term/tests/src/Functional/VocabularyResetPermissionsTest.php:68

Is the require-dev section of your composer.json file similar?

"require-dev": {
"behat/mink": "^1.12",
"mikey179/vfsstream": "^1.6",
"phpspec/prophecy-phpunit": "^2.4",
"phpunit/phpunit": "^11.0",
"symfony/phpunit-bridge": "^7.3"
}

Tried to run it like this:

ddev exec SIMPLETEST_DB=mysql://db:db@db/db SIMPLETEST_BASE_URL=https://drupal.ddev.site vendor/bin/phpunit -c web/core/phpunit.xml.dist web/modules/custom/permissions_by_term/tests
vitaliyb98’s picture

My dev section for my test project is (but not all of this is required for running the test), i guess in your case you need behat/mink-browserkit-driver

"require-dev": {
        "behat/mink": "^1.11",
        "behat/mink-browserkit-driver": "^2.2",
        "colinodell/psr-testlogger": "^1.2",
        "composer/composer": "^2.8.1",
        "drupal/coder": "^8.3.10",
        "justinrainbow/json-schema": "^5.2 || ^6.3",
        "lullabot/mink-selenium2-driver": "^1.7",
        "lullabot/php-webdriver": "^2.0.4",
        "mglaman/phpstan-drupal": "^1.2.12",
        "micheh/phpcs-gitlab": "^1.1",
        "mikey179/vfsstream": "^1.6.11",
        "open-telemetry/exporter-otlp": "^1",
        "open-telemetry/sdk": "^1",
        "php-http/guzzle7-adapter": "^1.0",
        "phpspec/prophecy-phpunit": "^2",
        "phpstan/extension-installer": "^1.1",
        "phpstan/phpstan": "^1.12.4",
        "phpstan/phpstan-phpunit": "^1.3.16",
        "phpunit/phpunit": "^9.6.13",
        "symfony/browser-kit": "^6.4",
        "symfony/css-selector": "^6.4",
        "symfony/dom-crawler": "^6.4",
        "symfony/error-handler": "^6.4",
        "symfony/lock": "^6.4",
        "symfony/phpunit-bridge": "^6.4",
        "symfony/var-dumper": "^6.4"
    },

jepster_’s picture

Thanks, now PHPUnit is not complaining about missing dependencies.

However, now all the tests are failing:

➜ d11-pbt ddev exec SIMPLETEST_DB=mysql://db:db@db/db SIMPLETEST_BASE_URL=https://drupal.ddev.site vendor/bin/phpunit -c web/core/phpunit.xml.dist web/modules/custom/permissions_by_term/tests
HTML output directory sites/simpletest/browser_output is not a writable directory.

PHPUnit 11.5.36 by Sebastian Bergmann and contributors.

Runtime: PHP 8.3.23
Configuration: /var/www/html/web/core/phpunit.xml.dist

FFFFFFFDDDDDDDDDDDDDDDDDDDDDDD 30 / 30 (100%)

Time: 00:25.901, Memory: 8.00 MB

There were 7 failures:

1) Drupal\Tests\permissions_by_term\Functional\NodeBatchTest::testBatchOnTermEditForm with data set "0" (50, true)
User ylbdyjxw successfully logged in.
Failed asserting that false is true.

/var/www/html/web/core/tests/Drupal/Tests/UiHelperTrait.php:186
/var/www/html/web/modules/custom/permissions_by_term/tests/src/Functional/NodeBatchTest.php:71

2) Drupal\Tests\permissions_by_term\Functional\NodeBatchTest::testBatchOnTermEditForm with data set "1" (5, false)
User tawfeax4 successfully logged in.
Failed asserting that false is true.

/var/www/html/web/core/tests/Drupal/Tests/UiHelperTrait.php:186
/var/www/html/web/modules/custom/permissions_by_term/tests/src/Functional/NodeBatchTest.php:71

3) Drupal\Tests\permissions_by_term\Functional\NodeBatchTest::testBatchOnUserEditForm with data set "0" (50, true)
User n7k8v63i successfully logged in.
Failed asserting that false is true.

/var/www/html/web/core/tests/Drupal/Tests/UiHelperTrait.php:186
/var/www/html/web/modules/custom/permissions_by_term/tests/src/Functional/NodeBatchTest.php:96

4) Drupal\Tests\permissions_by_term\Functional\NodeBatchTest::testBatchOnUserEditForm with data set "1" (5, false)
User qyc7drvo successfully logged in.
Failed asserting that false is true.

Since I do get the error "HTML output directory sites/simpletest/browser_output is not a writable directory.", I was also creating this directory and set it to chmod -R 777.

vitaliyb98’s picture

It’s weird, because in the MR pipelines all tests a successful. As I see, the test failing on the user login step, I guess some error is throw during logic process locally. In such cases I suggest to debug this test with xdebug or something like that, to detect problem.

Or as a first step run only this test with —debug option

jepster_’s picture

Status: Needs review » Reviewed & tested by the community

Yes, it was the local command. The parameter for the database (sqllite) and the base url were wrong.

I ended up with this command on my DDEV setup:

ddev exec SIMPLETEST_DB=sqlite://localhost/db.sqlite SIMPLETEST_BASE_URL=https://d11-pbt.ddev.site vendor/bin/phpunit -c web/core/phpunit.xml.dist web/modules/custom/permissions_by_term/tests --filter VocabularyResetPermissionsTest

The tests did pass. However, there are a couple of deprecation messages, which should be cleaned up some time.

Vitaly, could you please create a new patch release, since you merged a couple of MRs already?

jepster_’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • jepster_ committed 0108b3cf on 3.1.x-dev authored by vitaliyb98
    Issue #3408309 : Access control remains active when you remove a...
vitaliyb98’s picture

Hi @jepster_ "Vitaly, could you please create a new patch release, since you merged a couple of MRs already?" - yes, that’s a good idea let’s plan to do it next week.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.