function ForumUninstallValidatorTest::testValidateHasTermsForVocabularyWithNodesAccess

Same name and namespace in other branches
  1. 9 core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php \Drupal\Tests\forum\Unit\ForumUninstallValidatorTest::testValidateHasTermsForVocabularyWithNodesAccess()
  2. 10 core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php \Drupal\Tests\forum\Unit\ForumUninstallValidatorTest::testValidateHasTermsForVocabularyWithNodesAccess()
  3. 11.x core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php \Drupal\Tests\forum\Unit\ForumUninstallValidatorTest::testValidateHasTermsForVocabularyWithNodesAccess()

@covers ::validate

File

core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php, line 102

Class

ForumUninstallValidatorTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21forum%21src%21ForumUninstallValidator.php/class/ForumUninstallValidator/8.9.x" title="Prevents forum module from being uninstalled whilst any forum nodes exist or there are any terms in the forum vocabulary." class="local">\Drupal\forum\ForumUninstallValidator</a> @group forum

Namespace

Drupal\Tests\forum\Unit

Code

public function testValidateHasTermsForVocabularyWithNodesAccess() {
    $this->forumUninstallValidator
        ->expects($this->once())
        ->method('hasForumNodes')
        ->willReturn(TRUE);
    $url = $this->prophesize(Url::class);
    $url->toString()
        ->willReturn('/path/to/vocabulary/overview');
    $vocabulary = $this->createMock('Drupal\\taxonomy\\VocabularyInterface');
    $vocabulary->expects($this->once())
        ->method('label')
        ->willReturn('Vocabulary label');
    $vocabulary->expects($this->once())
        ->method('toUrl')
        ->willReturn($url->reveal());
    $vocabulary->expects($this->once())
        ->method('access')
        ->willReturn(TRUE);
    $this->forumUninstallValidator
        ->expects($this->once())
        ->method('getForumVocabulary')
        ->willReturn($vocabulary);
    $this->forumUninstallValidator
        ->expects($this->once())
        ->method('hasTermsForVocabulary')
        ->willReturn(TRUE);
    $module = 'forum';
    $expected = [
        'To uninstall Forum, first delete all <em>Forum</em> content',
        'To uninstall Forum, first delete all <a href="/path/to/vocabulary/overview"><em class="placeholder">Vocabulary label</em></a> terms',
    ];
    $reasons = $this->forumUninstallValidator
        ->validate($module);
    $this->assertSame($expected, $this->castSafeStrings($reasons));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.