Mercurial > hg > isophonics-drupal-site
comparison core/modules/comment/tests/src/Functional/CommentUninstallTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\comment\Functional; | |
4 | |
5 use Drupal\comment\Tests\CommentTestTrait; | |
6 use Drupal\field\Entity\FieldStorageConfig; | |
7 use Drupal\Core\Extension\ModuleUninstallValidatorException; | |
8 use Drupal\Tests\BrowserTestBase; | |
9 | |
10 /** | |
11 * Tests comment module uninstallation. | |
12 * | |
13 * @group comment | |
14 */ | |
15 class CommentUninstallTest extends BrowserTestBase { | |
16 | |
17 use CommentTestTrait; | |
18 | |
19 /** | |
20 * Modules to install. | |
21 * | |
22 * @var array | |
23 */ | |
24 public static $modules = ['comment', 'node']; | |
25 | |
26 protected function setUp() { | |
27 parent::setup(); | |
28 | |
29 // Create an article content type. | |
30 $this->drupalCreateContentType(['type' => 'article', 'name' => t('Article')]); | |
31 // Create comment field on article so that adds 'comment_body' field. | |
32 $this->addDefaultCommentField('node', 'article'); | |
33 } | |
34 | |
35 /** | |
36 * Tests if comment module uninstallation fails if the field exists. | |
37 * | |
38 * @throws \Drupal\Core\Extension\ModuleUninstallValidatorException | |
39 */ | |
40 public function testCommentUninstallWithField() { | |
41 // Ensure that the field exists before uninstallation. | |
42 $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); | |
43 $this->assertNotNull($field_storage, 'The comment_body field exists.'); | |
44 | |
45 // Uninstall the comment module which should trigger an exception. | |
46 try { | |
47 $this->container->get('module_installer')->uninstall(['comment']); | |
48 $this->fail("Expected an exception when uninstall was attempted."); | |
49 } | |
50 catch (ModuleUninstallValidatorException $e) { | |
51 $this->pass("Caught an exception when uninstall was attempted."); | |
52 } | |
53 } | |
54 | |
55 | |
56 /** | |
57 * Tests if uninstallation succeeds if the field has been deleted beforehand. | |
58 */ | |
59 public function testCommentUninstallWithoutField() { | |
60 // Manually delete the comment_body field before module uninstallation. | |
61 $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); | |
62 $this->assertNotNull($field_storage, 'The comment_body field exists.'); | |
63 $field_storage->delete(); | |
64 | |
65 // Check that the field is now deleted. | |
66 $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); | |
67 $this->assertNull($field_storage, 'The comment_body field has been deleted.'); | |
68 | |
69 // Manually delete the comment field on the node before module uninstallation. | |
70 $field_storage = FieldStorageConfig::loadByName('node', 'comment'); | |
71 $this->assertNotNull($field_storage, 'The comment field exists.'); | |
72 $field_storage->delete(); | |
73 | |
74 // Check that the field is now deleted. | |
75 $field_storage = FieldStorageConfig::loadByName('node', 'comment'); | |
76 $this->assertNull($field_storage, 'The comment field has been deleted.'); | |
77 | |
78 field_purge_batch(10); | |
79 // Ensure that uninstallation succeeds even if the field has already been | |
80 // deleted manually beforehand. | |
81 $this->container->get('module_installer')->uninstall(['comment']); | |
82 } | |
83 | |
84 } |