You are here

public function RecipeImportFormsTest::testRecipeMlMultipleImport in Recipe 7

Same name and namespace in other branches
  1. 7.2 src/Tests/RecipeImportFormsTest.php \Drupal\recipe\Tests\RecipeImportFormsTest::testRecipeMlMultipleImport()

Test import recipes in recipeML format with the multiple import form.

File

src/Tests/RecipeImportFormsTest.php, line 172

Class

RecipeImportFormsTest
Tests the single and multiple recipe import forms.

Namespace

Drupal\recipe\Tests

Code

public function testRecipeMlMultipleImport() {

  // Check for the recipeML form link on the bulk import page.
  $this
    ->drupalGet('admin/structure/recipe/import_multi');
  $this
    ->assertLink('recipeML', 0);

  // Import the recipeML test file using the multiple import form.
  $edit = array(
    'files[recipe_import_file]' => drupal_get_path('module', 'recipe') . '/tests/recipe_recipeml_test.xml',
  );
  $this
    ->drupalPost('admin/structure/recipe/import_multi/recipeml', $edit, t('Import'));
  $this
    ->assertText(t('The attached file was successfully uploaded'));

  // Verify that the first recipe was imported correctly.
  $this
    ->drupalGet('node/1');
  $this
    ->assertText('Salt water');
  $this
    ->assertFieldById('edit-custom-yield', 1, 'Found the recipe yield in the custom yield form.');
  $this
    ->assertText('Servings', 'Found the recipe yield unit.');
  $this
    ->assertText('John Doe', 'Found the recipe source.');
  $this
    ->assertText('2 c', 'Found ingredent 0 quantity and unit.');
  $this
    ->assertText('water (cold)', 'Found ingredient 0 name and note.');
  $this
    ->assertText('1 T', 'Found ingredient 1 quantity and unit.');
  $this
    ->assertText('salt', 'Found ingredient 1 name.');
  $this
    ->assertText('Combine water and salt in a glass.', 'Found the first instruction.');
  $this
    ->assertText('Stir.', 'Found the second instruction.');
  $this
    ->assertText('Do not consume!', 'Found the recipe notes.');

  // Verify that the second recipe was imported correctly.
  $this
    ->drupalGet('node/2');
  $this
    ->assertText('Hard-boiled eggs');
  $this
    ->assertFieldById('edit-custom-yield', 2, 'Found the recipe yield in the custom yield form.');
  $this
    ->assertText('Servings', 'Found the recipe yield unit.');
  $this
    ->assertText('Jane Doe', 'Found the recipe source.');
  $this
    ->assertText('2 q', 'Found ingredent 0 quantity and unit.');
  $this
    ->assertText('water (hot)', 'Found ingredient 0 name and note.');
  $this
    ->assertRaw('<div class="quantity-unit" property="schema:amount"> 4 </div>', 'Found ingredient 1 quantity with no unit.');
  $this
    ->assertText('eggs', 'Found ingredient 1 name.');
  $this
    ->assertText('Boil the water.', 'Found the first instruction.');
  $this
    ->assertText('Put the eggs in the boiling water for 5 minutes.', 'Found the second instruction.');
  $this
    ->assertText('Allow the eggs to cool.', 'Found the third instruction.');
  $this
    ->assertText('Break the shells and consume.', 'Found the fourth instruction.');
}