You are here

function MaxlengthTestCase::testField in Maxlength 8

Same name and namespace in other branches
  1. 7.3 maxlength.test \MaxlengthTestCase::testField()

Test fieldapi field.

File

./maxlength.test, line 32
Test maxlength module.

Class

MaxlengthTestCase
@file Test maxlength module.

Code

function testField() {
  $this
    ->drupalLogin($this->admin);
  $edit = array(
    'instance[widget][settings][maxlength_js]' => rand(50, 100),
    'instance[widget][settings][maxlength_js_label]' => $this
      ->randomString(30),
  );
  $this
    ->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/fields/body', $edit, t('Save settings'));
  $this
    ->drupalGet('node/add/' . $this->hyphen_type);

  // Check the maxlength html attributes.
  $elements = $this
    ->xpath('//textarea[@id=:id]', array(
    ':id' => 'edit-body-und-0-value',
  ));
  foreach ($elements[0]
    ->attributes() as $key => $value) {
    switch ($key) {
      case 'class':
        $this
          ->assertTrue(strpos($value, 'maxlength'), 'Take sure the maxlength class is existant');
        break;
      case 'maxlength_js':
        $this
          ->assertTrue($value, 'Take sure that the maxlenght_js attribute is set.');
        break;
      case 'maxlength_js_label':
        $this
          ->assertEqual($edit['instance[widget][settings][maxlength_js_label]'], $value, 'Take sure that the maxlenght_js_label is the defined one.');
        break;
      case 'maxlength':
        $this
          ->assertEqual($edit['instance[widget][settings][maxlength_js]'], $value);
    }
  }
}