FIX Use Live stage to fetch results during SearchFormTest

This resolves an issue with the testUnpublishedPagesNotIncluded case
when running against PostgreSQL.
This commit is contained in:
Garion Herman 2020-10-21 11:31:30 +13:00
parent 21a228fd23
commit 8a16d708d4
1 changed files with 87 additions and 13 deletions

View File

@ -136,7 +136,12 @@ class ZZZSearchFormTest extends FunctionalTest
$this->waitUntilIndexingFinished(); $this->waitUntilIndexingFinished();
$results = $sf->getResults(); // Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertContains( $this->assertContains(
$publishedPage->ID, $publishedPage->ID,
$results->column('ID'), $results->column('ID'),
@ -165,7 +170,13 @@ class ZZZSearchFormTest extends FunctionalTest
$publishedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $publishedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$this->waitUntilIndexingFinished(); $this->waitUntilIndexingFinished();
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertContains( $this->assertContains(
$publishedPage->ID, $publishedPage->ID,
$results->column('ID'), $results->column('ID'),
@ -187,7 +198,12 @@ class ZZZSearchFormTest extends FunctionalTest
$this->mockController->setRequest($request); $this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController); $sf = new SearchForm($this->mockController);
$results = $sf->getResults(); // Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$unpublishedPage = $this->objFromFixture(SiteTree::class, 'publicUnpublishedPage'); $unpublishedPage = $this->objFromFixture(SiteTree::class, 'publicUnpublishedPage');
$this->assertNotContains( $this->assertNotContains(
$unpublishedPage->ID, $unpublishedPage->ID,
@ -210,7 +226,13 @@ class ZZZSearchFormTest extends FunctionalTest
/** @var SiteTree $page */ /** @var SiteTree $page */
$page = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers'); $page = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers');
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertNotContains( $this->assertNotContains(
$page->ID, $page->ID,
$results->column('ID'), $results->column('ID'),
@ -242,7 +264,13 @@ class ZZZSearchFormTest extends FunctionalTest
/** @var SiteTree $page */ /** @var SiteTree $page */
$page = $this->objFromFixture(SiteTree::class, 'restrictedViewOnlyWebsiteUsers'); $page = $this->objFromFixture(SiteTree::class, 'restrictedViewOnlyWebsiteUsers');
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertNotContains( $this->assertNotContains(
$page->ID, $page->ID,
$results->column('ID'), $results->column('ID'),
@ -251,7 +279,13 @@ class ZZZSearchFormTest extends FunctionalTest
$member = $this->objFromFixture(Member::class, 'randomuser'); $member = $this->objFromFixture(Member::class, 'randomuser');
Security::setCurrentUser($member); Security::setCurrentUser($member);
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertNotContains( $this->assertNotContains(
$page->ID, $page->ID,
$results->column('ID'), $results->column('ID'),
@ -287,7 +321,13 @@ class ZZZSearchFormTest extends FunctionalTest
/** @var SiteTree $page */ /** @var SiteTree $page */
$page = $this->objFromFixture(SiteTree::class, 'inheritRestrictedView'); $page = $this->objFromFixture(SiteTree::class, 'inheritRestrictedView');
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertNotContains( $this->assertNotContains(
$page->ID, $page->ID,
$results->column('ID'), $results->column('ID'),
@ -296,7 +336,13 @@ class ZZZSearchFormTest extends FunctionalTest
$member = $this->objFromFixture(Member::class, 'websiteuser'); $member = $this->objFromFixture(Member::class, 'websiteuser');
Security::setCurrentUser($member); Security::setCurrentUser($member);
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertContains( $this->assertContains(
$page->ID, $page->ID,
$results->column('ID'), $results->column('ID'),
@ -317,7 +363,13 @@ class ZZZSearchFormTest extends FunctionalTest
$sf = new SearchForm($this->mockController); $sf = new SearchForm($this->mockController);
$page = $this->objFromFixture(SiteTree::class, 'dontShowInSearchPage'); $page = $this->objFromFixture(SiteTree::class, 'dontShowInSearchPage');
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertNotContains( $this->assertNotContains(
$page->ID, $page->ID,
$results->column('ID'), $results->column('ID'),
@ -343,7 +395,12 @@ class ZZZSearchFormTest extends FunctionalTest
$showInSearchFile = $this->objFromFixture(File::class, 'showInSearchFile'); $showInSearchFile = $this->objFromFixture(File::class, 'showInSearchFile');
$showInSearchFile->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $showInSearchFile->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults(); // Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertNotContains( $this->assertNotContains(
$dontShowInSearchFile->ID, $dontShowInSearchFile->ID,
$results->column('ID'), $results->column('ID'),
@ -355,7 +412,13 @@ class ZZZSearchFormTest extends FunctionalTest
$request->setSession($this->session()); $request->setSession($this->session());
$this->mockController->setRequest($request); $this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController); $sf = new SearchForm($this->mockController);
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertContains( $this->assertContains(
$showInSearchFile->ID, $showInSearchFile->ID,
$results->column('ID'), $results->column('ID'),
@ -382,7 +445,12 @@ class ZZZSearchFormTest extends FunctionalTest
$pageWithSpecialChars = $this->objFromFixture(SiteTree::class, 'pageWithSpecialChars'); $pageWithSpecialChars = $this->objFromFixture(SiteTree::class, 'pageWithSpecialChars');
$pageWithSpecialChars->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $pageWithSpecialChars->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults(); // Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertContains( $this->assertContains(
$pageWithSpecialChars->ID, $pageWithSpecialChars->ID,
$results->column('ID'), $results->column('ID'),
@ -394,7 +462,13 @@ class ZZZSearchFormTest extends FunctionalTest
$request->setSession($this->session()); $request->setSession($this->session());
$this->mockController->setRequest($request); $this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController); $sf = new SearchForm($this->mockController);
$results = $sf->getResults();
// Generate results on the Live stage for an accurate outcome
$results = Versioned::withVersionedMode(function () use ($sf) {
Versioned::set_stage(Versioned::LIVE);
return $sf->getResults();
});
$this->assertContains( $this->assertContains(
$pageWithSpecialChars->ID, $pageWithSpecialChars->ID,
$results->column('ID'), $results->column('ID'),