3 namespace Drupal\Tests\forum\Unit;
5 use Drupal\simpletest\AssertHelperTrait;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\forum\ForumUninstallValidator
12 class ForumUninstallValidatorTest extends UnitTestCase {
14 use AssertHelperTrait;
17 * @var \Drupal\forum\ForumUninstallValidator|\PHPUnit_Framework_MockObject_MockObject
19 protected $forumUninstallValidator;
24 protected function setUp() {
26 $this->forumUninstallValidator = $this->getMockBuilder('Drupal\forum\ForumUninstallValidator')
27 ->disableOriginalConstructor()
28 ->setMethods(['hasForumNodes', 'hasTermsForVocabulary', 'getForumVocabulary'])
30 $this->forumUninstallValidator->setStringTranslation($this->getStringTranslationStub());
36 public function testValidateNotForum() {
37 $this->forumUninstallValidator->expects($this->never())
38 ->method('hasForumNodes');
39 $this->forumUninstallValidator->expects($this->never())
40 ->method('hasTermsForVocabulary');
41 $this->forumUninstallValidator->expects($this->never())
42 ->method('getForumVocabulary');
44 $module = 'not_forum';
46 $reasons = $this->forumUninstallValidator->validate($module);
47 $this->assertSame($expected, $this->castSafeStrings($reasons));
53 public function testValidate() {
54 $this->forumUninstallValidator->expects($this->once())
55 ->method('hasForumNodes')
58 $vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
59 $this->forumUninstallValidator->expects($this->once())
60 ->method('getForumVocabulary')
61 ->willReturn($vocabulary);
63 $this->forumUninstallValidator->expects($this->once())
64 ->method('hasTermsForVocabulary')
69 $reasons = $this->forumUninstallValidator->validate($module);
70 $this->assertSame($expected, $this->castSafeStrings($reasons));
76 public function testValidateHasForumNodes() {
77 $this->forumUninstallValidator->expects($this->once())
78 ->method('hasForumNodes')
81 $vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
82 $this->forumUninstallValidator->expects($this->once())
83 ->method('getForumVocabulary')
84 ->willReturn($vocabulary);
86 $this->forumUninstallValidator->expects($this->once())
87 ->method('hasTermsForVocabulary')
92 'To uninstall Forum, first delete all <em>Forum</em> content',
94 $reasons = $this->forumUninstallValidator->validate($module);
95 $this->assertSame($expected, $this->castSafeStrings($reasons));
101 public function testValidateHasTermsForVocabularyWithNodesAccess() {
102 $this->forumUninstallValidator->expects($this->once())
103 ->method('hasForumNodes')
106 $vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
107 $vocabulary->expects($this->once())
109 ->willReturn('Vocabulary label');
110 $vocabulary->expects($this->once())
112 ->willReturn('/path/to/vocabulary/overview');
113 $vocabulary->expects($this->once())
116 $this->forumUninstallValidator->expects($this->once())
117 ->method('getForumVocabulary')
118 ->willReturn($vocabulary);
120 $this->forumUninstallValidator->expects($this->once())
121 ->method('hasTermsForVocabulary')
126 'To uninstall Forum, first delete all <em>Forum</em> content',
127 'To uninstall Forum, first delete all <a href="/path/to/vocabulary/overview"><em class="placeholder">Vocabulary label</em></a> terms',
129 $reasons = $this->forumUninstallValidator->validate($module);
130 $this->assertSame($expected, $this->castSafeStrings($reasons));
136 public function testValidateHasTermsForVocabularyWithNodesNoAccess() {
137 $this->forumUninstallValidator->expects($this->once())
138 ->method('hasForumNodes')
141 $vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
142 $vocabulary->expects($this->once())
144 ->willReturn('Vocabulary label');
145 $vocabulary->expects($this->never())
147 $vocabulary->expects($this->once())
150 $this->forumUninstallValidator->expects($this->once())
151 ->method('getForumVocabulary')
152 ->willReturn($vocabulary);
154 $this->forumUninstallValidator->expects($this->once())
155 ->method('hasTermsForVocabulary')
160 'To uninstall Forum, first delete all <em>Forum</em> content',
161 'To uninstall Forum, first delete all <em class="placeholder">Vocabulary label</em> terms',
163 $reasons = $this->forumUninstallValidator->validate($module);
164 $this->assertSame($expected, $this->castSafeStrings($reasons));
170 public function testValidateHasTermsForVocabularyAccess() {
171 $this->forumUninstallValidator->expects($this->once())
172 ->method('hasForumNodes')
175 $vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
176 $vocabulary->expects($this->once())
178 ->willReturn('/path/to/vocabulary/overview');
179 $vocabulary->expects($this->once())
181 ->willReturn('Vocabulary label');
182 $vocabulary->expects($this->once())
185 $this->forumUninstallValidator->expects($this->once())
186 ->method('getForumVocabulary')
187 ->willReturn($vocabulary);
189 $this->forumUninstallValidator->expects($this->once())
190 ->method('hasTermsForVocabulary')
195 'To uninstall Forum, first delete all <a href="/path/to/vocabulary/overview"><em class="placeholder">Vocabulary label</em></a> terms',
197 $reasons = $this->forumUninstallValidator->validate($module);
198 $this->assertSame($expected, $this->castSafeStrings($reasons));
204 public function testValidateHasTermsForVocabularyNoAccess() {
205 $this->forumUninstallValidator->expects($this->once())
206 ->method('hasForumNodes')
209 $vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
210 $vocabulary->expects($this->once())
212 ->willReturn('Vocabulary label');
213 $vocabulary->expects($this->never())
215 $vocabulary->expects($this->once())
218 $this->forumUninstallValidator->expects($this->once())
219 ->method('getForumVocabulary')
220 ->willReturn($vocabulary);
222 $this->forumUninstallValidator->expects($this->once())
223 ->method('hasTermsForVocabulary')
228 'To uninstall Forum, first delete all <em class="placeholder">Vocabulary label</em> terms',
230 $reasons = $this->forumUninstallValidator->validate($module);
231 $this->assertSame($expected, $this->castSafeStrings($reasons));