More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / modules / book / tests / src / Unit / BookUninstallValidatorTest.php
1 <?php
2
3 namespace Drupal\Tests\book\Unit;
4
5 use Drupal\simpletest\AssertHelperTrait;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * @coversDefaultClass \Drupal\book\BookUninstallValidator
10  * @group book
11  */
12 class BookUninstallValidatorTest extends UnitTestCase {
13
14   use AssertHelperTrait;
15
16   /**
17    * @var \Drupal\book\BookUninstallValidator|\PHPUnit_Framework_MockObject_MockObject
18    */
19   protected $bookUninstallValidator;
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26     $this->bookUninstallValidator = $this->getMockBuilder('Drupal\book\BookUninstallValidator')
27       ->disableOriginalConstructor()
28       ->setMethods(['hasBookOutlines', 'hasBookNodes'])
29       ->getMock();
30     $this->bookUninstallValidator->setStringTranslation($this->getStringTranslationStub());
31   }
32
33   /**
34    * @covers ::validate
35    */
36   public function testValidateNotBook() {
37     $this->bookUninstallValidator->expects($this->never())
38       ->method('hasBookOutlines');
39     $this->bookUninstallValidator->expects($this->never())
40       ->method('hasBookNodes');
41
42     $module = 'not_book';
43     $expected = [];
44     $reasons = $this->bookUninstallValidator->validate($module);
45     $this->assertSame($expected, $this->castSafeStrings($reasons));
46   }
47
48   /**
49    * @covers ::validate
50    */
51   public function testValidateEntityQueryWithoutResults() {
52     $this->bookUninstallValidator->expects($this->once())
53       ->method('hasBookOutlines')
54       ->willReturn(FALSE);
55     $this->bookUninstallValidator->expects($this->once())
56       ->method('hasBookNodes')
57       ->willReturn(FALSE);
58
59     $module = 'book';
60     $expected = [];
61     $reasons = $this->bookUninstallValidator->validate($module);
62     $this->assertSame($expected, $this->castSafeStrings($reasons));
63   }
64
65   /**
66    * @covers ::validate
67    */
68   public function testValidateEntityQueryWithResults() {
69     $this->bookUninstallValidator->expects($this->once())
70       ->method('hasBookOutlines')
71       ->willReturn(FALSE);
72     $this->bookUninstallValidator->expects($this->once())
73       ->method('hasBookNodes')
74       ->willReturn(TRUE);
75
76     $module = 'book';
77     $expected = ['To uninstall Book, delete all content that has the Book content type'];
78     $reasons = $this->bookUninstallValidator->validate($module);
79     $this->assertSame($expected, $this->castSafeStrings($reasons));
80   }
81
82   /**
83    * @covers ::validate
84    */
85   public function testValidateOutlineStorage() {
86     $this->bookUninstallValidator->expects($this->once())
87       ->method('hasBookOutlines')
88       ->willReturn(TRUE);
89     $this->bookUninstallValidator->expects($this->never())
90       ->method('hasBookNodes');
91
92     $module = 'book';
93     $expected = ['To uninstall Book, delete all content that is part of a book'];
94     $reasons = $this->bookUninstallValidator->validate($module);
95     $this->assertSame($expected, $this->castSafeStrings($reasons));
96   }
97
98 }