link.crud.test 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Basic CRUD simpletests for the link module, based off of content.crud.test in CCK.
  5. */
  6. class LinkContentCrudTest extends DrupalWebTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Link CRUD - Basic API tests',
  10. 'description' => 'Tests the field CRUD (create, read, update, delete) API.',
  11. 'group' => 'Link',
  12. );
  13. }
  14. function setUp() {
  15. parent::setUp('field_ui', 'link');
  16. }
  17. /**
  18. * All we're doing here is creating a content type, creating a simple link field
  19. * on that content type.
  20. */
  21. function testLinkCreateFieldAPI() {
  22. $content_type_friendly = $this->randomName(20);
  23. $content_type_machine = strtolower($this->randomName(10));
  24. $title = $this->randomName(20);
  25. // Create and login user.
  26. $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
  27. $perms = array_keys($perms[array_search('administrator', user_roles())]);
  28. $admin = $this->drupalCreateUser($perms);
  29. $this->drupalLogin($admin);
  30. $this->drupalGet('admin/structure/types');
  31. // Create the content type.
  32. $this->clickLink(t('Add content type'));
  33. $edit = array(
  34. 'name' => $content_type_friendly,
  35. 'type' => $content_type_machine,
  36. );
  37. $this->drupalPost(NULL, $edit, t('Save and add fields'));
  38. $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
  39. // Now add a singleton field.
  40. $single_field_name_friendly = $this->randomName(20);
  41. $single_field_name_machine = strtolower($this->randomName(10));
  42. $edit = array(
  43. 'fields[_add_new_field][label]' => $single_field_name_friendly,
  44. 'fields[_add_new_field][field_name]' => $single_field_name_machine,
  45. 'fields[_add_new_field][type]' => 'link_field',
  46. 'fields[_add_new_field][widget_type]' => 'link_field',
  47. );
  48. $this->drupalPost(NULL, $edit, t('Save'));
  49. // We'll go with the default settings for this run-through.
  50. $this->drupalPost(NULL, array(), t('Save field settings'));
  51. // Using all the default settings, so press the button.
  52. $this->drupalPost(NULL, array(), t('Save settings'));
  53. $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
  54. // Somehow clicking "save" isn't enough, and we have to do a
  55. // node_types_rebuild().
  56. node_types_rebuild();
  57. menu_rebuild();
  58. $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
  59. $this->assertTrue($type_exists, 'The new content type has been created in the database.');
  60. }
  61. }