@@ -25,141 +25,105 @@ protected function setDatabaseDumpFiles() {
2525 *
2626 * @see block_content_update_8600
2727 * @see block_content_update_8601
28- *
29- * @throws \Behat\Mink\Exception\ExpectationException
30- * @throws \Behat\Mink\Exception\ResponseTextException
3128 */
3229 public function testReusableFieldAddition () {
3330 $ assert_session = $ this ->assertSession ();
34- $ page = $ this ->getSession ()->getPage ();
3531 $ entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager ();
3632
37- /* require_once $this->root . '/core/includes/install.inc';
38- require_once $this->root . '/core/includes/update.inc';
39-
40- drupal_load_updates();
41- update_fix_compatibility();
42-
43- $context = [
44- 'sandbox' => [
45- '#finished' => 1,
46- ],
47- ];
48- update_do_one('system', 8501, [], $context);
49- print_r($context);
50- $context = [
51- 'sandbox' => [
52- '#finished' => 1,
53- ],
54- ];
55- update_do_one('block_content', 8400, [], $context);
56- print_r($context);*/
57-
58- /** @var \Drupal\block_content\Entity\BlockContent $pre_block_1 */
59- $ pre_block_1 = BlockContent::create ([
60- 'info ' => 'Previous block1 ' ,
61- 'type ' => 'basic_block ' ,
62- ]);
63- $ pre_block_1 ->save ();
64-
65-
66- /** @var \Drupal\block_content\Entity\BlockContent $pre_block_2 */
67- $ pre_block_2 = BlockContent::create ([
68- 'info ' => 'Previous block2 ' ,
69- 'type ' => 'basic_block ' ,
70- ]);
71- $ pre_block_2 ->save ();
72-
7333 // Delete custom block library view.
7434 View::load ('block_content ' )->delete ();
75- // Install the test module with the 'block_content' view with another
76- // display with overridden filters.
35+ // Install the test module with the 'block_content' view with an extra
36+ // display with overridden filters. This extra display should also have a
37+ // filter added for 'reusable' field so that it does not expose non-reusable
38+ // fields. This display also a filter only show blocks that contain
39+ // 'block2' in the 'info' field.
7740 $ this ->container ->get ('module_installer ' )->install (['block_content_view_override ' ]);
7841
79-
80- $ admin_user = $ this ->drupalCreateUser (['administer blocks ' ]);
81- $ this ->drupalLogin ($ admin_user );
82-
83- // Ensure the standard Custom Block view shows the reusable blocks but not
84- // the non-reusable block.
85- $ this ->drupalGet ('admin/structure/block/block-content ' );
86- $ assert_session ->statusCodeEquals ('200 ' );
87- $ assert_session ->responseContains ('view-id-block_content ' );
88- $ assert_session ->pageTextContains ($ pre_block_1 ->label ());
89- $ assert_session ->pageTextContains ($ pre_block_2 ->label ());
90-
91- // Ensure the standard Custom Block view shows the reusable blocks but not
92- // the non-reusable block.
93- $ this ->drupalGet ('blocks-override ' );
94- $ assert_session ->statusCodeEquals ('200 ' );
95- $ assert_session ->responseContains ('view-id-block_content ' );
96- $ assert_session ->pageTextNotContains ($ pre_block_1 ->label ());
97- $ assert_session ->pageTextContains ($ pre_block_2 ->label ());
98-
99-
10042 // Run updates.
10143 $ this ->runUpdates ();
10244
103- // Check that the field exists and has the correct label .
45+ // Check that the field exists and is configured correctly .
10446 $ reusable_field = $ entity_definition_update_manager ->getFieldStorageDefinition ('reusable ' , 'block_content ' );
10547 $ this ->assertEquals ('Reusable ' , $ reusable_field ->getLabel ());
48+ $ this ->assertEquals ('A boolean indicating whether this block is reusable. ' , $ reusable_field ->getDescription ());
49+ $ this ->assertEquals (FALSE , $ reusable_field ->isRevisionable ());
50+ $ this ->assertEquals (FALSE , $ reusable_field ->isTranslatable ());
10651
107- $ storage = $ this ->container ->get ('entity_type.manager ' )->getStorage ('block_content ' );
108-
109- $ pre_block_1 = $ storage ->load ($ pre_block_1 ->id ());
110-
111- $ this ->assertEquals (TRUE , $ pre_block_1 ->isReusable ());
112-
113- $ after_block = BlockContent::create ([
114- 'info ' => 'After update block ' ,
52+ $ after_block1 = BlockContent::create ([
53+ 'info ' => 'After update block1 ' ,
11554 'type ' => 'basic_block ' ,
11655 ]);
117- $ after_block ->save ();
118-
119- /** @var \Drupal\block_content\Entity\BlockContent $after_block */
120- $ after_block = $ storage ->load ($ after_block ->id ());
56+ $ after_block1 ->save ();
57+ // Add second block that will be shown with the 'info' filter on the
58+ // additional view display.
59+ $ after_block2 = BlockContent::create ([
60+ 'info ' => 'After update block2 ' ,
61+ 'type ' => 'basic_block ' ,
62+ ]);
63+ $ after_block2 ->save ();
12164
122- $ this ->assertEquals (TRUE , $ after_block ->isReusable ());
65+ $ this ->assertEquals (TRUE , $ after_block1 ->isReusable ());
66+ $ this ->assertEquals (TRUE , $ after_block2 ->isReusable ());
12367
12468 $ non_reusable_block = BlockContent::create ([
125- 'info ' => 'non-reusable block ' ,
69+ 'info ' => 'non-reusable block1 ' ,
12670 'type ' => 'basic_block ' ,
12771 'reusable ' => FALSE ,
12872 ]);
12973 $ non_reusable_block ->save ();
130-
74+ // Add second block that will be would shown with the 'info' filter on the
75+ // additional view display if the 'reusable filter was not added.
76+ $ non_reusable_block2 = BlockContent::create ([
77+ 'info ' => 'non-reusable block2 ' ,
78+ 'type ' => 'basic_block ' ,
79+ 'reusable ' => FALSE ,
80+ ]);
81+ $ non_reusable_block2 ->save ();
13182 $ this ->assertEquals (FALSE , $ non_reusable_block ->isReusable ());
83+ $ this ->assertEquals (FALSE , $ non_reusable_block2 ->isReusable ());
84+
85+ $ admin_user = $ this ->drupalCreateUser (['administer blocks ' ]);
86+ $ this ->drupalLogin ($ admin_user );
13287
133- // Ensure the standard Custom Block view shows the reusable blocks but not
88+ // Ensure the Custom Block view shows the reusable blocks but not
13489 // the non-reusable block.
13590 $ this ->drupalGet ('admin/structure/block/block-content ' );
13691 $ assert_session ->statusCodeEquals ('200 ' );
13792 $ assert_session ->responseContains ('view-id-block_content ' );
138- $ assert_session ->pageTextContains ($ pre_block_1 ->label ());
139- $ assert_session ->pageTextContains ($ after_block ->label ());
93+ $ assert_session ->pageTextContains ($ after_block1 ->label ());
94+ $ assert_session ->pageTextContains ($ after_block2 ->label ());
14095 $ assert_session ->pageTextNotContains ($ non_reusable_block ->label ());
96+ $ assert_session ->pageTextNotContains ($ non_reusable_block2 ->label ());
14197
142- // Ensure that reusable blocks edit form edit route is accessible.
143- $ this ->drupalGet ('block/ ' . $ pre_block_1 ->id ());
98+ // Ensure the views other display also filters out non-reusable blocks and
99+ // still filters on the 'info' field.
100+ $ this ->drupalGet ('extra-view-display ' );
144101 $ assert_session ->statusCodeEquals ('200 ' );
145- $ this ->drupalGet ('block/ ' . $ after_block ->id ());
102+ $ assert_session ->responseContains ('view-id-block_content ' );
103+ $ assert_session ->pageTextNotContains ($ after_block1 ->label ());
104+ $ assert_session ->pageTextContains ($ after_block2 ->label ());
105+ $ assert_session ->pageTextNotContains ($ non_reusable_block ->label ());
106+ $ assert_session ->pageTextNotContains ($ non_reusable_block2 ->label ());
107+
108+ $ this ->drupalGet ('block/ ' . $ after_block1 ->id ());
146109 $ assert_session ->statusCodeEquals ('200 ' );
147110
148111 // Ensure that non-reusable blocks edit form edit route is not accessible.
149112 $ this ->drupalGet ('block/ ' . $ non_reusable_block ->id ());
150113 $ assert_session ->statusCodeEquals ('403 ' );
151114
152115 // Ensure the Custom Block listing without Views installed shows the
153- // reusable blocks but not the non-reusable block .
116+ // reusable blocks but not the non-reusable blocks .
154117 // the non-reusable block.
155118 $ this ->drupalGet ('admin/structure/block/block-content ' );
156119 $ this ->container ->get ('module_installer ' )->uninstall (['views_ui ' , 'views ' ]);
157120 $ this ->drupalGet ('admin/structure/block/block-content ' );
158121 $ assert_session ->statusCodeEquals ('200 ' );
159122 $ assert_session ->responseNotContains ('view-id-block_content ' );
160- $ assert_session ->pageTextContains ($ pre_block_1 ->label ());
161- $ assert_session ->pageTextContains ($ after_block ->label ());
123+ $ assert_session ->pageTextContains ($ after_block1 ->label ());
124+ $ assert_session ->pageTextContains ($ after_block2 ->label ());
162125 $ assert_session ->pageTextNotContains ($ non_reusable_block ->label ());
126+ $ assert_session ->pageTextNotContains ($ non_reusable_block2 ->label ());
163127 }
164128
165129}
0 commit comments