link.test 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @file
  4. * Link base test file - contains common functions for testing links.
  5. */
  6. class LinkBaseTestClass extends DrupalWebTestCase {
  7. protected $permissions = array(
  8. 'access content',
  9. 'administer content types',
  10. 'administer nodes',
  11. 'administer filters',
  12. 'access comments',
  13. 'post comments',
  14. 'access administration pages',
  15. 'create page content',
  16. );
  17. function setUp() {
  18. $modules = func_get_args();
  19. $modules = (isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules);
  20. $modules[] = 'field_ui';
  21. $modules[] = 'link';
  22. parent::setUp($modules);
  23. $this->web_user = $this->drupalCreateUser($this->permissions);
  24. $this->drupalLogin($this->web_user);
  25. }
  26. protected function createLinkField($node_type = 'page', $settings = array()) {
  27. $name = strtolower($this->randomName());
  28. $edit = array(
  29. 'fields[_add_new_field][label]' => $name,
  30. 'fields[_add_new_field][field_name]' => $name,
  31. 'fields[_add_new_field][type]' => 'link_field',
  32. 'fields[_add_new_field][widget_type]' => 'link_field',
  33. );
  34. $field_name = 'field_' . $name;
  35. $this->drupalPost('admin/structure/types/manage/' . $node_type . '/fields', $edit, t('Save'));
  36. $this->drupalPost(NULL, array(), t('Save field settings'));
  37. $this->drupalPost(NULL, $settings, t('Save settings'));
  38. // Is field created?
  39. $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
  40. node_types_rebuild();
  41. menu_rebuild();
  42. return $field_name;
  43. }
  44. }