View source
<?php
namespace Drupal\recipe\Tests;
class RecipeYieldFormTest extends RecipeWebTestBase {
public static function getInfo() {
return array(
'name' => 'Recipe yield form',
'description' => 'Test the custom yield form in a recipe node.',
'group' => 'Recipe',
);
}
public function testRecipeYieldForm() {
$node_title = $this
->randomName(16);
$yield = 10;
$quantity = 2;
$unit_key = 'cup';
$ingredient_name = $this
->randomName(16);
$edit = array(
'type' => 'recipe',
'title' => $node_title,
'recipe_source' => '',
'recipe_yield' => $yield,
'recipe_yield_unit' => '',
'recipe_description' => array(
'value' => '',
),
'recipe_instructions' => array(
'value' => '',
),
'recipe_notes' => array(
'value' => '',
),
'recipe_preptime' => 1,
'recipe_cooktime' => 1,
'recipe_ingredients' => array(
'ing' => array(
0 => array(
'quantity' => $quantity,
'unit_key' => $unit_key,
'name' => $ingredient_name,
'note' => '',
'weight' => 0,
),
),
),
);
$this
->drupalCreateNode($edit);
$this
->drupalGet('node/1');
$this
->assertFieldById('edit-custom-yield', $yield, 'Found the recipe yield in the custom yield form.');
$this
->assertText(format_string('@quantity @unit', array(
'@quantity' => $quantity,
'@unit' => $this->unitList[$unit_key]['abbreviation'],
)), 'Found the recipe quantity.');
$this
->drupalPost(NULL, NULL, 'Halve');
$this
->assertFieldById('edit-custom-yield', $yield / 2, 'Found the halved recipe yield in the custom yield form.');
$this
->assertText(format_string('@quantity @unit', array(
'@quantity' => $quantity / 2,
'@unit' => $this->unitList[$unit_key]['abbreviation'],
)), 'Found the halved recipe quantity.');
$this
->drupalPost(NULL, NULL, 'Reset');
$this
->assertFieldById('edit-custom-yield', $yield, 'Found the recipe yield in the custom yield form.');
$this
->assertText(format_string('@quantity @unit', array(
'@quantity' => $quantity,
'@unit' => $this->unitList[$unit_key]['abbreviation'],
)), 'Found the recipe quantity.');
$this
->drupalPost(NULL, NULL, 'Double');
$this
->assertFieldById('edit-custom-yield', $yield * 2, 'Found the doubled recipe yield in the custom yield form.');
$this
->assertText(format_string('@quantity @unit', array(
'@quantity' => $quantity * 2,
'@unit' => $this->unitList[$unit_key]['abbreviation'],
)), 'Found the doubled recipe quantity.');
$edit = array(
'custom_yield' => $yield * 3,
);
$this
->drupalPost(NULL, $edit, 'Change');
$this
->assertFieldById('edit-custom-yield', $yield * 3, 'Found the tripled recipe yield in the custom yield form.');
$this
->assertText(format_string('@quantity @unit', array(
'@quantity' => $quantity * 3,
'@unit' => $this->unitList[$unit_key]['abbreviation'],
)), 'Found the tripled recipe quantity.');
}
}