You are here

function MenuLinkFieldTestCase::testMenuLinkFieldValidation in Menu Link (Field) 7

Test menu link field validation.

File

./menu_link.test, line 57
Tests for Menu link module.

Class

MenuLinkFieldTestCase
Tests for menu link field and formatter.

Code

function testMenuLinkFieldValidation() {

  // Test valid and invalid values with field_attach_validate().
  $langcode = LANGUAGE_NONE;
  $entity = field_test_create_stub_entity();
  $entity->uri = array(
    'path' => 'test',
    'options' => array(),
  );
  $entity->{$this->field_name}[$langcode][0] = array(
    'menu_name' => 'main-menu',
    'plid' => 0,
    'link_title' => 'Title',
  );
  try {
    field_attach_validate('test_entity', $entity);
    $this
      ->pass(t('Correct menu link does not cause validation error'));
  } catch (FieldValidationException $e) {
    $this
      ->fail(t('Correct menu link does not cause validation error'));
  }
  $entity = field_test_create_stub_entity();
  $entity->uri = array(
    'path' => 'test',
    'options' => array(),
  );
  $entity->{$this->field_name}[$langcode][0] = array(
    'menu_name' => 'nonexistant-menu',
    'plid' => 0,
    'link_title' => 'Title',
  );
  try {
    field_attach_validate('test_entity', $entity);
    $this
      ->fail(t('Menu link with an invalid menu name causes validation error'));
  } catch (FieldValidationException $e) {
    $this
      ->pass(t('Menu link with an invalid menu name causes validation error'));
  }
}