link.crud.test 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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'); // was views?
  16. //$this->loginWithPermissions();
  17. }
  18. /**
  19. * All we're doing here is creating a content type, creating a simple link field
  20. * on that content type.
  21. */
  22. function testLinkCreateFieldAPI() {
  23. $content_type_friendly = $this->randomName(20);
  24. $content_type_machine = strtolower($this->randomName(10));
  25. $title = $this->randomName(20);
  26. // Create and login user.
  27. $account = $this->drupalCreateUser(array('administer content types'));
  28. $this->drupalLogin($account);
  29. $this->drupalGet('admin/structure/types');
  30. // Create the content type.
  31. $this->clickLink(t('Add content type'));
  32. $edit = array (
  33. 'name' => $content_type_friendly,
  34. 'type' => $content_type_machine,
  35. );
  36. $this->drupalPost(NULL, $edit, t('Save and add fields'));
  37. $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
  38. //$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
  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. /*$table_schema = drupal_get_schema();
  61. $this->assertEqual(1, 1, print_r(array_keys($table_schema), TRUE));
  62. // Check the schema - the values should be in the per-type table.
  63. $this->assertSchemaMatchesTables(array(
  64. 'per_type' => array(
  65. $this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),
  66. ),
  67. ));*/
  68. }
  69. }