Skip to content

Commit

Permalink
Enable Whoops for most integration tests (#3976)
Browse files Browse the repository at this point in the history
- Also fixes an issue uncovered by this in status-full.phtml.
- Disables Whoops and logging for tests that expect failures.
  • Loading branch information
EreMaijala authored Oct 2, 2024
1 parent 5e939de commit a5b49a5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
9 changes: 7 additions & 2 deletions config/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
if (PHP_SAPI == 'cli' && APPLICATION_ENV !== 'testing') {
$modules[] = 'VuFindConsole';
}
if (APPLICATION_ENV == 'development') {
$modules[] = 'WhoopsErrorHandler';
if (APPLICATION_ENV === 'development' || APPLICATION_ENV === 'testing') {
if (!isset($_SERVER['HTTP_X_VUFIND_DISABLE_WHOOPS'])) {
$modules[] = 'WhoopsErrorHandler';
}
$modules[] = 'VuFindDevTools';
}
if (APPLICATION_ENV === 'development') {
$modules[] = 'VuFindDevTools';
}
if ($localModules = getenv('VUFIND_LOCAL_MODULES')) {
Expand Down
22 changes: 22 additions & 0 deletions module/VuFind/src/VuFindTest/Integration/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class Session extends \Behat\Mink\Session
*/
protected $coverageDir = '';

/**
* Whether Whoops error handler needs to be disabled
*
* @var bool
*/
protected $disableWhoops = false;

/**
* Set remote code coverage configuration
*
Expand All @@ -70,6 +77,18 @@ public function setRemoteCoverageConfig(
$this->coverageDir = $coverageDir;
}

/**
* Toggle HTTP header that disables Whoops
*
* @param bool $disable Whether to disable Whoops
*
* @return void
*/
public function setWhoopsDisabled(bool $disable): void
{
$this->disableWhoops = $disable;
}

/**
* Visit specified URL and automatically start session if not already running.
*
Expand All @@ -92,6 +111,9 @@ public function visit($url)
)
);
}
if ($this->disableWhoops) {
$this->setRequestHeader('X-VuFind-Disable-Whoops', '1');
}

parent::visit($url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,19 @@ protected function getBlenderIniOverrides()
*/
public function testDisabledSearch()
{
// Disable logging of a known exception:
$this->changeConfigs(
[
'config' => [
'Logging' => [
'file' => null,
],
],
]
);
$session = $this->getMinkSession();
// We expect an error, so let's act like production mode for realistic testing:
$session->setWhoopsDisabled(true);
$session->visit($this->getVuFindUrl() . '/Blender/Results');
$page = $session->getPage();
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ public function testOAuth2InvalidScope(): void
*/
public function testOAuth2InvalidClient(): void
{
// Disable logging of a known exception:
$this->changeConfigs(
[
'config' => [
'Logging' => [
'file' => null,
],
],
]
);
// Bogus redirect URI, but it doesn't matter since the page won't handle the
// authorization response:
$redirectUri = $this->getVuFindUrl() . '/Content/faq';
Expand All @@ -418,6 +428,8 @@ public function testOAuth2InvalidClient(): void
'state' => $state,
];
$session = $this->getMinkSession();
// We expect an error, so let's act like production mode for realistic testing:
$session->setWhoopsDisabled(true);
$session->visit(
$this->getVuFindUrl() . '/OAuth2/Authorize?' . http_build_query($params)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ public function testSavedSearchSecurity(): void
$this->findAndAssertLink($page, 'Log Out')->click();

// Use user A's delete link, but try to execute it as user B:
[$base, $params] = explode('?', $delete);
[, $params] = explode('?', $delete);
// We expect an error, so let's act like production mode for realistic testing:
$session->setWhoopsDisabled(true);
$session->visit($this->getVuFindUrl() . '/MyResearch/SaveSearch?' . $params);
$page = $session->getPage();
$this->clickCss($page, '.createAccountLink');
Expand All @@ -252,6 +254,8 @@ public function testSavedSearchSecurity(): void
$this->waitForPageLoad($page);
$this->findAndAssertLink($page, 'Log Out')->click();

// Go back to stricter error handling:
$session->setWhoopsDisabled(false);
// Go back in as user A -- see if the saved search still exists.
$this->findAndAssertLink($page, 'Search History')->click();
$this->clickCss($page, '#loginOptions a');
Expand Down
4 changes: 2 additions & 2 deletions themes/bootstrap3/templates/ajax/status-full.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

$itemHasAdditionalHoldingsFields = false;
foreach ($this->holdingsTextFieldNames as $holdingsTextField) {
if ($item[$holdingsTextField]) {
if (!empty($item[$holdingsTextField])) {
$itemHasAdditionalHoldingsFields = true;
break;
}
Expand Down Expand Up @@ -53,7 +53,7 @@
</tr>

<?php foreach ($this->holdingsTextFieldNames as $holdingsTextField): ?>
<?php if ($item[$holdingsTextField]): ?>
<?php if (!empty($item[$holdingsTextField])): ?>
<tr>
<td colspan="3" class="statusItemsHoldingsTextFields">
<strong><?= $this->transEsc(ucfirst($holdingsTextField)) ?>: </strong><span><?= $this->escapeHtml(implode('; ', ((array)$item[$holdingsTextField]))); ?></span>
Expand Down
4 changes: 2 additions & 2 deletions themes/bootstrap5/templates/ajax/status-full.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

$itemHasAdditionalHoldingsFields = false;
foreach ($this->holdingsTextFieldNames as $holdingsTextField) {
if ($item[$holdingsTextField]) {
if (!empty($item[$holdingsTextField])) {
$itemHasAdditionalHoldingsFields = true;
break;
}
Expand Down Expand Up @@ -53,7 +53,7 @@
</tr>

<?php foreach ($this->holdingsTextFieldNames as $holdingsTextField): ?>
<?php if ($item[$holdingsTextField]): ?>
<?php if (!empty($item[$holdingsTextField])): ?>
<tr>
<td colspan="3" class="statusItemsHoldingsTextFields">
<strong><?= $this->transEsc(ucfirst($holdingsTextField)) ?>: </strong><span><?= $this->escapeHtml(implode('; ', ((array)$item[$holdingsTextField]))); ?></span>
Expand Down

0 comments on commit a5b49a5

Please sign in to comment.