From 0d45badeab6cbb1102a41a404b8dabbecef2c26e Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Sun, 22 Oct 2023 21:43:41 -0700 Subject: [PATCH 1/4] Next site settings and config ignores --- config/sync/config_ignore.settings.yml | 1 + config/sync/next.settings.yml | 5 ++++- config/sync/user.role.decoupled_site_users.yml | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/sync/config_ignore.settings.yml b/config/sync/config_ignore.settings.yml index 1289aaf0e..4b1d3469b 100644 --- a/config/sync/config_ignore.settings.yml +++ b/config/sync/config_ignore.settings.yml @@ -5,6 +5,7 @@ ignored_config_entities: - 'block.block.*' - 'core.extension:theme' - 'google_tag.container.*' + - 'next.next_entity_type_config.*' - 'next.next_site.*' - 'samlauth.authentication:map_users_roles' - 'system.action.user_add_role_action.custm_*' diff --git a/config/sync/next.settings.yml b/config/sync/next.settings.yml index 19893cfd6..5a38867e1 100644 --- a/config/sync/next.settings.yml +++ b/config/sync/next.settings.yml @@ -4,5 +4,8 @@ langcode: en site_previewer: iframe site_previewer_configuration: width: 100% - sync_route: false + sync_route: true sync_route_skip_routes: '' +preview_url_generator: simple_preview +preview_url_generator_configuration: null +debug: false diff --git a/config/sync/user.role.decoupled_site_users.yml b/config/sync/user.role.decoupled_site_users.yml index 35faf8782..93a7dec50 100644 --- a/config/sync/user.role.decoupled_site_users.yml +++ b/config/sync/user.role.decoupled_site_users.yml @@ -6,6 +6,7 @@ dependencies: - file - node - subrequests + - view_unpublished id: decoupled_site_users label: 'Decoupled Site User' weight: 2 @@ -15,3 +16,4 @@ permissions: - 'bypass node access' - 'delete own files' - 'issue subrequests' + - 'view any unpublished content' From b8ffd43bbb39863bab62d0f116a6de80a6482dfd Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Mon, 23 Oct 2023 08:49:44 -0700 Subject: [PATCH 2/4] add some tests for json api --- .../acceptance/Paragraphs/ListsCest.php | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/tests/codeception/acceptance/Paragraphs/ListsCest.php b/tests/codeception/acceptance/Paragraphs/ListsCest.php index 37de1721b..446d96e2c 100644 --- a/tests/codeception/acceptance/Paragraphs/ListsCest.php +++ b/tests/codeception/acceptance/Paragraphs/ListsCest.php @@ -26,6 +26,8 @@ public function __construct() { /** * Shared tags on each content type are identical. + * + * @group jsonapi */ public function testSharedTags(AcceptanceTester $I) { $shared_tag = $I->createEntity([ @@ -112,10 +114,24 @@ public function testSharedTags(AcceptanceTester $I) { $I->canSeeOptionIsSelected('Shared Tags (value 1)', $shared_tag->label()); $I->amOnPage($publication->toUrl('edit-form')->toString()); $I->canSeeOptionIsSelected('Shared Tags (value 1)', $shared_tag->label()); + + $I->amOnPage('/jsonapi/views/stanford_shared_tags/card_grid?page[limit]=50&views-argument[]=' . preg_replace('/[^a-z0-9-]/', '-', strtolower($shared_tag->label()))); + $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $json_ids = []; + foreach ($json_data['data'] as $item) { + $json_ids[] = $item['id']; + } + $I->assertContains($basic_page->uuid(), $json_ids); + $I->assertContains($news->uuid(), $json_ids); + $I->assertContains($event->uuid(), $json_ids); + $I->assertContains($person->uuid(), $json_ids); + $I->assertContains($publication->uuid(), $json_ids); } /** * News items should display in the list paragraph. + * + * @group jsonapi */ public function testListParagraphNews(AcceptanceTester $I) { $I->logInWithRole('contributor'); @@ -135,13 +151,23 @@ public function testListParagraphNews(AcceptanceTester $I) { $I->canSee('Lorem Ipsum'); $I->canSeeLink('Google', 'http://google.com'); $I->canSee($title); + + $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99'); + $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $json_titles = []; + foreach ($json_data['data'] as $item) { + $json_titles[] = $item['attributes']['title']; + } + $I->assertContains($title, $json_titles); } /** * When using the list paragraph and view arguments, it should filter results. + * + * @group jsonapi */ public function testListParagraphNewsFiltersNoFilter(AcceptanceTester $I) { - $I->logInWithRole('site_manager'); + $I->logInWithRole('contributor'); $topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics'); @@ -163,13 +189,26 @@ public function testListParagraphNewsFiltersNoFilter(AcceptanceTester $I) { $I->amOnPage($node->toUrl()->toString()); $I->canSee($news->label()); + + $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . Drupal::service('pathauto.alias_cleaner')->cleanString($topic_term->label())); + $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $json_titles = []; + foreach ($json_data['data'] as $item) { + $json_titles[] = $item['attributes']['title']; + } + $I->assertContains($news->label(), $json_titles); + + $topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics'); + $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . $topic_term->label()); + $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $I->assertEmpty($json_data['data']); } /** * When using the list paragraph and view arguments, it should filter results. */ public function testListParagraphNewsFiltersRandomFilter(AcceptanceTester $I) { - $I->logInWithRole('site_manager'); + $I->logInWithRole('contributor'); $random_term = $this->createTaxonomyTerm($I, 'stanford_news_topics'); $topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics'); @@ -199,7 +238,7 @@ public function testListParagraphNewsFiltersRandomFilter(AcceptanceTester $I) { * When using the list paragraph and view arguments, it should filter results. */ public function testListParagraphNewsFiltersTopicFilter(AcceptanceTester $I) { - $I->logInWithRole('site_manager'); + $I->logInWithRole('contributor'); $topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics'); // Use a child term but the argument is the parent term to verify children @@ -257,13 +296,6 @@ public function testEmptyResultsListEvents(AcceptanceTester $I) { ], 'su_list_button' => ['uri' => 'http://google.com', 'title' => 'Google'], ], 'paragraph'); - // $row = $I->createEntity([ - // 'type' => 'node_stanford_page_row', - // 'su_page_components' => [ - // 'target_id' => $paragraph->id(), - // 'entity' => $paragraph, - // ], - // ], 'paragraph_row'); $node = $I->createEntity([ 'type' => 'stanford_page', @@ -341,7 +373,6 @@ public function testEmptyResultsListEvents(AcceptanceTester $I) { ], ]); - $I->amOnPage('/'); $I->amOnPage($node->toUrl()->toString()); $I->cantSee($headline_text); $I->cantSee($message); @@ -349,6 +380,8 @@ public function testEmptyResultsListEvents(AcceptanceTester $I) { /** * Event items should display in the list paragraph. + * + * @group jsonapi */ public function testListParagraphEvents(AcceptanceTester $I) { $I->logInWithRole('contributor'); @@ -459,6 +492,14 @@ public function testListParagraphEvents(AcceptanceTester $I) { ]); $I->amOnPage($node->toUrl()->toString()); $I->cantSee($event->label()); + + $I->amOnPage('/jsonapi/views/stanford_events/list_page?page[limit]=99'); + $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $json_titles = []; + foreach ($json_data['data'] as $item) { + $json_titles[] = $item['attributes']['title']; + } + $I->assertContains($event->label(), $json_titles); } /** From 79a81e86069116123571bcb58f2631c2a35dc070 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Mon, 23 Oct 2023 11:31:44 -0700 Subject: [PATCH 3/4] Check for array key --- tests/codeception/acceptance/Content/PersonCest.php | 1 + .../codeception/acceptance/Paragraphs/ListsCest.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/codeception/acceptance/Content/PersonCest.php b/tests/codeception/acceptance/Content/PersonCest.php index b0241db93..4f6c3f7bf 100644 --- a/tests/codeception/acceptance/Content/PersonCest.php +++ b/tests/codeception/acceptance/Content/PersonCest.php @@ -165,6 +165,7 @@ public function testD8Core2613Terms(AcceptanceTester $I) { 'parent' => ['target_id' => $term1->id()], ], 'taxonomy_term'); + $I->runDrush('cache:rebuild'); $I->amOnPage($term3->toUrl()->toString()); $I->canSeeLink($term1->label()); $I->canSeeLink($term2->label()); diff --git a/tests/codeception/acceptance/Paragraphs/ListsCest.php b/tests/codeception/acceptance/Paragraphs/ListsCest.php index 446d96e2c..c6f2326e3 100644 --- a/tests/codeception/acceptance/Paragraphs/ListsCest.php +++ b/tests/codeception/acceptance/Paragraphs/ListsCest.php @@ -117,6 +117,8 @@ public function testSharedTags(AcceptanceTester $I) { $I->amOnPage('/jsonapi/views/stanford_shared_tags/card_grid?page[limit]=50&views-argument[]=' . preg_replace('/[^a-z0-9-]/', '-', strtolower($shared_tag->label()))); $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $I->assertArrayHasKey('data', $json_data); + $json_ids = []; foreach ($json_data['data'] as $item) { $json_ids[] = $item['id']; @@ -154,6 +156,8 @@ public function testListParagraphNews(AcceptanceTester $I) { $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99'); $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $I->assertArrayHasKey('data', $json_data); + $json_titles = []; foreach ($json_data['data'] as $item) { $json_titles[] = $item['attributes']['title']; @@ -190,8 +194,11 @@ public function testListParagraphNewsFiltersNoFilter(AcceptanceTester $I) { $I->amOnPage($node->toUrl()->toString()); $I->canSee($news->label()); - $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . Drupal::service('pathauto.alias_cleaner')->cleanString($topic_term->label())); + $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . Drupal::service('pathauto.alias_cleaner') + ->cleanString($topic_term->label())); $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $I->assertArrayHasKey('data', $json_data); + $json_titles = []; foreach ($json_data['data'] as $item) { $json_titles[] = $item['attributes']['title']; @@ -201,6 +208,7 @@ public function testListParagraphNewsFiltersNoFilter(AcceptanceTester $I) { $topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics'); $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . $topic_term->label()); $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $I->assertArrayHasKey('data', $json_data); $I->assertEmpty($json_data['data']); } @@ -495,6 +503,8 @@ public function testListParagraphEvents(AcceptanceTester $I) { $I->amOnPage('/jsonapi/views/stanford_events/list_page?page[limit]=99'); $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); + $I->assertArrayHasKey('data', $json_data); + $json_titles = []; foreach ($json_data['data'] as $item) { $json_titles[] = $item['attributes']['title']; From 8e2b0f6f2dfdd5ef0a0386ee32ee7ff712e6db21 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Mon, 23 Oct 2023 15:45:57 -0700 Subject: [PATCH 4/4] remove test steps --- .../acceptance/Paragraphs/ListsCest.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/codeception/acceptance/Paragraphs/ListsCest.php b/tests/codeception/acceptance/Paragraphs/ListsCest.php index c6f2326e3..ea55564c8 100644 --- a/tests/codeception/acceptance/Paragraphs/ListsCest.php +++ b/tests/codeception/acceptance/Paragraphs/ListsCest.php @@ -193,23 +193,6 @@ public function testListParagraphNewsFiltersNoFilter(AcceptanceTester $I) { $I->amOnPage($node->toUrl()->toString()); $I->canSee($news->label()); - - $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . Drupal::service('pathauto.alias_cleaner') - ->cleanString($topic_term->label())); - $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); - $I->assertArrayHasKey('data', $json_data); - - $json_titles = []; - foreach ($json_data['data'] as $item) { - $json_titles[] = $item['attributes']['title']; - } - $I->assertContains($news->label(), $json_titles); - - $topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics'); - $I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . $topic_term->label()); - $json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR); - $I->assertArrayHasKey('data', $json_data); - $I->assertEmpty($json_data['data']); } /**