From 81e225a540ba71d731eb860fb33fa12eab5cc336 Mon Sep 17 00:00:00 2001 From: upchuk Date: Mon, 18 Oct 2021 12:03:31 +0200 Subject: [PATCH 1/2] EWPP-760: Configurable sort options. --- src/Form/ListPageConfigurationSubForm.php | 110 ++++++++++ src/ListPageConfiguration.php | 2 +- src/ListPageEvents.php | 8 + src/ListPageSortAlterEvent.php | 88 ++++++++ src/Plugin/EntityMetaRelation/ListPage.php | 1 + .../ListPagesTestSubscriber.php | 17 ++ .../ListPagesSortTest.php | 207 ++++++++++++++++++ 7 files changed, 432 insertions(+), 1 deletion(-) create mode 100644 src/ListPageSortAlterEvent.php create mode 100644 tests/src/FunctionalJavascript/ListPagesSortTest.php diff --git a/src/Form/ListPageConfigurationSubForm.php b/src/Form/ListPageConfigurationSubForm.php index 6ee65c8a..a6cd1052 100644 --- a/src/Form/ListPageConfigurationSubForm.php +++ b/src/Form/ListPageConfigurationSubForm.php @@ -16,6 +16,7 @@ use Drupal\oe_list_pages\ListPageConfiguration; use Drupal\oe_list_pages\ListPageConfigurationSubformInterface; use Drupal\oe_list_pages\ListPageEvents; +use Drupal\oe_list_pages\ListPageSortAlterEvent; use Drupal\oe_list_pages\ListPageSourceAlterEvent; use Drupal\oe_list_pages\DefaultFilterConfigurationBuilder; use Drupal\oe_list_pages\ListSourceFactoryInterface; @@ -24,6 +25,8 @@ /** * Default list page configuration subform. + * + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class ListPageConfigurationSubForm implements ListPageConfigurationSubformInterface { @@ -114,6 +117,13 @@ public function buildForm(array $form, FormStateInterface $form_state): array { $entity_type_options = $this->getEntityTypeOptions(); $entity_type_id = $this->configuration->getEntityType(); $entity_type_bundle = $this->configuration->getBundle(); + $configuration_sort = $this->configuration->getSort(); + if ($configuration_sort) { + $configuration_sort = static::generateSortMachineName($configuration_sort); + } + else { + $configuration_sort = NULL; + } $ajax_wrapper_id = 'list-page-configuration-' . ($form['#parents'] ? '-' . implode('-', $form['#parents']) : ''); @@ -126,6 +136,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array { $selected_entity_type = $form_state->has('entity_type') ? $form_state->get('entity_type') : $entity_type_id; $selected_bundle = $form_state->has('bundle') ? $form_state->get('bundle') : $entity_type_bundle; + $selected_sort = $form_state->has('sort') ? $form_state->get('sort') : $configuration_sort; if (!$form_state->has('entity_type')) { $form_state->set('entity_type', $selected_entity_type); } @@ -192,6 +203,23 @@ public function buildForm(array $form, FormStateInterface $form_state): array { // Try to get the list source for the selected entity type and bundle. $list_source = $this->listSourceFactory->get($selected_entity_type, $selected_bundle); + if ($list_source) { + $sort_options = $this->getSortOptions($list_source); + $form_state->set('default_bundle_sort', $this->getBundleDefaultSort($list_source)); + if ($selected_sort && !isset($sort_options[$selected_sort])) { + // In case we no longer have the sort option, we should not show + // any default value. + $selected_sort = NULL; + } + $form['wrapper']['sort'] = [ + '#type' => 'select', + '#options' => $sort_options, + '#title' => $this->t('Sort'), + '#default_value' => $selected_sort, + '#access' => count($sort_options) > 1, + ]; + } + // Get available filters. if ($list_source && $available_filters = $list_source->getAvailableFilters()) { $exposed_filters = $this->getExposedFilters($list_source); @@ -332,6 +360,29 @@ public function submitForm(array &$form, FormStateInterface $form_state): void { $exposed_filters = []; } + $sort = $form_state->getValue(['wrapper', 'sort']); + $default_bundle_sort = $form_state->get('default_bundle_sort'); + if ($default_bundle_sort) { + // In case a bundle is not properly configured with a default sort, we + // need to check if the value is there before we generate a machine name. + $default_bundle_sort = static::generateSortMachineName($default_bundle_sort); + } + + if ($sort) { + list($name, $direction) = explode('__', $sort); + $this->configuration->setSort([ + 'name' => $name, + 'direction' => strtoupper($direction), + ]); + } + + if ($sort === $default_bundle_sort || $sort == "") { + // If the user configured the default bundle sort, we remove the value + // from the configuration in case later we change the defaults, we want + // the defaults to still take effect. + $this->configuration->setSort([]); + } + $this->configuration->setExposedFilters($exposed_filters); } @@ -515,4 +566,63 @@ protected function getBundleDefaultExposedFilters(ListSourceInterface $list_sour return $bundle->getThirdPartySetting('oe_list_pages', 'default_exposed_filters', []); } + /** + * Get the default sort configuration from the bundle. + * + * @param \Drupal\oe_list_pages\ListSourceInterface $list_source + * The selected list source. + * + * @return array + * The sort information. + */ + protected function getBundleDefaultSort(ListSourceInterface $list_source): array { + $default_sort = &drupal_static(__FUNCTION__ . $list_source->getEntityType() . $list_source->getBundle()); + if ($default_sort) { + return $default_sort; + } + $bundle_entity_type = $this->entityTypeManager->getDefinition($list_source->getEntityType())->getBundleEntityType(); + $storage = $this->entityTypeManager->getStorage($bundle_entity_type); + $bundle = $storage->load($list_source->getBundle()); + $default_sort = $bundle->getThirdPartySetting('oe_list_pages', 'default_sort', []); + return $default_sort; + } + + /** + * Gets the available sort options. + * + * @param \Drupal\oe_list_pages\ListSourceInterface $list_source + * The selected list source. + * + * @return array + * The sort options. + */ + protected function getSortOptions(ListSourceInterface $list_source): array { + $options = []; + + // Get the default sort option. + $sort = $this->getBundleDefaultSort($list_source); + if ($sort) { + $options[static::generateSortMachineName($sort)] = $this->t('Default'); + } + + $event = new ListPageSortAlterEvent($list_source->getEntityType(), $list_source->getBundle()); + $event->setOptions($options); + $this->eventDispatcher->dispatch(ListPageEvents::ALTER_SORT_OPTIONS, $event); + + return $event->getOptions(); + } + + /** + * Given a sort array with "name" and "direction", generate a machine name. + * + * @param array $sort + * The sort information. + * + * @return string + * The machine name. + */ + public static function generateSortMachineName(array $sort): string { + return $sort['name'] . '__' . strtoupper($sort['direction']); + } + } diff --git a/src/ListPageConfiguration.php b/src/ListPageConfiguration.php index fb4b7180..2f229c19 100644 --- a/src/ListPageConfiguration.php +++ b/src/ListPageConfiguration.php @@ -121,7 +121,7 @@ public static function fromEntity(ContentEntityInterface $entity): ListPageConfi 'exposed_filters_overridden' => isset($wrapper_configuration['override_exposed_filters']) ? (bool) $wrapper_configuration['override_exposed_filters'] : FALSE, 'limit' => $wrapper_configuration['limit'] ?? NULL, 'page' => $wrapper_configuration['page'] ?? NULL, - 'sort' => [], + 'sort' => $wrapper_configuration['sort'] ?? [], ]; return new static($configuration); diff --git a/src/ListPageEvents.php b/src/ListPageEvents.php index 3708dfe3..91fe0021 100644 --- a/src/ListPageEvents.php +++ b/src/ListPageEvents.php @@ -37,4 +37,12 @@ final class ListPageEvents { */ const ALTER_RSS_ITEM_BUILD = "oe_list_pages.rss_build_item_alter"; + + /** + * Event fired to determine sort options. + * + * @var string + */ + const ALTER_SORT_OPTIONS = "oe_list_pages.alter_sort_options"; + } diff --git a/src/ListPageSortAlterEvent.php b/src/ListPageSortAlterEvent.php new file mode 100644 index 00000000..9281692a --- /dev/null +++ b/src/ListPageSortAlterEvent.php @@ -0,0 +1,88 @@ +entityType = $entity_type; + $this->bundle = $bundle; + } + + /** + * Returns the entity type. + * + * @return string + * The entity type. + */ + public function getEntityType(): string { + return $this->entityType; + } + + /** + * Returns the bundle. + * + * @return string + * The bundle. + */ + public function getBundle(): string { + return $this->bundle; + } + + /** + * Returns the sort options. + * + * @return array + * The sort options. + */ + public function getOptions(): array { + return $this->options; + } + + /** + * Sets the sort information. + * + * @param array $options + * The sort options. + */ + public function setOptions(array $options): void { + $this->options = $options; + } + +} diff --git a/src/Plugin/EntityMetaRelation/ListPage.php b/src/Plugin/EntityMetaRelation/ListPage.php index 2cd76561..d3943283 100755 --- a/src/Plugin/EntityMetaRelation/ListPage.php +++ b/src/Plugin/EntityMetaRelation/ListPage.php @@ -167,6 +167,7 @@ public function submit(array $form, FormStateInterface $form_state): void { $this->getFormKey(), 'limit', ]); + $entity_meta_configuration['sort'] = $configuration->getSort(); $entity_meta_wrapper->setConfiguration($entity_meta_configuration); $host_entity->get('emr_entity_metas')->attach($entity_meta); } diff --git a/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php b/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php index 88aa0f86..04c6bb6c 100755 --- a/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php +++ b/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php @@ -8,6 +8,7 @@ use Drupal\oe_list_pages\ListPageRssAlterEvent; use Drupal\oe_list_pages\ListPageEvents; use Drupal\oe_list_pages\ListPageRssItemAlterEvent; +use Drupal\oe_list_pages\ListPageSortAlterEvent; use Drupal\oe_list_pages\ListPageSourceAlterEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -42,6 +43,7 @@ public static function getSubscribedEvents() { ListPageEvents::ALTER_BUNDLES => ['onBundlesAlter'], ListPageEvents::ALTER_RSS_BUILD => ['onRssBuildAlter'], ListPageEvents::ALTER_RSS_ITEM_BUILD => ['onRssItemBuildAlter'], + ListPageEvents::ALTER_SORT_OPTIONS => ['onSortOptionsAlter'], ]; } @@ -117,4 +119,19 @@ public function onRssItemBuildAlter(ListPageRssItemAlterEvent $event): void { $event->setBuild($build); } + /** + * Event handler for altering the sort options. + * + * @param \Drupal\oe_list_pages\ListPageSortAlterEvent $event + * The event. + */ + public function onSortOptionsAlter(ListPageSortAlterEvent $event): void { + $alter = (bool) $this->state->get('oe_list_pages_test.alter_sort_options'); + if ($alter) { + $options = $event->getOptions(); + $options['title__DESC'] = 'Title desc'; + $event->setOptions($options); + } + } + } diff --git a/tests/src/FunctionalJavascript/ListPagesSortTest.php b/tests/src/FunctionalJavascript/ListPagesSortTest.php new file mode 100644 index 00000000..2dd5dcf1 --- /dev/null +++ b/tests/src/FunctionalJavascript/ListPagesSortTest.php @@ -0,0 +1,207 @@ + 'A - First by created', + 'type' => 'content_type_one', + 'status' => NodeInterface::PUBLISHED, + 'created' => $date->getTimestamp(), + ]; + $this->drupalCreateNode($values); + + $date = new DrupalDateTime('20-10-2019'); + $values = [ + 'title' => 'Z - First by title', + 'type' => 'content_type_one', + 'status' => NodeInterface::PUBLISHED, + 'created' => $date->getTimestamp(), + ]; + $this->drupalCreateNode($values); + + /** @var \Drupal\search_api\Entity\Index $index */ + $index = Index::load('node'); + // Index the nodes. + $index->indexItems(); + + // Log in and create a list page. + $admin = $this->createUser([], NULL, TRUE); + $this->drupalLogin($admin); + $this->goToListPageConfiguration(); + + // No sort field visible. + $this->assertSession()->fieldNotExists('Sort'); + + // Select node. + $this->getSession()->getPage()->selectFieldOption('Source entity type', 'node'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->fieldNotExists('Sort'); + + // Select a bundle with no default sort (normally this should not happen + // but in case the bundle is not fully configured). + $this->getSession()->getPage()->selectFieldOption('Source bundle', 'content_type_two'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->fieldNotExists('Sort'); + + // Select a bundle that has the sort configured and assert we don't see the + // sort field (as we only have 1 sort option). + $this->getSession()->getPage()->selectFieldOption('Source bundle', 'content_type_one'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->fieldNotExists('Sort'); + + // Subscribe to the event and provide another sort option. + \Drupal::state()->set('oe_list_pages_test.alter_sort_options', TRUE); + $this->goToListPageConfiguration(); + $this->getSession()->getPage()->selectFieldOption('Source entity type', 'node'); + $this->assertSession()->assertWaitOnAjaxRequest(); + // This bundle only has the event subscriber sort so no Sort select should + // show up. + $this->getSession()->getPage()->selectFieldOption('Source bundle', 'content_type_two'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->fieldNotExists('Sort'); + // Save the node and assert we have no sort info in the entity meta. + $this->getSession()->getPage()->fillField('Title', 'Node title'); + $this->getSession()->getPage()->pressButton('Save'); + $this->assertSession()->pageTextContains('List page Node title has been created.'); + $this->assertEmpty($this->getSortInformationFromNodeMeta('Node title')); + + // Edit the node and switch to the content type which has more options due + // to the subscriber. + $node = $this->drupalGetNodeByTitle('Node title'); + $this->drupalGet($node->toUrl('edit-form')); + $this->clickLink('List Page'); + $this->getSession()->getPage()->selectFieldOption('Source bundle', 'content_type_one'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->selectExists('Sort'); + $actual_options = $this->getSelectOptions('Sort'); + $expected_options = [ + 'created__DESC' => 'Default', + 'title__DESC' => 'Title desc', + ]; + $this->assertEquals($expected_options, $actual_options); + // Assert also that the Default option is selected. + $this->assertTrue($this->assertSession()->optionExists('Sort', 'Default')->isSelected()); + + // Save the node with the default sort selected and assert that again, no + // sort has been saved in the meta because the defaults should not be saved. + $this->getSession()->getPage()->pressButton('Save'); + $this->assertEmpty($this->getSortInformationFromNodeMeta('Node title')); + $this->assertResultsAreInCorrectOrder([ + 'A - First by created', + 'Z - First by title', + ]); + + // Edit again the node and save a different sort. + $this->drupalGet($node->toUrl('edit-form')); + $this->clickLink('List Page'); + $this->getSession()->getPage()->selectFieldOption('Sort', 'title__DESC'); + $this->getSession()->getPage()->pressButton('Save'); + $this->assertEquals([ + 'name' => 'title', + 'direction' => 'DESC', + ], $this->getSortInformationFromNodeMeta('Node title')); + + $this->assertResultsAreInCorrectOrder([ + 'Z - First by title', + 'A - First by created', + ]); + + // Switch back to the default sort. + $this->drupalGet($node->toUrl('edit-form')); + $this->clickLink('List Page'); + $this->assertTrue($this->assertSession()->optionExists('Sort', 'Title desc')->isSelected()); + $this->getSession()->getPage()->selectFieldOption('Sort', 'created__DESC'); + $this->getSession()->getPage()->pressButton('Save'); + $this->assertEmpty($this->getSortInformationFromNodeMeta('Node title')); + $this->assertResultsAreInCorrectOrder([ + 'A - First by created', + 'Z - First by title', + ]); + } + + /** + * Loads the entity meta of a given node and returns the sort value. + * + * @param string $title + * The node title to load. + * + * @return array + * The sort value. + */ + protected function getSortInformationFromNodeMeta(string $title): array { + $node = $this->drupalGetNodeByTitle($title, TRUE); + /** @var \Drupal\emr\Field\ComputedEntityMetasItemList $entity_meta_list */ + $entity_meta_list = $node->get('emr_entity_metas'); + $entity_meta = $entity_meta_list->getEntityMeta('oe_list_page'); + /** @var \Drupal\oe_list_pages\ListPageWrapper $entity_meta_wrapper */ + $entity_meta_wrapper = $entity_meta->getWrapper(); + return $entity_meta_wrapper->getConfiguration()['sort']; + } + + /** + * Asserts that the list page result titles are in the correct order. + * + * @param array $expected_title_order + * The expected order of the titles. + */ + protected function assertResultsAreInCorrectOrder(array $expected_title_order): void { + $actual_title_order = []; + foreach ($this->getSession()->getPage()->findAll('css', 'article h2 a') as $element) { + $actual_title_order[] = $element->getText(); + } + + $this->assertEquals($expected_title_order, $actual_title_order); + } + + /** + * {@inheritdoc} + */ + protected function goToListPageConfiguration(): void { + $this->drupalGet('node/add/oe_list_page'); + $this->clickLink('List Page'); + } + +} From 4c161e73fe8be5993eab72f73cc4fef7035ca630 Mon Sep 17 00:00:00 2001 From: upchuk Date: Fri, 5 Nov 2021 09:34:56 +0100 Subject: [PATCH 2/2] EWPP-760: Ensuring that the default bundle sort comes after the selected one. --- src/ListExecutionManager.php | 28 +++++++-- .../ListPagesTestSubscriber.php | 2 +- .../ListPagesSortTest.php | 62 +++++++++++++++---- 3 files changed, 73 insertions(+), 19 deletions(-) diff --git a/src/ListExecutionManager.php b/src/ListExecutionManager.php index 1f7a34a4..a57bf2de 100644 --- a/src/ListExecutionManager.php +++ b/src/ListExecutionManager.php @@ -93,13 +93,13 @@ public function executeList(ListPageConfiguration $configuration): ?ListExecutio // If there is a sort configured use it, // otherwise use the bundle's default sort if set. $sort = $configuration->getSort(); - if (!$sort) { - $bundle_entity_type = $this->entityTypeManager->getDefinition($configuration->getEntityType())->getBundleEntityType(); - $storage = $this->entityTypeManager->getStorage($bundle_entity_type); - $bundle = $storage->load($configuration->getBundle()); - $sort = $bundle->getThirdPartySetting('oe_list_pages', 'default_sort', []); - } + $bundle_sort = $this->getBundleDefaultSort($list_source); + // If we have a specific sort, we use that first, followed by the default + // bundle sort. Otherwise, just the bundle sort. $sort = $sort ? [$sort['name'] => $sort['direction']] : []; + if ($bundle_sort) { + $sort[$bundle_sort['name']] = $bundle_sort['direction']; + } $options = [ 'limit' => $limit, @@ -117,4 +117,20 @@ public function executeList(ListPageConfiguration $configuration): ?ListExecutio return $list_execution; } + /** + * Get the default sort configuration from the bundle. + * + * @param \Drupal\oe_list_pages\ListSourceInterface $list_source + * The selected list source. + * + * @return array + * The sort information. + */ + protected function getBundleDefaultSort(ListSourceInterface $list_source): array { + $bundle_entity_type = $this->entityTypeManager->getDefinition($list_source->getEntityType())->getBundleEntityType(); + $storage = $this->entityTypeManager->getStorage($bundle_entity_type); + $bundle = $storage->load($list_source->getBundle()); + return $bundle->getThirdPartySetting('oe_list_pages', 'default_sort', []); + } + } diff --git a/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php b/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php index 04c6bb6c..8c132917 100755 --- a/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php +++ b/tests/modules/oe_list_pages_event_subscriber_test/src/EventSubscriber/ListPagesTestSubscriber.php @@ -129,7 +129,7 @@ public function onSortOptionsAlter(ListPageSortAlterEvent $event): void { $alter = (bool) $this->state->get('oe_list_pages_test.alter_sort_options'); if ($alter) { $options = $event->getOptions(); - $options['title__DESC'] = 'Title desc'; + $options['field_test_boolean__DESC'] = 'Boolean'; $event->setOptions($options); } } diff --git a/tests/src/FunctionalJavascript/ListPagesSortTest.php b/tests/src/FunctionalJavascript/ListPagesSortTest.php index 2dd5dcf1..91b13774 100644 --- a/tests/src/FunctionalJavascript/ListPagesSortTest.php +++ b/tests/src/FunctionalJavascript/ListPagesSortTest.php @@ -45,8 +45,36 @@ class ListPagesSortTest extends ListPagePluginFormTestBase { public function testSortSelection(): void { // Create some nodes to test the sorting. $date = new DrupalDateTime('20-10-2020'); + $date->modify('- 1 hour'); $values = [ - 'title' => 'A - First by created', + 'title' => 'Second by created', + 'type' => 'content_type_one', + 'status' => NodeInterface::PUBLISHED, + 'created' => $date->getTimestamp(), + ]; + $this->drupalCreateNode($values); + + $date->modify('+ 2 hours'); + $values = [ + 'title' => 'First by created', + 'type' => 'content_type_one', + 'status' => NodeInterface::PUBLISHED, + 'created' => $date->getTimestamp(), + ]; + $this->drupalCreateNode($values); + + $date->modify('- 3 hours'); + $values = [ + 'title' => 'Third by created', + 'type' => 'content_type_one', + 'status' => NodeInterface::PUBLISHED, + 'created' => $date->getTimestamp(), + ]; + $this->drupalCreateNode($values); + + $date->modify('- 1 hour'); + $values = [ + 'title' => 'Fourth by created', 'type' => 'content_type_one', 'status' => NodeInterface::PUBLISHED, 'created' => $date->getTimestamp(), @@ -55,9 +83,10 @@ public function testSortSelection(): void { $date = new DrupalDateTime('20-10-2019'); $values = [ - 'title' => 'Z - First by title', + 'title' => 'First by boolean field', 'type' => 'content_type_one', 'status' => NodeInterface::PUBLISHED, + 'field_test_boolean' => 1, 'created' => $date->getTimestamp(), ]; $this->drupalCreateNode($values); @@ -119,7 +148,7 @@ public function testSortSelection(): void { $actual_options = $this->getSelectOptions('Sort'); $expected_options = [ 'created__DESC' => 'Default', - 'title__DESC' => 'Title desc', + 'field_test_boolean__DESC' => 'Boolean', ]; $this->assertEquals($expected_options, $actual_options); // Assert also that the Default option is selected. @@ -130,35 +159,44 @@ public function testSortSelection(): void { $this->getSession()->getPage()->pressButton('Save'); $this->assertEmpty($this->getSortInformationFromNodeMeta('Node title')); $this->assertResultsAreInCorrectOrder([ - 'A - First by created', - 'Z - First by title', + 'First by created', + 'Second by created', + 'Third by created', + 'Fourth by created', + 'First by boolean field', ]); // Edit again the node and save a different sort. $this->drupalGet($node->toUrl('edit-form')); $this->clickLink('List Page'); - $this->getSession()->getPage()->selectFieldOption('Sort', 'title__DESC'); + $this->getSession()->getPage()->selectFieldOption('Sort', 'field_test_boolean__DESC'); $this->getSession()->getPage()->pressButton('Save'); $this->assertEquals([ - 'name' => 'title', + 'name' => 'field_test_boolean', 'direction' => 'DESC', ], $this->getSortInformationFromNodeMeta('Node title')); $this->assertResultsAreInCorrectOrder([ - 'Z - First by title', - 'A - First by created', + 'First by boolean field', + 'First by created', + 'Second by created', + 'Third by created', + 'Fourth by created', ]); // Switch back to the default sort. $this->drupalGet($node->toUrl('edit-form')); $this->clickLink('List Page'); - $this->assertTrue($this->assertSession()->optionExists('Sort', 'Title desc')->isSelected()); + $this->assertTrue($this->assertSession()->optionExists('Sort', 'Boolean')->isSelected()); $this->getSession()->getPage()->selectFieldOption('Sort', 'created__DESC'); $this->getSession()->getPage()->pressButton('Save'); $this->assertEmpty($this->getSortInformationFromNodeMeta('Node title')); $this->assertResultsAreInCorrectOrder([ - 'A - First by created', - 'Z - First by title', + 'First by created', + 'Second by created', + 'Third by created', + 'Fourth by created', + 'First by boolean field', ]); }