public function RecipeNodeTest::testPseudoFields in Recipe 8.2
Tests the visibility of the Recipe pseudo-fields.
File
- tests/
src/ Functional/ RecipeNodeTest.php, line 114
Class
- RecipeNodeTest
- Tests the functionality of the Recipe content type and Recipe blocks.
Namespace
Drupal\Tests\recipe\FunctionalCode
public function testPseudoFields() {
// Create a node with values in all of the pseudo-field sub-fields.
$edit = [
'title[0][value]' => $this
->randomMachineName(16),
'recipe_yield_amount[0][value]' => 1,
'recipe_yield_unit[0][value]' => $this
->randomMachineName(16),
'recipe_prep_time[0][value]' => 1,
'recipe_cook_time[0][value]' => 1,
];
$this
->drupalPostForm('node/add/recipe', $edit, 'Save');
// Verify that the pseudo-fields are shown on the node view.
$this
->assertSession()
->pageTextContains('Yield');
$this
->assertSession()
->pageTextContains('Total time');
// Create a node with no value in the yield_amount and a value in only one
// time field.
$edit = [
'title[0][value]' => $this
->randomMachineName(16),
'recipe_yield_unit[0][value]' => $this
->randomMachineName(16),
'recipe_cook_time[0][value]' => 1,
];
$this
->drupalPostForm('node/add/recipe', $edit, 'Save');
// Verify that the pseudo-fields are not shown on the node view.
$this
->assertSession()
->pageTextNotContains('Yield');
$this
->assertSession()
->pageTextNotContains('Total time');
// Create a node with no values in time fields.
$edit = [
'title[0][value]' => $this
->randomMachineName(16),
];
$this
->drupalPostForm('node/add/recipe', $edit, 'Save');
// Verify that the pseudo-fields are not shown on the node view.
$this
->assertSession()
->pageTextNotContains('Yield');
$this
->assertSession()
->pageTextNotContains('Total time');
// Hide the pseudo-fields. Verify that they can't be found on the first
// node that we created, on which it was already verified that they
// appeared.
/** @var \Drupal\Core\Entity\EntityDisplayRepository $repository */
$repository = \Drupal::service('entity_display.repository');
$repository
->getViewDisplay('node', 'recipe', 'default')
->removeComponent('recipe_yield')
->removeComponent('recipe_total_time')
->save();
$this
->drupalGet('node/1');
$this
->assertSession()
->pageTextNotContains('Yield');
$this
->assertSession()
->pageTextNotContains('Total time');
}