IngredientSettingsTest.php in Recipe 8.2
File
modules/ingredient/tests/src/Kernel/IngredientSettingsTest.php
View source
<?php
namespace Drupal\Tests\ingredient\Kernel;
use Drupal\ingredient\Entity\Ingredient;
use Drupal\KernelTests\KernelTestBase;
class IngredientSettingsTest extends KernelTestBase {
protected static $modules = [
'ingredient',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('ingredient');
$this
->installConfig('ingredient');
}
public function testIngredientNormalization() {
$config = $this->container
->get('config.factory')
->getEditable('ingredient.settings');
$this
->assertEquals('0', $config
->get('ingredient_name_normalize'));
$first_ingredient = Ingredient::create([
'name' => 'TeSt InGrEdIeNt 1',
]);
$first_ingredient
->save();
$this
->assertEquals('TeSt InGrEdIeNt 1', $first_ingredient
->label());
$config
->set('ingredient_name_normalize', '1')
->save();
$second_ingredient = Ingredient::create([
'name' => 'TeSt InGrEdIeNt 2',
]);
$second_ingredient
->save();
$this
->assertEquals('test ingredient 2', $second_ingredient
->label());
$third_ingredient = Ingredient::create([
'name' => 'TeSt InGrEdIeNt 3 ®',
]);
$third_ingredient
->save();
$this
->assertEquals('TeSt InGrEdIeNt 3 ®', $third_ingredient
->label());
$config
->set('ingredient_name_normalize', '0')
->save();
$fourth_ingredient = Ingredient::create([
'name' => 'TeSt InGrEdIeNt 4',
]);
$fourth_ingredient
->save();
$this
->assertEquals('TeSt InGrEdIeNt 4', $fourth_ingredient
->label());
}
}