t('Link Attribute Tests'), 'description' => t('Tests the field attributes, making sure they appear in various displayed situations.'), 'group' => t('Link'), ); } function setup() { $this->zebra = 0; parent::setup('link', 'views'); $this->loginWithPermissions($this->permissions); } function createLink($url, $title, $attributes = array()) { return array( 'url' => $url, 'title' => $title, 'attributes' => $attributes, ); } private function outputScreenContents($description, $basename) { // This is a hack to get a directory that won't be cleaned up by simpletest $file_dir = file_directory_path().'/../simpletest_output_pages'; if (!is_dir($file_dir)) { mkdir($file_dir, 0777, TRUE); } $output_path = "$file_dir/$basename." . $this->randomName(10) . '.html'; $rv = file_put_contents($output_path, $this->drupalGetContent()); $this->pass("$description: Contents of result page are ".l('here',$output_path)); } 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('@@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')); $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('
'. print_r($field, TRUE) .'
'); $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->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com')); // Does this display on the front page? $this->drupalGet(''); // reset the zebra! $this->zebra = 0; $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com')); } /** * 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('
'. print_r($field, TRUE) .'
'); $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(''); // reset the zebra! $this->zebra = 0; $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class')))); } }