link.crud.test 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. //$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
  38. // Now add a singleton field.
  39. $single_field_name_friendly = $this->randomName(20);
  40. $single_field_name_machine = strtolower($this->randomName(10));
  41. $edit = array (
  42. 'fields[_add_new_field][label]' => $single_field_name_friendly,
  43. 'fields[_add_new_field][field_name]' => $single_field_name_machine,
  44. 'fields[_add_new_field][type]' => 'link_field',
  45. 'fields[_add_new_field][widget_type]' => 'link_field',
  46. );
  47. $this->drupalPost(NULL, $edit, t('Save'));
  48. // We'll go with the default settings for this run-through.
  49. $this->drupalPost(NULL, array(), t('Save field settings'));
  50. // Using all the default settings, so press the button.
  51. $this->drupalPost(NULL, array(), t('Save settings'));
  52. $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
  53. // Somehow clicking "save" isn't enough, and we have to do a
  54. // node_types_rebuild().
  55. node_types_rebuild();
  56. menu_rebuild();
  57. $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
  58. $this->assertTrue($type_exists, 'The new content type has been created in the database.');
  59. /*$table_schema = drupal_get_schema();
  60. $this->assertEqual(1, 1, print_r(array_keys($table_schema), TRUE));
  61. // Check the schema - the values should be in the per-type table.
  62. $this->assertSchemaMatchesTables(array(
  63. 'per_type' => array(
  64. $this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),
  65. ),
  66. ));*/
  67. }
  68. }