ClaroEntityDisplayTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace Drupal\FunctionalJavascriptTests\Theme;
  3. use Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest;
  4. /**
  5. * Runs EntityDisplayTest in Claro.
  6. *
  7. * @group claro
  8. *
  9. * @see \Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest.
  10. */
  11. class ClaroEntityDisplayTest extends EntityDisplayTest {
  12. /**
  13. * Modules to enable.
  14. *
  15. * Install the shortcut module so that claro.settings has its schema checked.
  16. * There's currently no way for Claro to provide a default and have valid
  17. * configuration as themes cannot react to a module install.
  18. *
  19. * @var string[]
  20. */
  21. public static $modules = ['shortcut'];
  22. /**
  23. * {@inheritdoc}
  24. */
  25. protected function setUp() {
  26. parent::setUp();
  27. $this->container->get('theme_installer')->install(['claro']);
  28. $this->config('system.theme')->set('default', 'claro')->save();
  29. }
  30. /**
  31. * Copied from parent.
  32. *
  33. * This is Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest::testEntityForm()
  34. * with a line changed to reflect row weight toggle being a link instead
  35. * of a button.
  36. */
  37. public function testEntityForm() {
  38. $this->drupalGet('entity_test/manage/1/edit');
  39. $this->assertSession()->fieldExists('field_test_text[0][value]');
  40. $this->drupalGet('entity_test/structure/entity_test/form-display');
  41. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
  42. $this->getSession()->getPage()->clickLink('Show row weights');
  43. $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
  44. $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'hidden');
  45. $this->assertSession()->assertWaitOnAjaxRequest();
  46. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
  47. $this->submitForm([], 'Save');
  48. $this->assertSession()->pageTextContains('Your settings have been saved.');
  49. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
  50. $this->drupalGet('entity_test/manage/1/edit');
  51. $this->assertSession()->fieldNotExists('field_test_text[0][value]');
  52. }
  53. /**
  54. * Copied from parent.
  55. *
  56. * This is Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest::testEntityView()
  57. * with a line changed to reflect row weight toggle being a link instead
  58. * of a button.
  59. */
  60. public function testEntityView() {
  61. $this->drupalGet('entity_test/1');
  62. $this->assertSession()->elementNotExists('css', '.field--name-field-test-text');
  63. $this->drupalGet('entity_test/structure/entity_test/display');
  64. $this->assertSession()->elementExists('css', '.region-content-message.region-empty');
  65. $this->getSession()->getPage()->clickLink('Show row weights');
  66. $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
  67. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
  68. $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'content');
  69. $this->assertSession()->assertWaitOnAjaxRequest();
  70. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
  71. $this->submitForm([], 'Save');
  72. $this->assertSession()->pageTextContains('Your settings have been saved.');
  73. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
  74. $this->drupalGet('entity_test/1');
  75. $this->assertSession()->elementExists('css', '.field--name-field-test-text');
  76. }
  77. /**
  78. * Copied from parent.
  79. *
  80. * This is Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest::testExtraFields()
  81. * with a line changed to reflect Claro's tabledrag selector.
  82. */
  83. public function testExtraFields() {
  84. entity_test_create_bundle('bundle_with_extra_fields');
  85. $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
  86. $this->assertSession()->waitForElement('css', '.tabledrag-handle');
  87. $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();
  88. $extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field');
  89. $disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title');
  90. $extra_field_row->find('css', '.js-tabledrag-handle')->dragTo($disabled_region_row);
  91. $this->assertSession()->assertWaitOnAjaxRequest();
  92. $this->assertSession()
  93. ->waitForElement('css', "[name='form_build_id']:not([value='$id'])");
  94. $this->submitForm([], 'Save');
  95. $this->assertSession()->pageTextContains('Your settings have been saved.');
  96. }
  97. }