123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781 |
- <?php
- /**
- * @file
- * Basic simpletests to test options on link module.
- */
- class LinkAttributeCrudTest extends DrupalWebTestCase {
- private $zebra;
- public $permissions = array(
- 'access content',
- 'administer content types',
- 'administer nodes',
- 'administer filters',
- 'access comments',
- 'post comments',
- 'skip comment approval',
- 'access administration pages',
- );
- public static function getInfo() {
- return array(
- 'name' => 'Link Attribute Tests',
- 'description' => 'Tests the field attributes, making sure they appear in various displayed situations.',
- 'group' => 'Link',
- );
- }
- function setup() {
- $this->zebra = 0;
- parent::setup('field_ui', 'link'); // was 'views'
- //$this->loginWithPermissions($this->permissions);
- // Create and login user.
- $account = $this->drupalCreateUser(array('administer content types'));
- $this->drupalLogin($account);
- }
- function createLink($url, $title, $attributes = array()) {
- return array(
- 'url' => $url,
- 'title' => $title,
- 'attributes' => $attributes,
- );
- }
- private function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
- $this->zebra++;
- $zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd';
- $cssFieldLocator = 'field-'. str_replace('_', '-', $field_name);
- $this->assertPattern('@<div class="field field-type-link '. $cssFieldLocator .'".*<div class="field-item '. $zebra_string .'">\s*'. $link_value .'\s*</div>@is',
- $message,
- $group);
- }
- /**
- * A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure
- * that the node is being displayed.
- */
- function testBasic() {
- /*$this->acquireContentTypes(1);
- variable_set('node_options_'. $this->content_types[0]->name, array('status', 'promote'));*/
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $title = $this->randomName(20);
- $this->drupalGet('admin/structure/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)));
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- $single_field_name = 'field_'. $single_field_name_machine;
- $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().
- node_types_rebuild();
- menu_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.');
- $permission = 'create ' . $content_type_machine . ' content';
- $permission_edit = 'edit ' . $content_type_machine . ' content';
- // Reset the permissions cache.
- $this->checkPermissions(array($permission), TRUE);
- // Now that we have a new content type, create a user that has privileges
- // on the content type.
- $permissions = array_merge($this->permissions, array($permission));
- $account = $this->drupalCreateUser($permissions);
- $this->drupalLogin($account);
- // Go to page.
- $this->drupalGet('node/add/'. $content_type_machine);
- // Add a node.
- $edit = array(
- 'title' => $title,
- 'field_'. $single_field_name_machine. '[und][0][title]' => 'Link',
- 'field_'. $single_field_name_machine. '[und][0][url]' => 'http://www.drupal.org/',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
- /*$field_settings = array(
- 'type' => 'link',
- 'widget_type' => 'link',
- 'type_name' => $this->content_types[0]->name,
- 'attributes' => array(), // <-- This is needed or we have an error.
- );
- $field = $this->createField($field_settings, 0);
- //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
- $field_db_info = content_database_info($field);*/
- //$this->acquireNodes(2);
- /*$node = $this->drupalCreateNode(array('type' => $content_type_machine,
- 'promote' => 1));
- $test_nid = $node->nid;*/
- //$node = node_load($this->nodes[0]->nid);
- //$node->promote = 1; // We want this to show on front page for the teaser test.
- /*$this->assert('debug', print_r($node, TRUE), 'Debug');
- $node->{$single_field_name}['und'][0] = $this->createLink('http://www.example.com', 'Test Link');
- node_save($node);
- $this->assert('debug', print_r($node, TRUE), 'Debug');*/
- //$this->drupalGet('node/'. $test_nid .'/edit');
- $this->drupalGet('node/add/'. $content_type_machine);
- // lets add a node:
- $edit = array(
- 'title' => $title,
- 'field_' . $single_field_name_machine . '[und][0][url]' => 'http://www.example.com/',
- 'field_' . $single_field_name_machine . '[und][0][title]' => 'Display',
- );
- // Now we can fill in the second item in the multivalue field and save.
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
- $this->assertText('Display');
- //$this->assertText('http://www.example.com/');
- $this->assertLinkByHref('http://www.example.com');
- }
- private function createNodeType($content_type_machine, $content_type_friendly) {
- $this->drupalGet('admin/structure/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)));
- }
- private function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) {
- $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().
- node_types_rebuild();
- menu_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.');
- }
- function createNodeTypeUser($content_type_machine) {
- $permission = 'create ' . $content_type_machine . ' content';
- $permission_edit = 'edit ' . $content_type_machine . ' content';
- // Reset the permissions cache.
- $this->checkPermissions(array($permission), TRUE);
- // Now that we have a new content type, create a user that has privileges
- // on the content type.
- $permissions = array_merge($this->permissions, array($permission));
- $account = $this->drupalCreateUser($permissions);
- $this->drupalLogin($account);
- }
- function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') {
- // Go to page.
- $this->drupalGet('node/add/'. $content_type_machine);
- if (!$node_title) {
- $node_title = $this->randomName(20);
- }
- $edit = array(
- 'title' => $node_title,
- );
- if ($url) {
- $edit['field_' . $single_field_name_machine . '[und][0][url]'] = $url;
- }
- if ($title) {
- $edit['field_' . $single_field_name_machine . '[und][0][title]'] = $title;
- }
- // Now we can fill in the second item in the multivalue field and save.
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $node_title)));
- }
- function testFormatterPlain() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText($link_url);
- $this->assertNoText($link_text);
- $this->assertNoLinkByHref($link_url);
- }
- function testFormatterPlainWithQuerystring() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/?q=test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText($link_url);
- $this->assertNoText($link_text);
- $this->assertNoLinkByHref($link_url);
- }
- function testFormatterPlainWithFragment() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/#test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText($link_url);
- $this->assertNoText($link_text);
- $this->assertNoLinkByHref($link_url);
- }
- function testFormatterURL() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertNoText($link_text);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterURLWithQuerystring() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/?q=test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertNoText($link_text);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterURLWithAnchor() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/#test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertNoText($link_text);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterShort() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText('Link');
- $this->assertNoText($link_text);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterShortWithQuerystring() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/?q=test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText('Link');
- $this->assertNoText($link_text);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterShortWithFragment() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/#test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText('Link');
- $this->assertNoText($link_text);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterLabel() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertNoText($link_text);
- $this->assertText($single_field_name_friendly);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterLabelWithQuerystring() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/?q=test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertNoText($link_text);
- $this->assertText($single_field_name_friendly);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterLabelWithFragment() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = 'Display';
- $link_url = 'http://www.example.com/#test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertNoText($link_text);
- $this->assertText($single_field_name_friendly);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterSeparate() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = $this->randomName(20);
- $link_url = 'http://www.example.com/';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText($link_text);
- $this->assertLink($link_url);
- $this->assertLinkByHref($link_url);
- }
- function testFormatterSeparateWithQuerystring() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = $this->randomName(20);
- $link_url = 'http://www.example.com/?q=test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText($link_text);
- $this->assertLink('http://www.example.com/');
- $this->assertLinkByHref($link_url);
- }
- function testFormatterSeparateWithFragment() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
- $this->createNodeType($content_type_machine, $content_type_friendly);
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->createNodeTypeUser($content_type_machine);
- $link_text = $this->randomName(20);
- $link_url = 'http://www.example.com/#test';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
- $this->assertText($link_text);
- $this->assertLink('http://www.example.com/');
- $this->assertLinkByHref($link_url);
- }
-
- function testFormatterPlainTitle() {
- $content_type_friendly = $this->randomName(20);
- $content_type_machine = strtolower($this->randomName(10));
-
- $this->createNodeType($content_type_machine, $content_type_friendly);
-
- // Now add a singleton field.
- $single_field_name_friendly = $this->randomName(20);
- $single_field_name_machine = strtolower($this->randomName(10));
- //$single_field_name = 'field_'. $single_field_name_machine;
- $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
-
- // Okay, now we want to make sure this display is changed:
- $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
- $edit = array(
- 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
- 'fields[field_'. $single_field_name_machine .'][type]' => 'link_title_plain',
- );
- $this->drupalPost(NULL, $edit, t('Save'));
-
- $this->createNodeTypeUser($content_type_machine);
-
- $link_text = 'Display';
- $link_url = 'http://www.example.com/';
- $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
-
- $this->assertText($link_text);
- $this->assertNoText($link_url);
- $this->assertNoLinkByHref($link_url);
- }
- /**
- * This test sees that we can create a link field with a defined class, and make sure
- * that class displays properly when the link is displayed.
- */
- /*function testLinkWithClassOnField() {
- $this->acquireContentTypes(1);
- $field_settings = array(
- 'type' => 'link',
- 'widget_type' => 'link',
- 'type_name' => $this->content_types[0]->name,
- 'attributes' => array(
- 'class' => 'test-class',
- 'target' => 'default',
- 'rel' => FALSE,
- ),
- );
- $field = $this->createField($field_settings, 0);
- //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
- $field_db_info = content_database_info($field);
- $this->acquireNodes(2);
- $node = node_load($this->nodes[0]->nid);
- $node->promote = 1; // We want this to show on front page for the teaser test.
- $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
- node_save($node);
- // Does this display on the node page?
- $this->drupalGet('node/'. $this->nodes[0]->nid);
- //$this->outputScreenContents('Link field with class', 'link_');
- $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
- // Does this display on the front page?
- $this->drupalGet('<front>');
- // reset the zebra!
- $this->zebra = 0;
- $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
- }*/
- }
|