function ForumUninstallValidatorTest::testValidateHasTermsForVocabularyWithNodesAccess

@covers ::validate

File

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

Class

ForumUninstallValidatorTest
@coversDefaultClass \Drupal\forum\ForumUninstallValidator[[api-linebreak]] @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.