link.crud.test 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * Setup.
  25. */
  26. public function setUp() {
  27. parent::setUp('field_ui', 'link');
  28. }
  29. /**
  30. * Create Field API.
  31. *
  32. * All we're doing here is creating a content type, creating a simple link
  33. * field on that content type.
  34. *
  35. * @codingStandardsIgnoreStart
  36. */
  37. public function testLinkCreateFieldAPI() {
  38. // @codingStandardsIgnoreEnd
  39. $content_type_friendly = $this->randomName(20);
  40. $content_type_machine = strtolower($this->randomName(10));
  41. // Create and login user.
  42. $this->web_user = $this->drupalCreateUser(array(
  43. 'administer content types',
  44. 'administer fields',
  45. ));
  46. $this->drupalLogin($this->web_user);
  47. $this->drupalGet('admin/structure/types');
  48. // Create the content type.
  49. $this->clickLink(t('Add content type'));
  50. $edit = array(
  51. 'name' => $content_type_friendly,
  52. 'type' => $content_type_machine,
  53. );
  54. $this->drupalPost(NULL, $edit, t('Save and add fields'));
  55. $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
  56. // Now add a singleton field.
  57. $single_field_name_friendly = $this->randomName(20);
  58. $single_field_name_machine = strtolower($this->randomName(10));
  59. $edit = array(
  60. 'fields[_add_new_field][label]' => $single_field_name_friendly,
  61. 'fields[_add_new_field][field_name]' => $single_field_name_machine,
  62. 'fields[_add_new_field][type]' => 'link_field',
  63. 'fields[_add_new_field][widget_type]' => 'link_field',
  64. );
  65. $this->drupalPost(NULL, $edit, t('Save'));
  66. // We'll go with the default settings for this run-through.
  67. $this->drupalPost(NULL, array(), t('Save field settings'));
  68. // Using all the default settings, so press the button.
  69. $this->drupalPost(NULL, array(), t('Save settings'));
  70. $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
  71. // Somehow clicking "save" isn't enough, and we have to do a
  72. // node_types_rebuild().
  73. node_types_rebuild();
  74. menu_rebuild();
  75. $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
  76. $this->assertTrue($type_exists, 'The new content type has been created in the database.');
  77. }
  78. }