class ForumUninstallValidatorTest

Same name in other branches
  1. 9 core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php \Drupal\Tests\forum\Unit\ForumUninstallValidatorTest
  2. 8.9.x core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php \Drupal\Tests\forum\Unit\ForumUninstallValidatorTest
  3. 11.x core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php \Drupal\Tests\forum\Unit\ForumUninstallValidatorTest

@coversDefaultClass \Drupal\forum\ForumUninstallValidator @group forum @group legacy

Hierarchy

Expanded class hierarchy of ForumUninstallValidatorTest

File

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

Namespace

Drupal\Tests\forum\Unit
View source
class ForumUninstallValidatorTest extends UnitTestCase {
    
    /**
     * @var \Drupal\forum\ForumUninstallValidator|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $forumUninstallValidator;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->forumUninstallValidator = $this->getMockBuilder('Drupal\\forum\\ForumUninstallValidator')
            ->disableOriginalConstructor()
            ->onlyMethods([
            'hasForumNodes',
            'hasTermsForVocabulary',
            'getForumVocabulary',
        ])
            ->getMock();
        $this->forumUninstallValidator
            ->setStringTranslation($this->getStringTranslationStub());
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateNotForum() : void {
        $this->forumUninstallValidator
            ->expects($this->never())
            ->method('hasForumNodes');
        $this->forumUninstallValidator
            ->expects($this->never())
            ->method('hasTermsForVocabulary');
        $this->forumUninstallValidator
            ->expects($this->never())
            ->method('getForumVocabulary');
        $module = 'not_forum';
        $expected = [];
        $reasons = $this->forumUninstallValidator
            ->validate($module);
        $this->assertEquals($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidate() : void {
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('hasForumNodes')
            ->willReturn(FALSE);
        $vocabulary = $this->createMock('Drupal\\taxonomy\\VocabularyInterface');
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('getForumVocabulary')
            ->willReturn($vocabulary);
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('hasTermsForVocabulary')
            ->willReturn(FALSE);
        $module = 'forum';
        $expected = [];
        $reasons = $this->forumUninstallValidator
            ->validate($module);
        $this->assertEquals($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateHasForumNodes() : void {
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('hasForumNodes')
            ->willReturn(TRUE);
        $vocabulary = $this->createMock('Drupal\\taxonomy\\VocabularyInterface');
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('getForumVocabulary')
            ->willReturn($vocabulary);
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('hasTermsForVocabulary')
            ->willReturn(FALSE);
        $module = 'forum';
        $expected = [
            'To uninstall Forum, first delete all <em>Forum</em> content',
        ];
        $reasons = $this->forumUninstallValidator
            ->validate($module);
        $this->assertEquals($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateHasTermsForVocabularyWithNodesAccess() : void {
        $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->assertEquals($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateHasTermsForVocabularyWithNodesNoAccess() : void {
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('hasForumNodes')
            ->willReturn(TRUE);
        $vocabulary = $this->createMock('Drupal\\taxonomy\\VocabularyInterface');
        $vocabulary->expects($this->once())
            ->method('label')
            ->willReturn('Vocabulary label');
        $vocabulary->expects($this->never())
            ->method('toUrl');
        $vocabulary->expects($this->once())
            ->method('access')
            ->willReturn(FALSE);
        $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 <em class="placeholder">Vocabulary label</em> terms',
        ];
        $reasons = $this->forumUninstallValidator
            ->validate($module);
        $this->assertEquals($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateHasTermsForVocabularyAccess() : void {
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('hasForumNodes')
            ->willReturn(FALSE);
        $url = $this->prophesize(Url::class);
        $url->toString()
            ->willReturn('/path/to/vocabulary/overview');
        $vocabulary = $this->createMock('Drupal\\taxonomy\\VocabularyInterface');
        $vocabulary->expects($this->once())
            ->method('toUrl')
            ->willReturn($url->reveal());
        $vocabulary->expects($this->once())
            ->method('label')
            ->willReturn('Vocabulary label');
        $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 <a href="/path/to/vocabulary/overview"><em class="placeholder">Vocabulary label</em></a> terms',
        ];
        $reasons = $this->forumUninstallValidator
            ->validate($module);
        $this->assertEquals($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateHasTermsForVocabularyNoAccess() : void {
        $this->forumUninstallValidator
            ->expects($this->once())
            ->method('hasForumNodes')
            ->willReturn(FALSE);
        $vocabulary = $this->createMock('Drupal\\taxonomy\\VocabularyInterface');
        $vocabulary->expects($this->once())
            ->method('label')
            ->willReturn('Vocabulary label');
        $vocabulary->expects($this->never())
            ->method('toUrl');
        $vocabulary->expects($this->once())
            ->method('access')
            ->willReturn(FALSE);
        $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 class="placeholder">Vocabulary label</em> terms',
        ];
        $reasons = $this->forumUninstallValidator
            ->validate($module);
        $this->assertEquals($expected, $reasons);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
ForumUninstallValidatorTest::$forumUninstallValidator protected property
ForumUninstallValidatorTest::setUp protected function Overrides UnitTestCase::setUp
ForumUninstallValidatorTest::testValidate public function @covers ::validate
ForumUninstallValidatorTest::testValidateHasForumNodes public function @covers ::validate
ForumUninstallValidatorTest::testValidateHasTermsForVocabularyAccess public function @covers ::validate
ForumUninstallValidatorTest::testValidateHasTermsForVocabularyNoAccess public function @covers ::validate
ForumUninstallValidatorTest::testValidateHasTermsForVocabularyWithNodesAccess public function @covers ::validate
ForumUninstallValidatorTest::testValidateHasTermsForVocabularyWithNodesNoAccess public function @covers ::validate
ForumUninstallValidatorTest::testValidateNotForum public function @covers ::validate
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

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