diff --git a/panelizer.post_update.php b/panelizer.post_update.php index 4149ff0..fcb8e18 100644 --- a/panelizer.post_update.php +++ b/panelizer.post_update.php @@ -27,7 +27,7 @@ function panelizer_post_update_rename_layout_machine_names(&$sandbox) { $results = []; // Update overridden panelizer entities. foreach ($panelizer_manager->getDefinitions() as $entity_type => $definition) { - if (db_table_exists($entity_type . '__panelizer')) { + if (\Drupal::database()->schema()->tableExists($entity_type . '__panelizer')) { $storage = \Drupal::entityTypeManager()->getStorage($entity_type); $ids = $storage->getQuery() ->condition('panelizer', serialize([]), '<>') diff --git a/panelizer_quickedit/tests/src/FunctionalJavascript/PanelizerQuickEditTest.php b/panelizer_quickedit/tests/src/FunctionalJavascript/PanelizerQuickEditTest.php index 005668a..8bddec5 100644 --- a/panelizer_quickedit/tests/src/FunctionalJavascript/PanelizerQuickEditTest.php +++ b/panelizer_quickedit/tests/src/FunctionalJavascript/PanelizerQuickEditTest.php @@ -4,14 +4,14 @@ namespace Drupal\Tests\panelizer_quickedit\FunctionalJavascript; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; -use Drupal\FunctionalJavascriptTests\JavascriptTestBase; +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; /** * Tests that a Panelized Node can be Quick-Edited. * * @group panelizer */ -class PanelizerQuickEditTest extends JavascriptTestBase { +class PanelizerQuickEditTest extends WebDriverTestBase { /** * {@inheritdoc} @@ -69,12 +69,12 @@ class PanelizerQuickEditTest extends JavascriptTestBase { // Enable Panelizer for Articles. $this->drupalGet('admin/structure/types/manage/page/display'); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $edit = [ 'panelizer[enable]' => TRUE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); } /** @@ -107,7 +107,7 @@ class PanelizerQuickEditTest extends JavascriptTestBase { // Visit the new node. $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // This is the unique ID we append to normal Quick Edit field IDs. $panelizer_id = 'panelizer-full-block-id-' . $block_id; @@ -138,7 +138,7 @@ class PanelizerQuickEditTest extends JavascriptTestBase { // Re-visit the node to make sure the edit worked. $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('Hello world'); } diff --git a/src/Form/PanelizerWizardContextDeleteForm.php b/src/Form/PanelizerWizardContextDeleteForm.php index e4175e0..29e9bf3 100644 --- a/src/Form/PanelizerWizardContextDeleteForm.php +++ b/src/Form/PanelizerWizardContextDeleteForm.php @@ -5,12 +5,40 @@ namespace Drupal\panelizer\Form; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\ctools\Form\ContextDelete; +use Drupal\Core\Messenger\MessengerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for deleting a context. */ class PanelizerWizardContextDeleteForm extends ContextDelete { + /** + * The messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + + /** + * Constructs a new PanelizerWizardContextDeleteForm object. + * + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger service. + */ + public function __construct(MessengerInterface $messenger) { + $this->messenger = $messenger; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('messenger') + ); + } + /** * {@inheritdoc} */ @@ -45,7 +73,7 @@ class PanelizerWizardContextDeleteForm extends ContextDelete { public function submitForm(array &$form, FormStateInterface $form_state) { $cached_values = $this->getTempstore(); $context = $cached_values['contexts'][$this->context_id]; - drupal_set_message($this->t('The static context %label has been removed.', ['%label' => $context['label']])); + $this->messenger->addMessage($this->t('The static context %label has been removed.', ['%label' => $context['label']])); unset($cached_values['contexts'][$this->context_id]); $this->setTempstore($cached_values); parent::submitForm($form, $form_state); diff --git a/src/Form/PanelizerWizardContextForm.php b/src/Form/PanelizerWizardContextForm.php index 44b6da7..8fe2846 100644 --- a/src/Form/PanelizerWizardContextForm.php +++ b/src/Form/PanelizerWizardContextForm.php @@ -8,7 +8,7 @@ use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\TypedDataManagerInterface; use Drupal\ctools\Form\ManageContext; -use Drupal\user\SharedTempStoreFactory; +use Drupal\Core\TempStore\SharedTempStoreFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -35,7 +35,7 @@ class PanelizerWizardContextForm extends ManageContext { return new static( $container->get('typed_data_manager'), $container->get('form_builder'), - $container->get('user.shared_tempstore') + $container->get('tempstore.shared') ); } @@ -141,7 +141,7 @@ class PanelizerWizardContextForm extends ManageContext { $content = $this->formBuilder->getForm($this->getContextClass($cached_values), $context, $this->getTempstoreId(), $this->machine_name); $content['#attached']['library'][] = 'core/drupal.dialog.ajax'; list(, $route_parameters) = $this->getContextOperationsRouteInfo($cached_values, $this->machine_name, $context); - $content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getContextAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]); + $content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->getUrlGenerator()->generateFromRoute($this->getContextAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]); $response = new AjaxResponse(); $response->addCommand(new OpenModalDialogCommand($this->t('Add new context'), $content, ['width' => '700'])); return $response; diff --git a/src/Panelizer.php b/src/Panelizer.php index 5169bb1..b33eeb9 100644 --- a/src/Panelizer.php +++ b/src/Panelizer.php @@ -318,7 +318,7 @@ class Panelizer implements PanelizerInterface { } // Updates the changed time of the entity, if necessary. - if ($entity->getEntityType()->isSubclassOf(EntityChangedInterface::class)) { + if ($entity->getEntityType()->entityClassImplements(EntityChangedInterface::class)) { $entity->setChangedTime(REQUEST_TIME); } diff --git a/src/Tests/Update/PanelizerLayoutIDUpdateTest.php b/src/Tests/Update/PanelizerLayoutIDUpdateTest.php index f08af8e..0863401 100644 --- a/src/Tests/Update/PanelizerLayoutIDUpdateTest.php +++ b/src/Tests/Update/PanelizerLayoutIDUpdateTest.php @@ -2,7 +2,7 @@ namespace Drupal\panelizer\Tests\Update; -use Drupal\system\Tests\Update\UpdatePathTestBase; +use Drupal\FunctionalTests\Update\UpdatePathTestBase; /** * Tests the updating of Layout IDs. diff --git a/tests/src/Functional/PanelizerAddDefaultLinkTest.php b/tests/src/Functional/PanelizerAddDefaultLinkTest.php index b8fb425..2055acd 100644 --- a/tests/src/Functional/PanelizerAddDefaultLinkTest.php +++ b/tests/src/Functional/PanelizerAddDefaultLinkTest.php @@ -55,13 +55,13 @@ class PanelizerAddDefaultLinkTest extends BrowserTestBase { $this->panelize($content_type); // Confirm that the content type is now panelized. - $this->assertLink('Add a new Panelizer default display'); + $this->assertSession()->linkExists('Add a new Panelizer default display'); // Un-panelize the content type. $this->unpanelize($content_type); // Confirm that the content type is no longer panelized. - $this->assertNoLink('Add a new Panelizer default display'); + $this->assertSession()->linkNotExists('Add a new Panelizer default display'); } } diff --git a/tests/src/Functional/PanelizerDefaultsTest.php b/tests/src/Functional/PanelizerDefaultsTest.php index a147f37..b537ace 100644 --- a/tests/src/Functional/PanelizerDefaultsTest.php +++ b/tests/src/Functional/PanelizerDefaultsTest.php @@ -73,18 +73,18 @@ class PanelizerDefaultsTest extends BrowserTestBase { // to (the panelizer[allow] checkbox in the view display configuration). By // default, they aren't. $this->drupalGet('node/add/page'); - $this->assertResponse(200); - $this->assertNoFieldByName("panelizer['{$i}][default]"); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->fieldNotExists("panelizer['{$i}][default]"); // Allow user to select panelized modes in UI. $this->panelize('page', $view_mode_name, [ 'panelizer[custom]' => TRUE, 'panelizer[allow]' => TRUE, ]); $this->drupalGet('node/add/page'); - $this->assertResponse(200); - $this->assertFieldByName("panelizer[{$i}][default]"); - $this->assertOption("edit-panelizer-{$i}-default", 'default'); - $this->assertOption("edit-panelizer-{$i}-default", $panelizer_id); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->fieldNotExists("panelizer[{$i}][default]"); + $this->assertSession()->optionExists("edit-panelizer-{$i}-default", 'default'); + $this->assertSession()->optionExists("edit-panelizer-{$i}-default", $panelizer_id); // Clean up. $this->deletePanelizerDefault('page', $view_mode_name, $panelizer_id); $this->assertDefaultNotExists('page', $view_mode_name, $panelizer_id); diff --git a/tests/src/Functional/PanelizerIpeTest.php b/tests/src/Functional/PanelizerIpeTest.php index 9b04138..c500e3a 100644 --- a/tests/src/Functional/PanelizerIpeTest.php +++ b/tests/src/Functional/PanelizerIpeTest.php @@ -99,7 +99,7 @@ class PanelizerIpeTest extends BrowserTestBase { // Load the test node. $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Confirm the JSON Drupal settings are appropriate. $drupalSettings = NULL; @@ -119,9 +119,9 @@ class PanelizerIpeTest extends BrowserTestBase { $this->assertTrue(isset($drupalSettings['panelizer'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_type_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['revert'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['save_default'])); @@ -146,7 +146,7 @@ class PanelizerIpeTest extends BrowserTestBase { // Load the test node. $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Confirm the appropriate DOM structures are present for the IPE. $drupalSettings = NULL; @@ -166,9 +166,9 @@ class PanelizerIpeTest extends BrowserTestBase { $this->assertTrue(isset($drupalSettings['panelizer'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_type_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['revert'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['save_default'])); @@ -218,9 +218,9 @@ class PanelizerIpeTest extends BrowserTestBase { $this->assertTrue(isset($drupalSettings['panelizer'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_type_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['revert'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['save_default'])); @@ -273,9 +273,9 @@ class PanelizerIpeTest extends BrowserTestBase { $this->assertTrue(isset($drupalSettings['panelizer'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_type_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['revert'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['save_default'])); @@ -329,9 +329,9 @@ class PanelizerIpeTest extends BrowserTestBase { $this->assertTrue(isset($drupalSettings['panelizer'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity'])); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_type_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_type_id'], 'node'); $this->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_id'])); - $this->assertEqual($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); + $this->assertEquals($drupalSettings['panelizer']['entity']['entity_id'], $node->id()); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['revert'])); $this->assertTrue(isset($drupalSettings['panelizer']['user_permission']['save_default'])); @@ -363,12 +363,12 @@ class PanelizerIpeTest extends BrowserTestBase { // Load the test node. $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Extract the drupalSettings structure and return it. $drupalSettings = NULL; $matches = []; - if (preg_match('@@', $this->getRawContent(), $matches)) { + if (preg_match('@@', $this->getSession()->getPage()->getContent(), $matches)) { $drupalSettings = Json::decode($matches[1]); $this->verbose('
' . print_r($drupalSettings, TRUE) . '
'); } diff --git a/tests/src/Functional/PanelizerNodeFunctionalTest.php b/tests/src/Functional/PanelizerNodeFunctionalTest.php index fe57812..5182a8e 100644 --- a/tests/src/Functional/PanelizerNodeFunctionalTest.php +++ b/tests/src/Functional/PanelizerNodeFunctionalTest.php @@ -53,13 +53,13 @@ class PanelizerNodeFunctionalTest extends BrowserTestBase { public function testWizardUI() { // Enter the wizard. $this->drupalGet('admin/structure/panelizer/edit/node__page__default__default'); - $this->assertResponse(200); - $this->assertText('Wizard Information'); - $this->assertField('edit-label'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('Wizard Information'); + $this->assertSession()->fieldExists('edit-label'); // Contexts step. $this->clickLink('Contexts'); - $this->assertText('@panelizer.entity_context:entity', 'The current entity context is present.'); + $this->assertSession()->pageTextContains('@panelizer.entity_context:entity', 'The current entity context is present.'); // Layout selection step. $this->clickLink('Layout'); @@ -73,57 +73,57 @@ class PanelizerNodeFunctionalTest extends BrowserTestBase { 'region' => 'content', ]; $this->drupalPostForm(NULL, $edit, t('Add block')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Finish the wizard. $this->drupalPostForm(NULL, [], t('Update and save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Confirm this returned to the main wizard page. - $this->assertText('Wizard Information'); - $this->assertField('edit-label'); + $this->assertSession()->pageTextContains('Wizard Information'); + $this->assertSession()->fieldExists('edit-label'); // Return to the Manage Display page, which is where the Cancel button // currently sends you. That's a UX WTF and should be fixed... $this->drupalPostForm(NULL, [], t('Cancel')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Confirm the page is back to the content type settings page. - $this->assertFieldChecked('edit-panelizer-custom'); + $this->assertSession()->checkboxChecked('edit-panelizer-custom'); // Now change and save the general setting. $edit = [ 'panelizer[custom]' => FALSE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); - $this->assertNoFieldChecked('edit-panelizer-custom'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->checkboxNotChecked('edit-panelizer-custom'); // Add another block at the Content step and then save changes. $this->drupalGet('admin/structure/panelizer/edit/node__page__default__default/content'); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->clickLink('Add new block'); $this->clickLink('Body'); $edit = [ 'region' => 'content', ]; $this->drupalPostForm(NULL, $edit, t('Add block')); - $this->assertResponse(200); - $this->assertText('entity_field:node:body', 'The body block was added successfully.'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('entity_field:node:body', 'The body block was added successfully.'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->clickLink('Content'); - $this->assertText('entity_field:node:body', 'The body block was saved successfully.'); + $this->assertSession()->pageTextContains('entity_field:node:body', 'The body block was saved successfully.'); // Check that the Manage Display tab changed now that Panelizer is set up. // Also, the field display table should be hidden. - $this->assertNoRaw('
'); + $this->assertSession()->responseNotContains('
'); // Disable Panelizer for the default display mode. This should bring back // the field overview table at Manage Display and not display the link to // edit the default Panelizer layout. $this->unpanelize('page'); - $this->assertNoLinkByHref('admin/structure/panelizer/edit/node__page__default'); - $this->assertRaw('
'); + $this->assertSession()->linkByHrefNotExists('admin/structure/panelizer/edit/node__page__default'); + $this->assertSession()->responseContains('
'); } /** @@ -145,19 +145,19 @@ class PanelizerNodeFunctionalTest extends BrowserTestBase { // Create a node, and check that the IPE is visible on it. $node = $this->drupalCreateNode(['type' => 'page']); $out = $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->verbose($out); $elements = $this->xpath('//*[@id="panels-ipe-content"]'); if (is_array($elements)) { - $this->assertIdentical(count($elements), 1); + $this->assertSame(count($elements), 1); } else { $this->fail('Could not parse page content.'); } // Check that the block we added is visible. - $this->assertText('Panelizer test'); - $this->assertText('Abracadabra'); + $this->assertSession()->pageTextContains('Panelizer test'); + $this->assertSession()->pageTextContains('Abracadabra'); } } diff --git a/tests/src/Functional/PanelizerNodeTranslationsTest.php b/tests/src/Functional/PanelizerNodeTranslationsTest.php index 714f92e..a4fc23d 100644 --- a/tests/src/Functional/PanelizerNodeTranslationsTest.php +++ b/tests/src/Functional/PanelizerNodeTranslationsTest.php @@ -72,13 +72,13 @@ class PanelizerNodeTranslationsTest extends ContentTranslationTestBase { // Enter the wizard. $this->drupalGet("admin/structure/panelizer/edit/{$this->entityTypeId}__{$this->bundle}__default__default"); - $this->assertResponse(200); - $this->assertText('Wizard Information'); - $this->assertField('edit-label'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('Wizard Information'); + $this->assertSession()->buttonExists('edit-label'); // Contexts step. $this->clickLink('Contexts'); - $this->assertText('@panelizer.entity_context:entity', 'The current entity context is present.'); + $this->assertSession()->pageTextContains('@panelizer.entity_context:entity', 'The current entity context is present.'); // Layout selection step. $this->clickLink('Layout'); @@ -93,57 +93,57 @@ class PanelizerNodeTranslationsTest extends ContentTranslationTestBase { 'region' => 'content', ]; $this->drupalPostForm(NULL, $edit, t('Add block')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Finish the wizard. $this->drupalPostForm(NULL, [], t('Update and save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Confirm this returned to the main wizard page. - $this->assertText('Wizard Information'); - $this->assertField('edit-label'); + $this->assertSession()->pageTextContains('Wizard Information'); + $this->assertSession()->buttonExists('edit-label'); // Return to the Manage Display page, which is where the Cancel button // currently sends you. That's a UX WTF and should be fixed... $this->drupalPostForm(NULL, [], t('Cancel')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Confirm the page is back to the content type settings page. - $this->assertFieldChecked('edit-panelizer-custom'); + $this->assertSession()->checkboxChecked('edit-panelizer-custom'); // Now change and save the general setting. $edit = [ 'panelizer[custom]' => FALSE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); - $this->assertNoFieldChecked('edit-panelizer-custom'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->checkboxNotChecked('edit-panelizer-custom'); // Add another block at the Content step and then save changes. $this->drupalGet("admin/structure/panelizer/edit/{$this->entityTypeId}__{$this->bundle}__default__default/content"); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->clickLink('Add new block'); $this->clickLink('Body'); $edit = [ 'region' => 'content', ]; $this->drupalPostForm(NULL, $edit, t('Add block')); - $this->assertResponse(200); - $this->assertText("entity_field:{$this->entityTypeId}:body", 'The body block was added successfully.'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains("entity_field:{$this->entityTypeId}:body", 'The body block was added successfully.'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->clickLink('Content', 1); - $this->assertText("entity_field:{$this->entityTypeId}:body", 'The body block was saved successfully.'); + $this->assertSession()->pageTextContains("entity_field:{$this->entityTypeId}:body", 'The body block was saved successfully.'); // Check that the Manage Display tab changed now that Panelizer is set up. // Also, the field display table should be hidden. - $this->assertNoRaw('
'); + $this->assertSession()->responseNotContains('
'); // Disable Panelizer for the default display mode. This should bring back // the field overview table at Manage Display and not display the link to // edit the default Panelizer layout. $this->unpanelize($this->bundle); - $this->assertNoLinkByHref("admin/structure/panelizer/edit/{$this->entityTypeId}__{$this->bundle}__default"); - $this->assertRaw('
'); + $this->assertSession()->linkByHrefNotExists("admin/structure/panelizer/edit/{$this->entityTypeId}__{$this->bundle}__default"); + $this->assertSession()->responseContains('
'); } /** @@ -173,25 +173,25 @@ class PanelizerNodeTranslationsTest extends ContentTranslationTestBase { ], ]); $out = $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->verbose($out); $elements = $this->xpath('//*[@id="panels-ipe-content"]'); if (is_array($elements)) { - $this->assertIdentical(count($elements), 1); + $this->assertSame(count($elements), 1); } else { $this->fail('Could not parse page content.'); } // Check that the block we added is visible. - $this->assertText('Panelizer test'); - $this->assertText('Abracadabra'); + $this->assertSession()->pageTextContains('Panelizer test'); + $this->assertSession()->pageTextContains('Abracadabra'); // Load the translation page. $this->clickLink('Translate'); - $this->assertText('English (Original language)'); - $this->assertText('Published'); - $this->assertText('Not translated'); + $this->assertSession()->pageTextContains('English (Original language)'); + $this->assertSession()->pageTextContains('Published'); + $this->assertSession()->pageTextContains('Not translated'); } // @todo Confirm that the different languages of a translated node are loaded properly when using a default display. diff --git a/tests/src/Functional/PanelizerTermFunctionalTest.php b/tests/src/Functional/PanelizerTermFunctionalTest.php index 3467f7a..7623b01 100644 --- a/tests/src/Functional/PanelizerTermFunctionalTest.php +++ b/tests/src/Functional/PanelizerTermFunctionalTest.php @@ -63,7 +63,7 @@ class PanelizerTermFunctionalTest extends BrowserTestBase { 'panelizer[custom]' => TRUE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->rebuildAll(); } @@ -87,19 +87,19 @@ class PanelizerTermFunctionalTest extends BrowserTestBase { $term = $this->createTerm(); $out = $this->drupalGet('taxonomy/term/' . $term->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->verbose($out); $elements = $this->xpath('//*[@id="panels-ipe-content"]'); if (is_array($elements)) { - $this->assertIdentical(count($elements), 1); + $this->assertSame(count($elements), 1); } else { $this->fail('Could not parse page content.'); } // Check that the block we added is visible. - $this->assertText('Panelizer test'); - $this->assertText('Abracadabra'); + $this->assertSession()->pageTextContains('Panelizer test'); + $this->assertSession()->pageTextContains('Abracadabra'); } /** diff --git a/tests/src/Functional/PanelizerTestTrait.php b/tests/src/Functional/PanelizerTestTrait.php index 951c0a9..5d5eb33 100644 --- a/tests/src/Functional/PanelizerTestTrait.php +++ b/tests/src/Functional/PanelizerTestTrait.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\panelizer\Functional; use Drupal\user\Entity\User; +use Drupal\Core\Entity\Entity\EntityFormDisplay; /** * Contains helper methods for writing functional tests of Panelizer. @@ -75,25 +76,25 @@ trait PanelizerTestTrait { */ protected function panelize($content_type = 'page', $display = NULL, array $values = []) { $this->drupalGet("admin/structure/types"); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->drupalGet("admin/structure/types/manage/{$content_type}"); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $path = "admin/structure/types/manage/{$content_type}/display"; if (!empty($display)) { $path .= '/' . $display; } $this->drupalGet($path); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $edit = [ 'panelizer[enable]' => TRUE, ] + $values; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); - entity_get_form_display('node', $content_type, 'default') + EntityFormDisplay::load('node.' . $content_type . '.default') ->setComponent('panelizer', [ 'type' => 'panelizer', ]) @@ -115,15 +116,15 @@ trait PanelizerTestTrait { */ protected function unpanelize($content_type = 'page', $display = NULL, array $values = []) { $this->drupalGet("admin/structure/types/manage/{$content_type}/display/{$display}"); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $edit = [ 'panelizer[enable]' => FALSE, ] + $values; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); - entity_get_form_display('node', $content_type, 'default') + EntityFormDisplay::load('node.' . $content_type . '.default') ->removeComponent('panelizer') ->save(); } @@ -149,7 +150,7 @@ trait PanelizerTestTrait { $path .= '/' . $display; } $this->drupalGet($path); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->clickLink('Add a new Panelizer default display'); // Step 1: Enter the default's label and ID. @@ -158,22 +159,22 @@ trait PanelizerTestTrait { 'label' => $label, ]; $this->drupalPostForm(NULL, $edit, t('Next')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Step 2: Define contexts. - $this->assertUrl("admin/structure/panelizer/add/{$default_id}/contexts", $options); + $this->assertSession()->addressEquals("admin/structure/panelizer/add/{$default_id}/contexts", $options); $this->drupalPostForm(NULL, [], t('Next')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Step 3: Select layout. - $this->assertUrl("admin/structure/panelizer/add/{$default_id}/layout", $options); + $this->assertSession()->addressEquals("admin/structure/panelizer/add/{$default_id}/layout", $options); $this->drupalPostForm(NULL, [], t('Next')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Step 4: Select content. - $this->assertUrl("admin/structure/panelizer/add/{$default_id}/content", $options); + $this->assertSession()->addressEquals("admin/structure/panelizer/add/{$default_id}/content", $options); $this->drupalPostForm(NULL, [], t('Finish')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); return $id; } @@ -191,9 +192,9 @@ trait PanelizerTestTrait { */ protected function deletePanelizerDefault($content_type = 'page', $display = 'default', $id = 'default') { $this->drupalGet("admin/structure/panelizer/delete/node__{$content_type}__{$display}__{$id}"); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->drupalPostForm(NULL, [], t('Confirm')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); } /** @@ -208,7 +209,7 @@ trait PanelizerTestTrait { * (optional) The default ID. */ protected function assertDefaultExists($content_type = 'page', $display = 'default', $id = 'default') { - $settings = entity_get_display('node', $content_type, $display) + $settings = \Drupal::service('entity_display.repository')->getViewDisplay('node', $content_type, $display) ->getThirdPartySettings('panelizer'); $display_exists = isset($settings['displays'][$id]); @@ -227,7 +228,7 @@ trait PanelizerTestTrait { * The default ID. */ protected function assertDefaultNotExists($content_type = 'page', $display = 'default', $id = 'default') { - $settings = entity_get_display('node', $content_type, $display) + $settings = \Drupal::service('entity_display.repository')->getViewDisplay('node', $content_type, $display) ->getThirdPartySettings('panelizer'); $display_exists = isset($settings['displays'][$id]); diff --git a/tests/src/Functional/PanelizerUserFunctionalTest.php b/tests/src/Functional/PanelizerUserFunctionalTest.php index 73aa092..02c6d22 100644 --- a/tests/src/Functional/PanelizerUserFunctionalTest.php +++ b/tests/src/Functional/PanelizerUserFunctionalTest.php @@ -58,13 +58,13 @@ class PanelizerUserFunctionalTest extends BrowserTestBase { // Enable Panelizer for this entity. $this->drupalGet('admin/config/people/accounts/display'); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $edit = [ 'panelizer[enable]' => TRUE, 'panelizer[custom]' => TRUE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Reload all caches. $this->rebuildAll(); @@ -91,21 +91,21 @@ class PanelizerUserFunctionalTest extends BrowserTestBase { // Check the user entity page. $out = $this->drupalGet('user/' . $account->id()); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->verbose($out); // Verify that $elements = $this->xpath('//*[@id="panels-ipe-content"]'); if (is_array($elements)) { - $this->assertIdentical(count($elements), 1); + $this->assertSame(count($elements), 1); } else { $this->fail('Could not parse page content.'); } // Check that the block we added is visible. - $this->assertText('Panelizer test'); - $this->assertText('Abracadabra'); + $this->assertSession()->pageTextContains('Panelizer test'); + $this->assertSession()->pageTextContains('Abracadabra'); } } diff --git a/tests/src/FunctionalJavascript/PanelizerIntegrationTest.php b/tests/src/FunctionalJavascript/PanelizerIntegrationTest.php index d9af169..0c70f2d 100644 --- a/tests/src/FunctionalJavascript/PanelizerIntegrationTest.php +++ b/tests/src/FunctionalJavascript/PanelizerIntegrationTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\panelizer\FunctionalJavascript; -use Drupal\simpletest\ContentTypeCreationTrait; +use Drupal\Tests\node\Traits\ContentTypeCreationTrait; use Drupal\Tests\panels_ipe\FunctionalJavascript\PanelsIPETestBase; /**