More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Extension / RequiredModuleUninstallValidatorTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Extension;
4
5 use Drupal\simpletest\AssertHelperTrait;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * @coversDefaultClass \Drupal\Core\Extension\RequiredModuleUninstallValidator
10  * @group Extension
11  */
12 class RequiredModuleUninstallValidatorTest extends UnitTestCase {
13
14   use AssertHelperTrait;
15
16   /**
17    * @var \Drupal\Core\Extension\RequiredModuleUninstallValidator|\PHPUnit_Framework_MockObject_MockObject
18    */
19   protected $uninstallValidator;
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26     $this->uninstallValidator = $this->getMockBuilder('Drupal\Core\Extension\RequiredModuleUninstallValidator')
27       ->disableOriginalConstructor()
28       ->setMethods(['getModuleInfoByModule'])
29       ->getMock();
30     $this->uninstallValidator->setStringTranslation($this->getStringTranslationStub());
31   }
32
33   /**
34    * @covers ::validate
35    */
36   public function testValidateNoModule() {
37     $this->uninstallValidator->expects($this->once())
38       ->method('getModuleInfoByModule')
39       ->willReturn([]);
40
41     $module = $this->randomMachineName();
42     $expected = [];
43     $reasons = $this->uninstallValidator->validate($module);
44     $this->assertSame($expected, $reasons);
45   }
46
47   /**
48    * @covers ::validate
49    */
50   public function testValidateNotRequired() {
51     $module = $this->randomMachineName();
52
53     $this->uninstallValidator->expects($this->once())
54       ->method('getModuleInfoByModule')
55       ->willReturn(['required' => FALSE, 'name' => $module]);
56
57     $expected = [];
58     $reasons = $this->uninstallValidator->validate($module);
59     $this->assertSame($expected, $reasons);
60   }
61
62   /**
63    * @covers ::validate
64    */
65   public function testValidateRequired() {
66     $module = $this->randomMachineName();
67
68     $this->uninstallValidator->expects($this->once())
69       ->method('getModuleInfoByModule')
70       ->willReturn(['required' => TRUE, 'name' => $module]);
71
72     $expected = ["The $module module is required"];
73     $reasons = $this->uninstallValidator->validate($module);
74     $this->assertSame($expected, $this->castSafeStrings($reasons));
75   }
76
77 }