Skip to content

Commit

Permalink
EWPP-3953: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
brummbar committed Feb 13, 2024
1 parent 685bb4d commit ff7bfe3
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public function testListPageLinkListDisplayForm(): void {

$page = $this->getSession()->getPage();
$page->fillField('Title', 'List page for ct1');
$page->selectFieldOption('Source bundle', 'Content type one');
$this->assertSession()->assertWaitOnAjaxRequest();
$display = $this->assertSession()->selectExists('Display');
$assert_session = $this->assertSession();
$this->assertTrue($assert_session->optionExists('Source bundle', 'Content type one')->isSelected());
$display = $assert_session->selectExists('Display');
$this->assertEquals('required', $display->getAttribute('required'));
$this->assertFieldSelectOptions('Display', [
'same_configuration_display_one',
Expand All @@ -94,8 +94,8 @@ public function testListPageLinkListDisplayForm(): void {

// Pick a display with no configuration.
$page->selectFieldOption('Display', 'Title');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->pageTextContains('This plugin does not have any configuration options.');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->pageTextContains('This plugin does not have any configuration options.');
$page->pressButton('Save');

// Assert we see the results as just titles.
Expand All @@ -116,18 +116,18 @@ public function testListPageLinkListDisplayForm(): void {
$this->clickLink('List Page');
$this->assertEquals('title', $page->findField('Display')->find('css', 'option[selected="selected"]')->getValue());
$page->selectFieldOption('Display', 'Titles with optional link');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->pageTextNotContains('This plugin does not have any configuration options.');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->pageTextNotContains('This plugin does not have any configuration options.');
// By default, the Link checkbox is checked.
$checkbox = $page->find('css', '.form-item-emr-plugins-oe-list-page-wrapper-display-plugin-configuration-wrapper-test-configurable-title-link input');
$this->assertTrue($checkbox->isChecked());
// Switch again to another plugin for testing.
$page->selectFieldOption('Display', 'Same configuration display one.');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->fieldExists('The value');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->fieldExists('The value');
// Switch back and save.
$page->selectFieldOption('Display', 'Titles with optional link');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert_session->assertWaitOnAjaxRequest();
$page->pressButton('Save');
// We should see the titles in the same way: linked.
$links = $page->findAll('css', '.field--name-extra-field-oe-list-page-resultsnodeoe-list-page ul li a');
Expand Down Expand Up @@ -221,17 +221,16 @@ public function testBackendSortWithDisplayPlugins(): void {
$this->goToListPageConfiguration();

// Select node.
$this->getSession()->getPage()->selectFieldOption('Source entity type', 'node');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->getSession()->getPage()->selectFieldOption('Source bundle', 'content_type_one');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->selectExists('Sort');
$this->assertTrue($this->assertSession()->optionExists('Sort', 'Default')->isSelected());
$assert_session = $this->assertSession();
$this->assertTrue($assert_session->optionExists('Source entity type', 'node')->isSelected());
$this->assertTrue($assert_session->optionExists('Source bundle', 'content_type_one')->isSelected());
$assert_session->selectExists('Sort');
$this->assertTrue($assert_session->optionExists('Sort', 'Default')->isSelected());
$this->getSession()->getPage()->selectFieldOption('Display', 'Title');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert_session->assertWaitOnAjaxRequest();
$this->getSession()->getPage()->fillField('Title', 'Node title');
$this->getSession()->getPage()->pressButton('Save');
$this->assertSession()->pageTextContains('List page Node title has been created.');
$assert_session->pageTextContains('List page Node title has been created.');
// The sorting is by the default sort.
$this->assertResultsAreInCorrectOrder([
'First by created',
Expand Down Expand Up @@ -284,15 +283,14 @@ public function testPagerOnListPageWithDisplays(): void {
$this->goToListPageConfiguration();

// Select node.
$this->getSession()->getPage()->selectFieldOption('Source entity type', 'node');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->getSession()->getPage()->selectFieldOption('Source bundle', 'content_type_one');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert_session = $this->assertSession();
$this->assertTrue($assert_session->optionExists('Source entity type', 'node')->isSelected());
$this->assertTrue($assert_session->optionExists('Source bundle', 'content_type_one')->isSelected());
$this->getSession()->getPage()->selectFieldOption('Display', 'Title');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert_session->assertWaitOnAjaxRequest();
$this->getSession()->getPage()->fillField('Title', 'Node title');
$this->getSession()->getPage()->pressButton('Save');
$this->assertSession()->pageTextContains('List page Node title has been created.');
$assert_session->pageTextContains('List page Node title has been created.');

// The sorting is by the default sort.
$first_ten = array_splice($expected_order, 0, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public function testListPagePresetFilterValidations(): void {
$this->drupalLogin($admin);

$this->goToListPageConfiguration();

$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->assertTrue($assert_session->optionExists('Link source', 'List pages')->isSelected());
$page->selectFieldOption('Source entity type', 'Content');
$assert_session->assertWaitOnAjaxRequest();
$page->selectFieldOption('Source bundle', 'Content type one');
$assert_session->assertWaitOnAjaxRequest();
$this->assertListPagePresetFilterValidations('configuration[0][link_source][plugin_configuration_wrapper][list_pages][list_page_configuration][wrapper][default_filter_values]');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,26 @@ public function testListPagePluginFiltersFormConfiguration(): void {
$this->drupalLogin($admin);
$this->goToListPageConfiguration();
$page = $this->getSession()->getPage();
$page->selectFieldOption('Source bundle', 'Content type one');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert = $this->assertSession();
$this->assertTrue($assert->optionExists('Source bundle', 'Content type one')->isSelected());
$page->checkField('Override default exposed filters');

// By default, the CT exposed filters are Body and Status.
$this->assertSession()->checkboxChecked('Published');
$this->assertSession()->checkboxChecked('Body');
$this->assertSession()->checkboxNotChecked('Select one');
$this->assertSession()->checkboxNotChecked('Created');
$this->assertSession()->checkboxNotChecked($this->firstAssociation->label());
$this->assertSession()->checkboxNotChecked($this->secondAssociation->label());
$assert->checkboxChecked('Published');
$assert->checkboxChecked('Body');
$assert->checkboxNotChecked('Select one');
$assert->checkboxNotChecked('Created');
$assert->checkboxNotChecked($this->firstAssociation->label());
$assert->checkboxNotChecked($this->secondAssociation->label());

// Expose the associations fields.
$page->checkField($this->firstAssociation->label());
$page->checkField($this->secondAssociation->label());
$page->fillField('Title', 'Node title');
$page->pressButton('Save');

$this->assertSession()->pageTextContains('one yellow fruit');
$this->assertSession()->pageTextContains('a green fruit');
$assert->pageTextContains('one yellow fruit');
$assert->pageTextContains('a green fruit');
$actual_bundles = $this->getSelectOptions($this->firstAssociation->label());
$expected_bundles = [
'1' => 'yellow color',
Expand All @@ -228,42 +228,41 @@ public function testListPagePluginFiltersFormConfiguration(): void {
// Search on the first association field.
$this->getSession()->getPage()->selectFieldOption($this->firstAssociation->label(), 'yellow color');
$this->getSession()->getPage()->pressButton('Search');
$this->assertSession()->pageTextContains('one yellow fruit');
$this->assertSession()->pageTextNotContains('a green fruit');
$this->assertSession()->pageTextNotContains('Leaf');
$assert->pageTextContains('one yellow fruit');
$assert->pageTextNotContains('a green fruit');
$assert->pageTextNotContains('Leaf');

// Reset search.
$this->getSession()->getPage()->pressButton('Clear filters');
$this->assertSession()->pageTextContains('one yellow fruit');
$this->assertSession()->pageTextContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$assert->pageTextContains('one yellow fruit');
$assert->pageTextContains('a green fruit');
$assert->pageTextContains('Leaf');

// Search on the other value of the first association.
$this->getSession()->getPage()->selectFieldOption($this->firstAssociation->label(), 'green color');
$this->getSession()->getPage()->pressButton('Search');
$this->assertSession()->pageTextNotContains('one yellow fruit');
$this->assertSession()->pageTextContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$assert->pageTextNotContains('one yellow fruit');
$assert->pageTextContains('a green fruit');
$assert->pageTextContains('Leaf');

// Search on the second association.
$this->getSession()->getPage()->selectFieldOption($this->secondAssociation->label(), 'yellow color');
$this->getSession()->getPage()->pressButton('Search');
$this->assertSession()->pageTextNotContains('one yellow fruit');
$this->assertSession()->pageTextNotContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$assert->pageTextNotContains('one yellow fruit');
$assert->pageTextNotContains('a green fruit');
$assert->pageTextContains('Leaf');

// Add default values for the first association.
$node = $this->drupalGetNodeByTitle('Node title');
$this->drupalGet($node->toUrl('edit-form'));
$this->clickLink('List Page');

$page->selectFieldOption('Add default value for', $this->firstAssociation->label());
$this->assertSession()->assertWaitOnAjaxRequest();
$assert = $this->assertSession();
$assert->assertWaitOnAjaxRequest();
$assert->pageTextContains('Set default value for ' . $this->firstAssociation->label());
// Test required fields.
$page->pressButton('Set default value');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert->assertWaitOnAjaxRequest();
$assert->pageTextContains($this->firstAssociation->label() . ' field is required.');

$field_id = 'open_vocabularies_tags_vocabulary_tags_vocabulary_node_content_type_one_field_open_vocabularies';
Expand All @@ -272,7 +271,7 @@ public function testListPagePluginFiltersFormConfiguration(): void {
$filter_selector = $default_value_name_prefix . '[wrapper][edit][' . $association_filter_id . ']';
$this->getSession()->getPage()->fillField($filter_selector . '[' . $field_id . '][0][entity_reference]', 'green color (2)');
$page->pressButton('Set default value');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert->assertWaitOnAjaxRequest();
$expected_set_filters = [
[
'key' => $this->firstAssociation->label(),
Expand All @@ -283,9 +282,9 @@ public function testListPagePluginFiltersFormConfiguration(): void {
$page->pressButton('Save');

// Results are correct and facet correctly filled.
$this->assertSession()->pageTextNotContains('one yellow fruit');
$this->assertSession()->pageTextContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$assert->pageTextNotContains('one yellow fruit');
$assert->pageTextContains('a green fruit');
$assert->pageTextContains('Leaf');
$actual_bundles = $this->getSelectOptions($this->firstAssociation->label());
$expected_bundles = [
'2' => 'green color',
Expand All @@ -298,12 +297,11 @@ public function testListPagePluginFiltersFormConfiguration(): void {

// Add another default value, for the second association.
$page->selectFieldOption('Add default value for', $this->secondAssociation->label());
$this->assertSession()->assertWaitOnAjaxRequest();
$assert = $this->assertSession();
$assert->assertWaitOnAjaxRequest();
$assert->pageTextContains('Set default value for ' . $this->secondAssociation->label());
// Test required fields.
$page->pressButton('Set default value');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert->assertWaitOnAjaxRequest();
$assert->pageTextContains($this->secondAssociation->label() . ' field is required.');

$field_id = 'open_vocabularies_tags_vocabulary_two_tags_vocabulary_two_node_content_type_one_field_open_vocabularies';
Expand All @@ -312,7 +310,7 @@ public function testListPagePluginFiltersFormConfiguration(): void {
$filter_selector = $default_value_name_prefix . '[wrapper][edit][' . $association_filter_id . ']';
$this->getSession()->getPage()->fillField($filter_selector . '[' . $field_id . '][0][entity_reference]', 'yellow color (1)');
$page->pressButton('Set default value');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert->assertWaitOnAjaxRequest();
$expected_set_filters = [
[
'key' => $this->firstAssociation->label(),
Expand All @@ -327,9 +325,9 @@ public function testListPagePluginFiltersFormConfiguration(): void {
$page->pressButton('Save');

// Results are correct and facet correctly filled.
$this->assertSession()->pageTextNotContains('one yellow fruit');
$this->assertSession()->pageTextNotContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$assert->pageTextNotContains('one yellow fruit');
$assert->pageTextNotContains('a green fruit');
$assert->pageTextContains('Leaf');
$actual_bundles = $this->getSelectOptions($this->firstAssociation->label());
$expected_bundles = [
'2' => 'green color',
Expand All @@ -347,19 +345,19 @@ public function testListPagePluginFiltersFormConfiguration(): void {
$this->secondAssociation->delete();
$node = $this->drupalGetNodeByTitle('Node title');
$this->drupalGet($node->toUrl());
$this->assertSession()->pageTextContains('one yellow fruit');
$this->assertSession()->pageTextContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$assert->pageTextContains('one yellow fruit');
$assert->pageTextContains('a green fruit');
$assert->pageTextContains('Leaf');

// Can be edited again.
$this->drupalGet($node->toUrl('edit-form'));
$this->clickLink('List Page');
$this->assertSession()->fieldNotExists('Tags association');
$this->assertSession()->fieldNotExists('Tags association two');
$assert->fieldNotExists('Tags association');
$assert->fieldNotExists('Tags association two');
$page->pressButton('Save');
$this->assertSession()->pageTextContains('one yellow fruit');
$this->assertSession()->pageTextContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$assert->pageTextContains('one yellow fruit');
$assert->pageTextContains('a green fruit');
$assert->pageTextContains('Leaf');
}

/**
Expand All @@ -369,31 +367,29 @@ public function testListPageContextualFilters(): void {
$admin = $this->createUser([], NULL, TRUE);
$this->drupalLogin($admin);
$this->drupalGet('link_list/add/dynamic');
$this->getSession()->getPage()->selectFieldOption('Link source', 'List page');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert_session = $this->assertSession();
$this->assertTrue($assert_session->optionExists('Link source', 'List pages')->isSelected());
$contextual_filter_name_prefix = 'configuration[0][link_source][plugin_configuration_wrapper][list_pages][list_page_configuration][wrapper][contextual_filters]';
$this->getSession()->getPage()->fillField('Administrative title', 'List page plugin test');
$this->getSession()->getPage()->fillField('Title', 'List page list OpenVocabularies');
$this->getSession()->getPage()->selectFieldOption('Link display', 'Title');
$this->assertSession()->assertWaitOnAjaxRequest();
$page = $this->getSession()->getPage();
$assert = $this->assertSession();
$page->selectFieldOption('Source entity type', 'Content');
$assert->assertWaitOnAjaxRequest();
$assert_session->assertWaitOnAjaxRequest();
$page->selectFieldOption('Source bundle', 'Content type one');
$assert->assertWaitOnAjaxRequest();
$assert_session->assertWaitOnAjaxRequest();

// Set a contextual filter for the association.
$field_id = 'open_vocabularies_tags_vocabulary_tags_vocabulary_node_content_type_one_field_open_vocabularies';
$association_filter_id = FilterConfigurationFormBuilderBase::generateFilterId($field_id);
$expected_contextual_filters = [];
$page->selectFieldOption('Add contextual value for', $this->firstAssociation->label());
$this->assertSession()->assertWaitOnAjaxRequest();
$assert->pageTextContains('Set contextual options for ' . $this->firstAssociation->label());
$assert_session->assertWaitOnAjaxRequest();
$assert_session->pageTextContains('Set contextual options for ' . $this->firstAssociation->label());
$filter_selector = $contextual_filter_name_prefix . '[wrapper][edit][' . $association_filter_id . ']';
$this->getSession()->getPage()->selectFieldOption($filter_selector . '[operator]', 'and');
$page->pressButton('Set options');
$this->assertSession()->assertWaitOnAjaxRequest();
$assert_session->assertWaitOnAjaxRequest();
$expected_contextual_filters['reference'] = [
'key' => $this->firstAssociation->label(),
'value' => 'All of',
Expand All @@ -408,14 +404,14 @@ public function testListPageContextualFilters(): void {
// Nodes from content type one with same terms appear.
$node = $this->drupalGetNodeByTitle('Sun');
$this->drupalGet($node->toUrl());
$this->assertSession()->pageTextContains('one yellow fruit');
$this->assertSession()->pageTextNotContains('a green fruit');
$this->assertSession()->pageTextNotContains('Leaf');
$assert_session->pageTextContains('one yellow fruit');
$assert_session->pageTextNotContains('a green fruit');
$assert_session->pageTextNotContains('Leaf');
$node = $this->drupalGetNodeByTitle('Grass');
$this->drupalGet($node->toUrl());
$this->assertSession()->pageTextContains('a green fruit');
$this->assertSession()->pageTextContains('Leaf');
$this->assertSession()->pageTextNotContains('one yellow fruit');
$assert_session->pageTextContains('a green fruit');
$assert_session->pageTextContains('Leaf');
$assert_session->pageTextNotContains('one yellow fruit');
}

/**
Expand Down
Loading

0 comments on commit ff7bfe3

Please sign in to comment.