link.test 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
  24. $perms = array_keys($perms[array_search('administrator', user_roles())]);
  25. $admin = $this->drupalCreateUser($perms);
  26. $this->drupalLogin($admin);
  27. }
  28. protected function createLinkField($node_type = 'page', $settings = array()) {
  29. $name = strtolower($this->randomName());
  30. $edit = array(
  31. 'fields[_add_new_field][label]' => $name,
  32. 'fields[_add_new_field][field_name]' => $name,
  33. 'fields[_add_new_field][type]' => 'link_field',
  34. 'fields[_add_new_field][widget_type]' => 'link_field',
  35. );
  36. $field_name = 'field_' . $name;
  37. $this->drupalPost('admin/structure/types/manage/' . $node_type . '/fields', $edit, t('Save'));
  38. $this->drupalPost(NULL, array(), t('Save field settings'));
  39. $this->drupalPost(NULL, $settings, t('Save settings'));
  40. // Is field created?
  41. $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
  42. node_types_rebuild();
  43. menu_rebuild();
  44. return $field_name;
  45. }
  46. }