protected function UniqueFieldAjaxBase::itCanSaveField in Unique field ajax 2.x
Runs a test to see if a field can be saved.
Parameters
array $edit: Edit data.
int|null $nid: Node id.
bool $debug: Adds debug information.
Return value
int Saved/updated node id.
Throws
\Behat\Mink\Exception\ResponseTextException
15 calls to UniqueFieldAjaxBase::itCanSaveField()
- UniqueFieldAjaxBase::itCanUpdateField in tests/
src/ Functional/ UniqueFieldAjaxBase.php - An Alias method for save field, requiring an nid.
- UniqueFieldAjaxLanguageTest::testUniqueFieldPerLang in tests/
src/ Functional/ UniqueFieldAjaxLanguageTest.php - Tests unique field per language.
- UniqueFieldAjaxLanguageTest::testUniqueTitlePerLang in tests/
src/ Functional/ UniqueFieldAjaxLanguageTest.php - Tests unique title per language.
- UniqueFieldAjaxTest::testUniqueFieldAllowsSavingSameField in tests/
src/ Functional/ UniqueFieldAjaxTest.php - Test if field unique is enabled you can still save the same node.
- UniqueFieldAjaxTest::testUniqueFieldCustomMessage in tests/
src/ Functional/ UniqueFieldAjaxTest.php - Tests unique field custom message.
File
- tests/
src/ Functional/ UniqueFieldAjaxBase.php, line 199
Class
- UniqueFieldAjaxBase
- The base testing class for unique_field_ajax.
Namespace
Drupal\Tests\unique_field_ajax\FunctionalCode
protected function itCanSaveField(array $edit, int $nid = NULL, bool $debug = FALSE) : int {
$title = $edit['title[0][value]'];
$method = $this
->getSaveMethod($nid);
$this
->drupalPostForm($method, $edit, t('Save'));
preg_match('|node/(\\d+)|', $this
->getUrl(), $match);
if (!empty($match)) {
$id = $match[1];
if (!$nid) {
$this
->assertSession()
->pageTextContains(t('@contentType @title has been created.', [
'@title' => $title,
'@contentType' => $this->contentTypeName,
]));
}
else {
if ($debug) {
var_dump($this
->getSession()
->getPage()
->getHtml());
}
$this
->assertSession()
->pageTextContains(t('@contentType @title has been updated.', [
'@title' => $title,
'@contentType' => $this->contentTypeName,
]));
}
return (int) $id;
}
else {
var_dump($this
->getUrl());
var_dump($this
->getSession()
->getPage()
->getHtml());
static::fail(t('Could not extract entity id from url'));
}
return -1;
}