function DrupalRenderTestCase::testDrupalRenderFormElements
Test rendering form elements without passing through form_builder().
File
-
modules/
simpletest/ tests/ common.test, line 2286
Class
- DrupalRenderTestCase
- Tests for drupal_render().
Code
function testDrupalRenderFormElements() {
// Define a series of form elements.
$element = array(
'#type' => 'button',
'#value' => $this->randomName(),
);
$this->assertRenderedElement($element, '//input[@type=:type]', array(
':type' => 'submit',
));
$element = array(
'#type' => 'textfield',
'#title' => $this->randomName(),
'#value' => $this->randomName(),
);
$this->assertRenderedElement($element, '//input[@type=:type]', array(
':type' => 'text',
));
$element = array(
'#type' => 'password',
'#title' => $this->randomName(),
);
$this->assertRenderedElement($element, '//input[@type=:type]', array(
':type' => 'password',
));
$element = array(
'#type' => 'textarea',
'#title' => $this->randomName(),
'#value' => $this->randomName(),
);
$this->assertRenderedElement($element, '//textarea');
$element = array(
'#type' => 'radio',
'#title' => $this->randomName(),
'#value' => FALSE,
);
$this->assertRenderedElement($element, '//input[@type=:type]', array(
':type' => 'radio',
));
$element = array(
'#type' => 'checkbox',
'#title' => $this->randomName(),
);
$this->assertRenderedElement($element, '//input[@type=:type]', array(
':type' => 'checkbox',
));
$element = array(
'#type' => 'select',
'#title' => $this->randomName(),
'#options' => array(
0 => $this->randomName(),
1 => $this->randomName(),
),
);
$this->assertRenderedElement($element, '//select');
$element = array(
'#type' => 'file',
'#title' => $this->randomName(),
);
$this->assertRenderedElement($element, '//input[@type=:type]', array(
':type' => 'file',
));
$element = array(
'#type' => 'item',
'#title' => $this->randomName(),
'#markup' => $this->randomName(),
);
$this->assertRenderedElement($element, '//div[contains(@class, :class) and contains(., :markup)]/label[contains(., :label)]', array(
':class' => 'form-type-item',
':markup' => $element['#markup'],
':label' => $element['#title'],
));
$element = array(
'#type' => 'hidden',
'#title' => $this->randomName(),
'#value' => $this->randomName(),
);
$this->assertRenderedElement($element, '//input[@type=:type]', array(
':type' => 'hidden',
));
$element = array(
'#type' => 'link',
'#title' => $this->randomName(),
'#href' => $this->randomName(),
'#options' => array(
'absolute' => TRUE,
),
);
$this->assertRenderedElement($element, '//a[@href=:href and contains(., :title)]', array(
':href' => url($element['#href'], array(
'absolute' => TRUE,
)),
':title' => $element['#title'],
));
$element = array(
'#type' => 'fieldset',
'#title' => $this->randomName(),
);
$this->assertRenderedElement($element, '//fieldset/legend[contains(., :title)]', array(
':title' => $element['#title'],
));
$element['item'] = array(
'#type' => 'item',
'#title' => $this->randomName(),
'#markup' => $this->randomName(),
);
$this->assertRenderedElement($element, '//fieldset/div/div[contains(@class, :class) and contains(., :markup)]', array(
':class' => 'form-type-item',
':markup' => $element['item']['#markup'],
));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.