Skip to content

Commit

Permalink
Merge branch 'main' into feat/behat-definitions-user
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm authored Nov 1, 2024
2 parents 703d438 + e9b76e8 commit 03ff70a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/ContentContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Frontkom\DrupalBehatDefinitions;

use Drupal\DrupalExtension\Context\RawDrupalContext;

/**
* Class ContentContext.
*
* Provide Behat step-definitions for content related operations.
*/
class ContentContext extends RawDrupalContext {

/**
* Unpublish the chosed term.
*
* @Then I unpublish term :name
*/
public function iUnpublishTerm($name) {
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')
->loadByProperties(['name' => $name]);

if ($term) {
$term = reset($term);
$term->setUnpublished();
$term->save();
}
else {
throw new \Exception("Term with name '$name' not found");
}
}

}
13 changes: 12 additions & 1 deletion src/FailOnWatchDogTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Frontkom\DrupalBehatDefinitions;

use Drupal\Component\Render\FormattableMarkup;

/**
* Trait to include a step for failing on watchdog messages.
*/
Expand Down Expand Up @@ -44,7 +46,16 @@ public function failStepIfPhpInWatchdog() {
// class will only live the rest of the step, and not until the next
// scenario.
\Drupal::state()->set(self::LAST_WATCHDOG_TIME, time());
throw new \Exception('Found a PHP warning/notice or similar. The message was: ' . $msg->message);
$arguments = [];
try {
$arguments = unserialize($msg->variables);
}
catch (\Throwable $e) {
// Do nothing. We already have an empty array as arguments, and let's
// hope that will be enough?
}
$message = new FormattableMarkup($msg->message, $arguments);
throw new \Exception('Found a PHP warning/notice or similar. The message was: ' . (string) $message);
}
}

Expand Down

0 comments on commit 03ff70a

Please sign in to comment.