link.test 1.6 KB

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