public function EntityAutocompleteWebTestCase::testAutocompleteElement in Entity Autocomplete 7
Tests FAPI element.
File
- tests/
entity_autocomplete.test, line 162 - Tests suite for Entity Autocomplete module.
Class
- EntityAutocompleteWebTestCase
- Performs functional tests on advanced functionalities, such as administrative UI, etc.
Code
public function testAutocompleteElement() {
foreach (array(
'page',
'article',
) as $bundle) {
if (!node_type_get_type($bundle)) {
$this
->drupalCreateContentType(array(
'type' => $bundle,
'name' => ucfirst($bundle),
));
}
}
//end foreach
$node = $this
->drupalCreateNode(array(
'type' => 'page',
'uid' => $this->author->uid,
));
$label = entity_autocomplete_get_label($node->title, $node->nid);
$unexisting_nid = 1;
while ($node->nid == $unexisting_nid) {
$unexisting_nid++;
}
// Check element in the form.
$this
->drupalGet('entity_autocomplete_test/node');
$this
->assertFieldByName('entity_autocomplete', '');
$this
->drupalGet("entity_autocomplete_test/node/{$node->nid}");
$this
->assertFieldByName('entity_autocomplete', $label, t('Field value is properly built when entity exists.'));
$this
->drupalGet("entity_autocomplete_test/node/{$unexisting_nid}");
$this
->assertFieldByName('entity_autocomplete', $unexisting_nid, t('Field value is kept raw when entity does not exist.'));
// Check element validation.
$this
->drupalPost('entity_autocomplete_test/node', array(
'entity_autocomplete' => $unexisting_nid,
), t('Test'));
$this
->assertRaw(t('The specified entity %value does not match requirements.', array(
'%value' => $unexisting_nid,
)), t('Unexisting entity ID throws an error.'));
$this
->drupalPost('entity_autocomplete_test/bundle/node/article', array(
'entity_autocomplete' => $node->nid,
), t('Test'));
$this
->assertRaw(t('The specified entity %value does not match requirements.', array(
'%value' => $label,
)), t('Existing entity ID for wrong bundle throws an error.'));
// Check element submission.
$this
->drupalPost('entity_autocomplete_test/node', array(
'entity_autocomplete' => $node->nid,
), t('Test'));
$this
->assertText(t('The form was successfully submitted. Field value is: @value.', array(
'@value' => $node->nid,
)));
}