public static function ContentProcessorTest::assertCheckboxFieldEqualsOptions in GatherContent 8.4
Assertion for checkbox elements.
1 call to ContentProcessorTest::assertCheckboxFieldEqualsOptions()
- ContentProcessorTest::assertFieldEqualsElement in tests/
src/ Kernel/ ContentProcessorTest.php - Assertion for Drupal field and GC element.
File
- tests/
src/ Kernel/ ContentProcessorTest.php, line 279
Class
- ContentProcessorTest
- Class for testing core node import functionality.
Namespace
Drupal\Tests\gathercontent\KernelCode
public static function assertCheckboxFieldEqualsOptions(array $field, array $options) {
$termIds = array_map(function ($fieldTerm) {
return $fieldTerm['target_id'];
}, $field);
$terms = Term::loadMultiple($termIds);
foreach ($options as $option) {
$termsMatchingThisOption = array_filter($terms, function ($term) use ($option) {
$termOptionIdsMatchingThisOption = array_filter($term
->get('gathercontent_option_ids')
->getValue(), function ($optionId) use ($option) {
return $optionId['value'] === $option['name'];
});
$isSameOptionId = 1 === count($termOptionIdsMatchingThisOption);
$isSameName = $term
->get('name')
->getValue()[0]['value'] == $option['label'];
$isCheckboxTaxonomy = $term
->get('vid')
->getValue()[0]['target_id'] === MockData::CHECKBOX_TAXONOMY_NAME;
return $isSameOptionId && $isSameName && $isCheckboxTaxonomy;
});
if ($option['selected']) {
static::assertEquals(1, count($termsMatchingThisOption), 'Term was not imported correctly.');
}
else {
static::assertEmpty($termsMatchingThisOption, 'Term should not be imported.');
}
}
}