You are here

public function RecipeTranslationTest::testRecipeTranslation in Recipe 7

Tests translation of recipe data.

File

src/Tests/RecipeTranslationTest.php, line 65

Class

RecipeTranslationTest
Tests translating Recipe nodes.

Namespace

Drupal\recipe\Tests

Code

public function testRecipeTranslation() {

  // Create a recipe node.
  $node_title = $this
    ->randomName(16);
  $source = $this
    ->randomName(16);
  $yield = 10;
  $yield_unit = $this
    ->randomName(10);
  $description = $this
    ->randomName(32);
  $instructions = $this
    ->randomName(32);
  $notes = $this
    ->randomName(32);
  $preptime = 30;
  $cooktime = 90;
  $quantity = 2;
  $unit_key = 'cup';
  $ingredient_name = $this
    ->randomName(16);
  $ingredient_note = $this
    ->randomName(16);
  $edit = array(
    'type' => 'recipe',
    'title' => $node_title,
    'recipe_source' => $source,
    'recipe_yield' => $yield,
    'recipe_yield_unit' => $yield_unit,
    'recipe_description' => array(
      'value' => $description,
    ),
    'recipe_instructions' => array(
      'value' => $instructions,
    ),
    'recipe_notes' => array(
      'value' => $notes,
    ),
    'recipe_preptime' => $preptime,
    'recipe_cooktime' => $cooktime,
    'recipe_ingredients' => array(
      'ing' => array(
        0 => array(
          'quantity' => $quantity,
          'unit_key' => $unit_key,
          'name' => $ingredient_name,
          'note' => $ingredient_note,
          'weight' => 0,
        ),
      ),
    ),
    'language' => 'en',
  );
  $this
    ->drupalCreateNode($edit);

  // Verify that the node was created and that the translation link exists.
  $this
    ->drupalGet('node/1');
  $this
    ->assertLink('Translate', 0, 'Found the translate link.');
  $this
    ->clickLink('Translate', 0);
  $this
    ->assertLink('add translation', 0, 'Found the add translation link.');
  $this
    ->clickLink('add translation', 0);

  // Verify that the translation form is populated with the source values.
  $this
    ->assertFieldById('edit-recipe-description-value', $description, 'Found the source description.');
  $this
    ->assertFieldById('edit-recipe-yield-unit', $yield_unit, 'Found the source yield units.');
  $this
    ->assertFieldById('edit-recipe-yield', $yield, 'Found the source yield.');
  $this
    ->assertFieldById('edit-recipe-ingredients-ing-0-quantity', $quantity, 'Found the source ingredient quantity.');
  $this
    ->assertFieldById('edit-recipe-ingredients-ing-0-unit-key', $unit_key, 'Found the source ingredient unit key.');
  $this
    ->assertFieldById('edit-recipe-ingredients-ing-0-name', $ingredient_name, 'Found the source ingredient name.');
  $this
    ->assertFieldById('edit-recipe-ingredients-ing-0-note', $ingredient_note, 'Found the source ingredient note.');
  $this
    ->assertFieldById('edit-recipe-source', $source, 'Found the source source.');
  $this
    ->assertFieldById('edit-recipe-instructions-value', $instructions, 'Found the source instructions.');
  $this
    ->assertFieldById('edit-recipe-notes-value', $notes, 'Found the source notes.');
  $this
    ->assertFieldById('edit-recipe-preptime', $preptime, 'Found the source prep time.');
  $this
    ->assertFieldById('edit-recipe-cooktime', $cooktime, 'Found the source cook time.');
}