123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- * @file
- * Tests for Menu link module.
- */
- /**
- * Tests for menu link field and formatter.
- */
- class MenuLinkFieldTestCase extends DrupalWebTestCase {
- protected $instance;
- public static function getInfo() {
- return array(
- 'name' => 'Menu link field',
- 'description' => 'Test the creation of menu link fields.',
- 'group' => 'Menu link',
- );
- }
- function setUp() {
- parent::setUp('field_test');
- $web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
- $this->drupalLogin($web_user);
- // Setup a field and instance.
- $this->field_name = drupal_strtolower($this->randomName());
- $this->field = array(
- 'field_name' => $this->field_name,
- 'type' => 'menu_link',
- );
- field_create_field($this->field);
- $this->instance = array(
- 'field_name' => $this->field_name,
- 'entity_type' => 'test_entity',
- 'bundle' => 'test_bundle',
- 'setings' => array(
- 'menu_options' => array('main-menu'),
- ),
- 'widget' => array(
- 'type' => 'menu_link_default',
- ),
- 'display' => array(
- 'full' => array(
- 'type' => 'menu_link_link',
- ),
- ),
- );
- field_create_instance($this->instance);
- }
- /**
- * Test menu link field validation.
- */
- 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'));
- }
- }
- }
|