From 40cda9582616afc4e4f5d8962df5437f5e4d5e9f Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Mon, 23 Oct 2023 08:49:44 -0700 Subject: [PATCH] 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..a4ff3b05a 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[]=' . $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); } /**