link.crud.test 2.7 KB

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