link.crud.test 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $this->web_user = $this->drupalCreateUser(array('administer content types'));
  27. $this->drupalLogin($this->web_user);
  28. $this->drupalGet('admin/structure/types');
  29. // Create the content type.
  30. $this->clickLink(t('Add content type'));
  31. $edit = array(
  32. 'name' => $content_type_friendly,
  33. 'type' => $content_type_machine,
  34. );
  35. $this->drupalPost(NULL, $edit, t('Save and add fields'));
  36. $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
  37. // Now add a singleton field.
  38. $single_field_name_friendly = $this->randomName(20);
  39. $single_field_name_machine = strtolower($this->randomName(10));
  40. $edit = array(
  41. 'fields[_add_new_field][label]' => $single_field_name_friendly,
  42. 'fields[_add_new_field][field_name]' => $single_field_name_machine,
  43. 'fields[_add_new_field][type]' => 'link_field',
  44. 'fields[_add_new_field][widget_type]' => 'link_field',
  45. );
  46. $this->drupalPost(NULL, $edit, t('Save'));
  47. // We'll go with the default settings for this run-through.
  48. $this->drupalPost(NULL, array(), t('Save field settings'));
  49. // Using all the default settings, so press the button.
  50. $this->drupalPost(NULL, array(), t('Save settings'));
  51. $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
  52. // Somehow clicking "save" isn't enough, and we have to do a
  53. // node_types_rebuild().
  54. node_types_rebuild();
  55. menu_rebuild();
  56. $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
  57. $this->assertTrue($type_exists, 'The new content type has been created in the database.');
  58. }
  59. }