View source
<?php
namespace Drupal\recipe\Tests;
class IngredientSettingsTest extends RecipeWebTestBase {
public static function getInfo() {
return array(
'name' => 'Recipe ingredient settings',
'description' => 'Ensure that the ingredient field settings function properly.',
'group' => 'Recipe',
);
}
public function setUp() {
parent::setUp(array(
'recipe',
));
$this
->drupalCreateContentType(array(
'type' => 'test_bundle',
));
$this->adminUser = $this
->drupalCreateUser(array(
'create test_bundle content',
'administer site configuration',
));
$this
->drupalLogin($this->adminUser);
}
public function testIngredientFieldSettings() {
$field = array(
'cardinality' => -1,
'field_name' => 'ingredient',
'module' => 'recipe',
'settings' => array(
'ingredient_name_normalize' => 1,
),
'type' => 'ingredient_reference',
);
field_create_field($field);
$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');
$this
->assertOptionSelected('edit-ingredient-und-0-unit-key', 'cup', 'The default unit was selected.');
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText('test ingredient', 'Found the normalized ingredient name.');
}
}