You are here

public function IngredientSettingsTest::testIngredientFieldSettings in Recipe 7.2

Tests ingredient field settings.

File

src/Tests/IngredientSettingsTest.php, line 39

Class

IngredientSettingsTest
Tests the functionality of the ingredient field settings.

Namespace

Drupal\recipe\Tests

Code

public function testIngredientFieldSettings() {

  // Create the field.
  $field = array(
    'cardinality' => -1,
    'field_name' => 'ingredient',
    'module' => 'recipe',
    'settings' => array(
      'ingredient_name_normalize' => 1,
    ),
    'type' => 'ingredient_reference',
  );
  field_create_field($field);

  // Create the field instance.
  $instance = array(
    'bundle' => 'test_bundle',
    'display' => array(
      'default' => array(
        'label' => 'above',
        'module' => 'recipe',
        'settings' => array(
          'fraction_format' => '{%d }%d⁄%d',
          'unit_abbreviation' => 0,
        ),
        'type' => 'recipe_ingredient_default',
        'weight' => 0,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'ingredient',
    'label' => 'Ingredients',
    'widget' => array(
      'active' => 0,
      'module' => 'recipe',
      'settings' => array(
        'default_unit' => 'cup',
      ),
      'type' => 'recipe_ingredient_autocomplete',
      'weight' => 0,
    ),
  );
  field_create_instance($instance);
  $edit = array(
    'title' => $this
      ->randomName(16),
    'ingredient[' . LANGUAGE_NONE . '][0][quantity]' => 4,
    'ingredient[' . LANGUAGE_NONE . '][0][unit_key]' => 'us gallon',
    'ingredient[' . LANGUAGE_NONE . '][0][name]' => 'TeSt InGrEdIeNt',
    'ingredient[' . LANGUAGE_NONE . '][0][note]' => '',
  );
  $this
    ->drupalGet('node/add/test_bundle');

  // Assert that the default element, 'cup', is selected.
  $this
    ->assertOptionSelected('edit-ingredient-und-0-unit-key', 'cup', 'The default unit was selected.');

  // Post the values to the node form.
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Assert that the normalized ingredient name can be found on the node page.
  $this
    ->assertText('test ingredient', 'Found the normalized ingredient name.');
}