Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing integrations #39

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public function assertNodeByTitleAndLanguage($contentType, $title, $language)
*
* @When I examine the :termName term in the :vocabulary( vocabulary)
*
* @param string $termName A Drupal taxonomy term name.
* @param string $termName A Drupal taxonomy term name.
* @param string $vocabulary The machine name of a Drupal taxonomy vocabulary.
*
* @throws \Exception
*
* @return void
*/
public function assertTermByName($termName, $vocabulary)
{
throw new NotUpdatedException('Method not yet updated for Drupal 8.');

$term = $this->findTermByName($termName, $vocabulary);

$this->currentEntity = $term;
Expand All @@ -106,6 +106,28 @@ public function assertTermByName($termName, $vocabulary)
}//end assertTermByName()


/**
* Verify field and property values of a taxonomy term entity.
*
* @When I examine the term with machine name :machineName in the :vocabulary( vocabulary)
*
* @param string $machineName A Drupal taxonomy term machine name.
* @param string $vocabulary The machine name of a Drupal taxonomy vocabulary.
*
* @throws \Exception
*
* @return void
*/
public function assertTermByMachineName($machineName, $vocabulary)
{
$term = $this->findTermByMachineName($machineName, $vocabulary);

$this->currentEntity = $term;
$this->currentEntityType = 'taxonomy_term';

}//end assertTermByName()


/**
* Verify field and property values of a block entity.
*
Expand Down Expand Up @@ -686,6 +708,23 @@ public function assertEntityFieldValueLink($field, $value)

}//end assertEntityFieldValueLink()

/**
* Test a text field for a partial string.
*
* @param \Drupal\Core\Field\FieldItemList $field
* A Drupal field object.
* @param mixed $value
* The value to look for.
*
* @throws \Exception when value was not found.
*
* @return void
*/
public function assertEntityFieldValueTextWithSummary($field, $value)
{
// Re-use the assertEntityFieldVallueTextLong for now.
return $this->assertEntityFieldValueTextLong($field, $value);
}

/**
* Test a text field for a partial string.
Expand Down Expand Up @@ -722,6 +761,8 @@ public function assertEntityFieldValueTextLong($field, $value)
return;
}
}

throw new \Exception(sprintf('Field value of "%s" does not contain expected value "%s"', $field_value, $value));
}//end assertEntityFieldValueTextLong()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,70 @@ protected function getNodeByTitle($contentType, $title)
* @param string $termName A Drupal taxonomy term name.
* @param string $vocabulary The machine name of a Drupal taxonomy vocabulary.
*
* @return stdclass
* @return Drupal\taxonomy\TermInterface
* The Drupal term object, if it exists.
*/
public function findTermByName($termName, $vocabulary)
{
throw new NotUpdatedException('Method not yet updated for Drupal 8.');

$query = new \EntityFieldQuery();
/**
* @var $query \Drupal\Core\Entity\Query\QueryInterface
*/
$query = \Drupal::entityQuery('taxonomy_term');

$entities = $query->entityCondition('entity_type', 'taxonomy_term')
->entityCondition('bundle', $vocabulary)
->propertyCondition('name', $termName)
$entities = $query
->condition('name', $termName)
->condition('vid', $vocabulary)
->execute();

if (empty($entities['taxonomy_term']) === false && count($entities['taxonomy_term']) === 1) {
$id = key($entities['taxonomy_term']);
return taxonomy_term_load($id);
} else if (empty($entities['taxonomy_term']) === false && count($entities['taxonomy_term']) > 1) {
throw new \Exception(sprintf('Found more than one "%s" term entitled "%s"', $vocabulary, $termName));
if (count($entities) === 1) {
$term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$tid = array_shift($entities);

$term = $term_storage->load($tid);

return $term;
} else if (count($entities) > 1) {
throw new \Exception(sprintf('Found more than one term with name "%s"', $termName));
} else {
throw new \Exception(sprintf('No "%s" term entitled "%s" exists', $vocabulary, $termName));
throw new \Exception(sprintf('No term with name "%s" exists', $termName));
}

}//end findTermByName()

/**
* Get a term object by machine name and vocabulary.
*
* @param string $machineName A Drupal taxonomy term machine name.
* @param string $vocabulary The machine name of a Drupal taxonomy vocabulary.
*
* @return Drupal\taxonomy\TermInterface
* The Drupal term object, if it exists.
*/
public function findTermByMachineName($machineName, $vocabulary)
{
/**
* @var $query \Drupal\Core\Entity\Query\QueryInterface
*/
$query = \Drupal::entityQuery('taxonomy_term');

$entities = $query
->condition('machine_name', $machineName)
->condition('vid', $vocabulary)
->execute();

if (count($entities) === 1) {
$term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$tid = array_shift($entities);

$term = $term_storage->load($tid);

return $term;
} else if (count($entities) > 1) {
throw new \Exception(sprintf('Found more than one term with machine name "%s"', $machineName));
} else {
throw new \Exception(sprintf('No term with machine name "%s" exists', $machineName));
}
}//end findTermByMachineName()


/**
* Get block object by its description.
Expand Down