ConfigUpdateTest.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. namespace Drupal\config_update_ui\Tests;
  3. use Drupal\simpletest\WebTestBase;
  4. /**
  5. * Verify the config revert report and its links.
  6. *
  7. * @group config
  8. */
  9. class ConfigUpdateTest extends WebTestBase {
  10. /**
  11. * Modules to enable.
  12. *
  13. * Use the Search module because it has two included config items in its
  14. * config/install, assuming node and user are also enabled.
  15. *
  16. * @var array.
  17. */
  18. public static $modules = ['config', 'config_update', 'config_update_ui', 'search', 'node', 'user', 'block', 'text', 'field', 'filter'];
  19. /**
  20. * The admin user that will be created.
  21. */
  22. protected $adminUser;
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function setUp() {
  27. parent::setUp();
  28. // Create user and log in.
  29. $this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer search', 'view config updates report', 'synchronize configuration', 'export configuration', 'import configuration', 'revert configuration', 'delete configuration']);
  30. $this->drupalLogin($this->adminUser);
  31. // Make sure local tasks and page title are showing.
  32. $this->drupalPlaceBlock('local_tasks_block');
  33. $this->drupalPlaceBlock('page_title_block');
  34. }
  35. /**
  36. * Tests the config report and its linked pages.
  37. */
  38. public function testConfigReport() {
  39. // Test links to report page.
  40. $this->drupalGet('admin/config/development/configuration');
  41. $this->clickLink('Updates report');
  42. $this->assertNoReport();
  43. // Verify some empty reports.
  44. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  45. $this->assertReport('Search page', [], [], [], []);
  46. // Module, theme, and profile reports have no 'added' section.
  47. $this->drupalGet('admin/config/development/configuration/report/module/search');
  48. $this->assertReport('Search module', [], [], [], [], ['added']);
  49. $this->drupalGet('admin/config/development/configuration/report/theme/classy');
  50. $this->assertReport('Classy theme', [], [], [], [], ['added']);
  51. $inactive = ['locale.settings' => 'Simple configuration'];
  52. $this->drupalGet('admin/config/development/configuration/report/profile');
  53. $this->assertReport('Testing profile', [], [], [], $inactive, ['added']);
  54. // Delete the user search page from the search UI and verify report for
  55. // both the search page config type and user module.
  56. $this->drupalGet('admin/config/search/pages');
  57. $this->clickLink('Delete');
  58. $this->drupalPostForm(NULL, [], 'Delete');
  59. $inactive = ['search.page.user_search' => 'Users'];
  60. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  61. $this->assertReport('Search page', [], [], [], $inactive);
  62. $this->drupalGet('admin/config/development/configuration/report/module/user');
  63. $this->assertReport('User module', [], [], [], $inactive, ['added', 'changed']);
  64. // Use the import link to get it back. Do this from the search page
  65. // report to make sure we are importing the right config.
  66. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  67. $this->clickLink('Import from source');
  68. $this->assertText('The configuration was imported');
  69. $this->assertNoReport();
  70. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  71. $this->assertReport('Search page', [], [], [], []);
  72. // Edit the node search page from the search UI and verify report.
  73. $this->drupalGet('admin/config/search/pages');
  74. $this->clickLink('Edit');
  75. $this->drupalPostForm(NULL, [
  76. 'label' => 'New label',
  77. 'path' => 'new_path',
  78. ], 'Save search page');
  79. $changed = ['search.page.node_search' => 'New label'];
  80. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  81. $this->assertReport('Search page', [], [], $changed, []);
  82. // Test the show differences link.
  83. $this->clickLink('Show differences');
  84. $this->assertText('Content');
  85. $this->assertText('New label');
  86. $this->assertText('node');
  87. $this->assertText('new_path');
  88. // Test the Back link.
  89. $this->clickLink("Back to 'Updates report' page.");
  90. $this->assertNoReport();
  91. // Test the export link.
  92. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  93. $this->clickLink('Export');
  94. $this->assertText('Here is your configuration:');
  95. $this->assertText('id: node_search');
  96. $this->assertText('New label');
  97. $this->assertText('path: new_path');
  98. $this->assertText('search.page.node_search.yml');
  99. // Test reverting.
  100. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  101. $this->clickLink('Revert to source');
  102. $this->assertText('Are you sure you want to revert');
  103. $this->assertText('Search page');
  104. $this->assertText('node_search');
  105. $this->assertText('Customizations will be lost. This action cannot be undone');
  106. $this->drupalPostForm(NULL, [], 'Revert');
  107. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  108. $this->assertReport('Search page', [], [], [], []);
  109. // Add a new search page from the search UI and verify report.
  110. $this->drupalPostForm('admin/config/search/pages', [
  111. 'search_type' => 'node_search',
  112. ], 'Add new page');
  113. $this->drupalPostForm(NULL, [
  114. 'label' => 'test',
  115. 'id' => 'test',
  116. 'path' => 'test',
  117. ], 'Add search page');
  118. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  119. $added = ['search.page.test' => 'test'];
  120. $this->assertReport('Search page', [], $added, [], []);
  121. // Test the export link.
  122. $this->clickLink('Export');
  123. $this->assertText('Here is your configuration:');
  124. $this->assertText('id: test');
  125. $this->assertText('label: test');
  126. $this->assertText('path: test');
  127. $this->assertText('search.page.test.yml');
  128. // Test the delete link.
  129. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  130. $this->clickLink('Delete');
  131. $this->assertText('Are you sure');
  132. $this->assertText('cannot be undone');
  133. $this->drupalPostForm(NULL, [], 'Delete');
  134. $this->assertText('The configuration was deleted');
  135. // And verify the report again.
  136. $this->drupalGet('admin/config/development/configuration/report/type/search_page');
  137. $this->assertReport('Search page', [], [], [], []);
  138. // Change the search module config and verify the actions work for
  139. // simple config.
  140. $this->drupalPostForm('admin/config/search/pages', [
  141. 'minimum_word_size' => 4,
  142. ], 'Save configuration');
  143. $changed = ['search.settings' => 'search.settings'];
  144. $this->drupalGet('admin/config/development/configuration/report/module/search');
  145. $this->assertReport('Search module', [], [], $changed, [], ['added']);
  146. $this->clickLink('Show differences');
  147. $this->assertText('Config difference for Simple configuration search.settings');
  148. $this->assertText('index::minimum_word_size');
  149. $this->assertText('4');
  150. $this->drupalGet('admin/config/development/configuration/report/module/search');
  151. $this->clickLink('Export');
  152. $this->assertText('minimum_word_size: 4');
  153. $this->drupalGet('admin/config/development/configuration/report/module/search');
  154. $this->clickLink('Revert to source');
  155. $this->drupalPostForm(NULL, [], 'Revert');
  156. $this->drupalGet('admin/config/development/configuration/report/module/search');
  157. $this->assertReport('Search module', [], [], [], [], ['added']);
  158. }
  159. /**
  160. * Asserts that the report page has the correct content.
  161. *
  162. * Assumes you are already on the report page.
  163. *
  164. * @param string $title
  165. * Report title to check for.
  166. * @param string[] $missing
  167. * Array of items that should be listed as missing, name => label.
  168. * @param string[] $added
  169. * Array of items that should be listed as missing, name => label.
  170. * @param string[] $changed
  171. * Array of items that should be listed as changed, name => label.
  172. * @param string[] $inactive
  173. * Array of items that should be listed as inactive, name => label.
  174. * @param string[] $skip
  175. * Array of report sections to skip checking.
  176. */
  177. protected function assertReport($title, $missing, $added, $changed, $inactive, $skip = []) {
  178. $this->assertText('Configuration updates report for ' . $title);
  179. $this->assertText('Generate new report');
  180. if (!in_array('missing', $skip)) {
  181. $this->assertText('Missing configuration items');
  182. if (count($missing)) {
  183. foreach ($missing as $name => $label) {
  184. $this->assertText($name);
  185. $this->assertText($label);
  186. }
  187. $this->assertNoText('None: all provided configuration items are in your active configuration.');
  188. }
  189. else {
  190. $this->assertText('None: all provided configuration items are in your active configuration.');
  191. }
  192. }
  193. if (!in_array('inactive', $skip)) {
  194. $this->assertText('Inactive optional items');
  195. if (count($inactive)) {
  196. foreach ($inactive as $name => $label) {
  197. $this->assertText($name);
  198. $this->assertText($label);
  199. }
  200. $this->assertNoText('None: all optional configuration items are in your active configuration.');
  201. }
  202. else {
  203. $this->assertText('None: all optional configuration items are in your active configuration.');
  204. }
  205. }
  206. if (!in_array('added', $skip)) {
  207. $this->assertText('Added configuration items');
  208. if (count($added)) {
  209. foreach ($added as $name => $label) {
  210. $this->assertText($name);
  211. $this->assertText($label);
  212. }
  213. $this->assertNoText('None: all active configuration items of this type were provided by modules, themes, or install profile.');
  214. }
  215. else {
  216. $this->assertText('None: all active configuration items of this type were provided by modules, themes, or install profile.');
  217. }
  218. }
  219. if (!in_array('changed', $skip)) {
  220. $this->assertText('Changed configuration items');
  221. if (count($changed)) {
  222. foreach ($changed as $name => $label) {
  223. $this->assertText($name);
  224. $this->assertText($label);
  225. }
  226. $this->assertNoText('None: no active configuration items differ from their current provided versions.');
  227. }
  228. else {
  229. $this->assertText('None: no active configuration items differ from their current provided versions.');
  230. }
  231. }
  232. }
  233. /**
  234. * Asserts that the report is not shown.
  235. *
  236. * Assumes you are already on the report form page.
  237. */
  238. protected function assertNoReport() {
  239. $this->assertText('Report type');
  240. $this->assertText('Configuration type');
  241. $this->assertText('Module');
  242. $this->assertText('Theme');
  243. $this->assertText('Installation profile');
  244. $this->assertText('Updates report');
  245. $this->assertNoText('Missing configuration items');
  246. $this->assertNoText('Added configuration items');
  247. $this->assertNoText('Changed configuration items');
  248. $this->assertNoText('Unchanged configuration items');
  249. }
  250. }