home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (link.crud.test)

This example Drupal source code file (link.crud.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, content, content_type_friendly, crud, edit, fields, function, link_field, name, php, single_field_name_friendly, the, type, type_exists

The link.crud.test Drupal example source code

// $Id: link.crud.test,v 2011/01/16 04:12:21 jcfiala Exp $

 * @file
 * Basic CRUD simpletests for the link module, based off of content.crud.test in CCK.

class LinkContentCrudTest extends DrupalWebTestCase {
  function getInfo() {
    return array(
      'name' => t('Link CRUD - Basic API tests'),
      'description' => t('Tests the field CRUD (create, read, update, delete) API.'),
      'group' => t('Link'),
  function setUp() {
    parent::setUp('field_ui', 'link'); // was views?
   * All we're doing here is creating a content type, creating a simple link field
   * on that content type.
  function testLinkCreateFieldAPI() {
    $content_type_friendly = $this->randomName(20);
    $content_type_machine = strtolower($this->randomName(10));
    $title = $this->randomName(20);

    // Create and login user.
    $account = $this->drupalCreateUser(array('administer content types'));


    // Create the content type.
    $this->clickLink(t('Add content type'));

    $edit = array (
      'name' => $content_type_friendly,
      'type' => $content_type_machine,
    $this->drupalPost(NULL, $edit, t('Save and add fields'));
    $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
    //$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
    // Now add a singleton field.
    $single_field_name_friendly = $this->randomName(20);
    $single_field_name_machine = strtolower($this->randomName(10));
    $edit = array (
      'fields[_add_new_field][label]' => $single_field_name_friendly,
      'fields[_add_new_field][field_name]' => $single_field_name_machine,
      'fields[_add_new_field][type]' => 'link_field',
      'fields[_add_new_field][widget_type]' => 'link_field',

    $this->drupalPost(NULL, $edit, t('Save'));
    // We'll go with the default settings for this run-through.
    $this->drupalPost(NULL, array(), t('Save field settings'));
    // Using all the default settings, so press the button.
    $this->drupalPost(NULL, array(), t('Save settings'));
    $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
    // Somehow clicking "save" isn't enough, and we have to do a
    // node_types_rebuild().
    $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
    $this->assertTrue($type_exists, 'The new content type has been created in the database.');
    /*$table_schema = drupal_get_schema();
    $this->assertEqual(1, 1, print_r(array_keys($table_schema), TRUE));
    // Check the schema - the values should be in the per-type table.
      'per_type' => array(
        $this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal link.crud.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.