public function UniqueFieldAjaxTest::testUniqueFieldCustomMessageWithLinkToken in Unique field ajax 2.x
Tests unique field custom message with an added link token.
Throws
\Drupal\Core\Entity\EntityStorageException
\Behat\Mink\Exception\ResponseTextException
File
- tests/
src/ Functional/ UniqueFieldAjaxTest.php, line 181
Class
- UniqueFieldAjaxTest
- Test the field permissions report page.
Namespace
Drupal\Tests\unique_field_ajax\FunctionalCode
public function testUniqueFieldCustomMessageWithLinkToken() {
$num = 5;
foreach ($this->fieldTypes as $field_type) {
$this
->createField($field_type['type'], $field_type['widget'], $field_type['settings']);
$field_name = $this->fieldStorage
->getName();
// Create a random sentence including the label token.
$msg = $this
->createRandomData('sentence');
$msg .= " Here is my field link: %link";
// Enable unique and set a custom message then create a basic node.
$this
->updateThirdPartyFieldSetting('unique', TRUE);
$this
->updateThirdPartyFieldSetting('message', $msg);
// Create a random number of nodes saving the data for later.
$edits = [];
for ($i = 0; $i < $num; $i++) {
$edits[$i] = $this
->createUpdateFieldData($field_name, $field_type['value'], $field_type['effect']);
$this
->itCanSaveField($edits[$i]);
}
// Pick a random edit and see if it tries to link to it.
$edit = $edits[array_rand($edits)];
$msg = str_replace('%link', $edit['title[0][value]'], $msg);
$this
->itCannotSaveField($edit, $msg);
}
}