link.test 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. * {@inheritdoc}
  23. */
  24. public function setUp(array $modules = array()) {
  25. $modules[] = 'field_ui';
  26. $modules[] = 'link';
  27. parent::setUp($modules);
  28. $this->web_user = $this->drupalCreateUser($this->permissions);
  29. $this->drupalLogin($this->web_user);
  30. }
  31. /**
  32. * Create Link Field.
  33. */
  34. protected function createLinkField($node_type = 'page', $settings = array()) {
  35. $name = strtolower($this->randomName());
  36. $edit = array(
  37. 'fields[_add_new_field][label]' => $name,
  38. 'fields[_add_new_field][field_name]' => $name,
  39. 'fields[_add_new_field][type]' => 'link_field',
  40. 'fields[_add_new_field][widget_type]' => 'link_field',
  41. );
  42. $field_name = 'field_' . $name;
  43. $this->drupalPost('admin/structure/types/manage/' . $node_type . '/fields', $edit, t('Save'));
  44. $this->drupalPost(NULL, array(), t('Save field settings'));
  45. $this->drupalPost(NULL, $settings, t('Save settings'));
  46. // Is field created?
  47. $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
  48. node_types_rebuild();
  49. menu_rebuild();
  50. return $field_name;
  51. }
  52. }