You are here

class WebformNodeUninstallValidatorTest in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_node/tests/src/Unit/WebformNodeUninstallValidatorTest.php \Drupal\Tests\webform_node\Unit\WebformNodeUninstallValidatorTest

@coversDefaultClass \Drupal\webform_node\WebformNodeUninstallValidator @group webform_node

Hierarchy

Expanded class hierarchy of WebformNodeUninstallValidatorTest

File

modules/webform_node/tests/src/Unit/WebformNodeUninstallValidatorTest.php, line 11

Namespace

Drupal\Tests\webform_node\Unit
View source
class WebformNodeUninstallValidatorTest extends UnitTestCase {

  /**
   * A mock webform node uninstall validator.
   *
   * @var \Drupal\webform_node\WebformNodeUninstallValidator|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $webformNodeUninstallValidator;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->webformNodeUninstallValidator = $this
      ->getMockBuilder('Drupal\\webform_node\\WebformNodeUninstallValidator')
      ->disableOriginalConstructor()
      ->setMethods([
      'hasWebformNodes',
    ])
      ->getMock();
    $this->webformNodeUninstallValidator
      ->setStringTranslation($this
      ->getStringTranslationStub());
  }

  /**
   * @covers ::validate
   */
  public function testValidateNotWebformNode() {
    $this->webformNodeUninstallValidator
      ->expects($this
      ->never())
      ->method('hasWebformNodes');
    $module = 'not_webform_node';
    $expected = [];
    $reasons = $this->webformNodeUninstallValidator
      ->validate($module);
    $this
      ->assertEquals($expected, $reasons);
  }

  /**
   * @covers ::validate
   */
  public function testValidateEntityQueryWithoutResults() {
    $this->webformNodeUninstallValidator
      ->expects($this
      ->once())
      ->method('hasWebformNodes')
      ->willReturn(FALSE);
    $module = 'webform_node';
    $expected = [];
    $reasons = $this->webformNodeUninstallValidator
      ->validate($module);
    $this
      ->assertEquals($expected, $reasons);
  }

  /**
   * @covers ::validate
   */
  public function testValidateEntityQueryWithResults() {
    $this->webformNodeUninstallValidator
      ->expects($this
      ->once())
      ->method('hasWebformNodes')
      ->willReturn(TRUE);
    $module = 'webform_node';
    $expected = [
      'To uninstall Webform node, delete all content that has the Webform content type.',
    ];
    $reasons = $this->webformNodeUninstallValidator
      ->validate($module);
    $this
      ->assertEquals($expected, $reasons);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
WebformNodeUninstallValidatorTest::$webformNodeUninstallValidator protected property A mock webform node uninstall validator.
WebformNodeUninstallValidatorTest::setUp protected function Overrides UnitTestCase::setUp
WebformNodeUninstallValidatorTest::testValidateEntityQueryWithoutResults public function @covers ::validate
WebformNodeUninstallValidatorTest::testValidateEntityQueryWithResults public function @covers ::validate
WebformNodeUninstallValidatorTest::testValidateNotWebformNode public function @covers ::validate