Commit ad738b96 authored by Digidog's avatar Digidog
Browse files

Issue #1218422 by Dave Reid, twistor, Digidog: Fixed tests files: strict...

Issue #1218422 by Dave Reid, twistor, Digidog: Fixed tests files: strict warnings about static getInfo and parameters for setUp(), whitespace, and file structure.
parent b21ca3f5
......@@ -6,9 +6,11 @@ package = Fields
files[] = link.module
files[] = link.install
; Tests
files[] = tests/link.crud.test
files[] = tests/link.test
files[] = tests/link.attribute.test
files[] = tests/link.crud.test
files[] = tests/link.crud_browser.test
files[] = tests/link.token.test
files[] = tests/link.validate.test
; Views Handlers
......
This diff is collapsed.
......@@ -6,20 +6,20 @@
*/
class LinkContentCrudTest extends DrupalWebTestCase {
function getInfo() {
public static 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'),
'name' => 'Link CRUD - Basic API tests',
'description' => 'Tests the field CRUD (create, read, update, delete) API.',
'group' => 'Link',
);
}
function setUp() {
parent::setUp('field_ui', 'link'); // was views?
//$this->loginWithPermissions();
}
/**
* All we're doing here is creating a content type, creating a simple link field
* on that content type.
......@@ -38,14 +38,14 @@ class LinkContentCrudTest extends DrupalWebTestCase {
// 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);
......@@ -58,21 +58,21 @@ class LinkContentCrudTest extends DrupalWebTestCase {
);
$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.');
/*$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.
......
......@@ -12,33 +12,27 @@ class LinkUITest extends DrupalWebTestcase {
/**
* Link supposed to be good
*/
*/
const LINK_INPUT_TYPE_GOOD = 0;
/**
* Link supposed to have a bad title
*/
*/
const LINK_INPUT_TYPE_BAD_TITLE = 1;
/**
* Link supposed to have a bad URL
*/
*/
const LINK_INPUT_TYPE_BAD_URL = 2;
/**
* Implementation of getInfo().
*/
function getInfo() {
public static function getInfo() {
return array(
'name' => t('Link CRUD - browser test'),
'description' => t('Tests the field CRUD (create, read, update, delete) API 2.'),
'group' => t('Link'),
'name' => 'Link CRUD - browser test',
'description' => 'Tests the field CRUD (create, read, update, delete) API 2.',
'group' => 'Link',
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('field_ui', 'link');
}
......@@ -72,7 +66,7 @@ class LinkUITest extends DrupalWebTestcase {
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
$permission = 'create page content';
$this->checkPermissions(array($permission), TRUE);
......@@ -129,7 +123,7 @@ class LinkUITest extends DrupalWebTestcase {
);
$test_case['expected_href'] = 'http://'. $test_case['href'];
$input_test_cases[] = $test_case;
foreach ($input_test_cases as $input) {
$this->drupalLogin($account);
$this->drupalGet('node/add/page');
......@@ -153,7 +147,7 @@ class LinkUITest extends DrupalWebTestcase {
// change to anonym user
$this->drupalLogout();
$this->drupalGet($url);
//debug($this);
// If simpletest starts using something to override the error system, this will flag
......@@ -172,7 +166,7 @@ class LinkUITest extends DrupalWebTestcase {
}
//libxml_use_internal_errors(FALSE);
}
/**
* Creates a link field for the "page" type and creates a page with a link.
* Just like the above test, only here we're turning off the validation on the field.
......@@ -199,7 +193,7 @@ class LinkUITest extends DrupalWebTestcase {
_content_type_info(TRUE);
$fields = content_fields();
$this->assertTRUE(0 === $fields['field_'. $name]['validate_url'], 'Make sure validation is off.');
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
......@@ -267,7 +261,7 @@ class LinkUITest extends DrupalWebTestcase {
// change to anonym user
$this->drupalLogout();
$this->drupalGet($url);
//debug($this);
// If simpletest starts using something to override the error system, this will flag
......@@ -281,7 +275,7 @@ class LinkUITest extends DrupalWebTestcase {
}
//libxml_use_internal_errors(FALSE);
}*/
/**
* Testing that if you use <strong> in a static title for your link, that the
* title actually displays <strong>.
......@@ -311,26 +305,26 @@ class LinkUITest extends DrupalWebTestcase {
// create page form
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName()
);
$edit = array(
'title' => $name,
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l('<strong>'. $name .'</strong>', $input['href'], array('html' => TRUE)));
}
/**
* If we're creating a new field and just hit 'save' on the default options, we want to make
* sure they are set to the expected results.
......@@ -373,7 +367,7 @@ class LinkUITest extends DrupalWebTestcase {
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
$this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
//$this->fail('<pre>'. print_r($fields['field_'. $name], TRUE) .'</pre>');
}
}
......@@ -16,9 +16,9 @@ class LinkBaseTestClass extends DrupalWebTestCase {
'access administration pages',
'create page content',
);
public $account;
function setUp($modules = array()) {
if ($modules) {
parent::setUp($modules);
......@@ -29,7 +29,7 @@ class LinkBaseTestClass extends DrupalWebTestCase {
$this->account = $this->drupalCreateUser($this->permissions);
$this->drupalLogin($this->account);
}
function createLinkField($node_type = 'page',
$settings = array()) {
$name = strtolower($this->randomName());
......@@ -48,7 +48,7 @@ class LinkBaseTestClass extends DrupalWebTestCase {
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
return $field_name;
}
}
\ No newline at end of file
}
......@@ -5,30 +5,25 @@
* Contains simpletests making sure token integration works.
*/
// Let's include the parent class.
module_load_include('inc', 'link', 'tests/link.base-test');
/**
* Testing that tokens can be used in link titles
*/
class LinkTokenTest extends LinkBaseTestClass {
/**
* Implementation of getInfo().
*/
function getInfo() {
public static function getInfo() {
return array(
'name' => t('Link tokens - browser test'),
'description' => t('Tests including tokens in link titles, making sure they appear in node views. <strong>Requires <a href="@token_link">Token module</a>.</strong>'),
'group' => t('Link'),
'name' => 'Link tokens - browser test',
'description' => 'Tests including tokens in link titles, making sure they appear in node views.',
'group' => 'Link',
'dependencies' => array('token'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp(array('field_ui', 'link', 'token'));
function setUp($modules = array()) {
$modules[] = 'field_ui';
$modules[] = 'link';
$modules[] = 'token';
parent::setUp($modules);
}
/**
......@@ -56,7 +51,7 @@ class LinkTokenTest extends LinkBaseTestClass {
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
);
//$this->drupalLogin($account);
$this->drupalGet('node/add/page');
......@@ -65,17 +60,17 @@ class LinkTokenTest extends LinkBaseTestClass {
$field_name . '[und][0][title]' => $input['label'] . " [node:content-type:machine-name]",
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'] . ' page', $input['href']));
}
/**
* Creates a link field with a static title and an admin-entered token.
* Creates a node with a link and checks the title value.
......@@ -104,17 +99,17 @@ class LinkTokenTest extends LinkBaseTestClass {
'title' => $name,
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($name . ' page', $input['href']));
}
/**
* Creates a link field with a static title and an admin-entered token.
* Creates a node with a link and checks the title value.
......@@ -147,17 +142,17 @@ class LinkTokenTest extends LinkBaseTestClass {
'title' => $name,
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($name .' '. $name, $input['href']));
}
// This test doesn't seem to actually work, due to lack of 'title' in url.
function _test_Link_With_Title_Attribute_token_url_form() {
/* $this->loginWithPermissions($this->permissions);
......@@ -173,13 +168,13 @@ class LinkTokenTest extends LinkBaseTestClass {
'title' => '',
),
);
$field = $this->createField($field_settings, 0);
//$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
$field_name = $field['field_name'];
$field_db_info = content_database_info($field);
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '['. $field_name .'-url]',
'enable_tokens' => TRUE);
......@@ -190,31 +185,31 @@ class LinkTokenTest extends LinkBaseTestClass {
$settings = array(
'instance[settings][attributes][rel]' => 'nofollow',
);
$field_name = $this->createLinkField('page', $settings);
// So, having saved this field_name, let's see if it works...
//$this->acquireNodes(1);
//$node = node_load($this->nodes[0]->nid);
//$this->drupalGet('node/'. $this->nodes[0]->nid);
$edit = array();
$test_link_url = 'http://www.example.com/test';
$edit[$field_name .'[und][0][url]'] = $test_link_url;
$title = 'title_'. $this->randomName(20);
$edit[$field_name .'[und][0][title]'] = $title;
$edit['title'] = $name;
$this->drupalGet('node/add/page');
$this->drupalPost(NULL, $edit, t('Save'));
// Make sure we get a new version!
//$node = node_load($this->nodes[0]->nid, NULL, TRUE);
$this->assertText(t('Basic page @title has been updated.',
array('@title' => $name)));
//$this->drupalGet('node/'. $node->nid);
$this->assertText($title, 'Make sure the link title/text shows');
$this->assertRaw(' title="'. $test_link_url .'"', "Do we show the link url as the title attribute?");
......@@ -222,7 +217,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
//$this->fail($this->content);
}
/**
* If the title of the link is set to the title attribute, then the title
* attribute isn't supposed to show.
......@@ -241,39 +236,39 @@ class LinkTokenTest extends LinkBaseTestClass {
'title' => '',
),
);
$field = $this->createField($field_settings, 0);
$field_name = $field['field_name'];
$field_db_info = content_database_info($field);
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '['. $field_name .'-title]',
'enable_tokens' => TRUE);
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
$edit, t('Save field settings'));
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
// So, having saved this field_name, let's see if it works...
$this->acquireNodes(1);
$node = node_load($this->nodes[0]->nid);
$this->drupalGet('node/'. $this->nodes[0]->nid);
$edit = array();
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
$title = 'title_'. $this->randomName(20);
$edit[$field['field_name'] .'[0][title]'] = $title;
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
// Make sure we get a new version!
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
$this->assertText(t('@type @title has been updated.',
array('@title' => $node->title,
'@type' => $this->content_types[0]->name)));
$this->drupalGet('node/'. $node->nid);
$this->assertText($title, 'Make sure the link title/text shows');
$this->assertNoRaw(' title="'. $title .'"', "We should not show the link title as the title attribute?");
......@@ -314,7 +309,7 @@ class LinkTokenTest extends LinkBaseTestClass {
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
);
$this->drupalLogin($account);
$this->drupalGet('node/add/page');
......@@ -323,17 +318,17 @@ class LinkTokenTest extends LinkBaseTestClass {
$field_name . '[0][title]' => $input['label'],
$field_name . '[0][url]' => $input['href'] . "/[type]",
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] .'/page'));
//$this->fail($this->content);
}
/**
* Trying to set the url to contain a token.
*/
......@@ -367,7 +362,7 @@ class LinkTokenTest extends LinkBaseTestClass {
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
);
$this->drupalLogin($account);
$this->drupalGet('node/add/page');
......@@ -376,11 +371,11 @@ class LinkTokenTest extends LinkBaseTestClass {
$field_name . '[0][title]' => $input['label'],
$field_name . '[0][url]' => $input['href'] . "/[author-uid]",
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] .'/'. $account->uid));
......
......@@ -5,15 +5,12 @@
* Tests that exercise the validation functions in the link module.
*/
// Let's include the parent class.
module_load_include('inc', 'link', 'tests/link.base-test');
class LinkValidateTestCase extends LinkBaseTestClass {
function setUp() {
parent::setUp();
function setUp($modules = array()) {
parent::setUp($modules);
}
function createLink($url, $title, $attributes = array()) {
return array(
'url' => $url,
......@@ -21,14 +18,14 @@ class LinkValidateTestCase extends LinkBaseTestClass {
'attributes' => $attributes,
);
}
/**
* Takes a url, and sees if it can validate that the url is valid.
*/
public function link_test_validate_url($url) {
$field_name = $this->createLinkField();
$permission = 'create page content';
$this->checkPermissions(array($permission), TRUE);
......@@ -42,29 +39,29 @@ class LinkValidateTestCase extends LinkBaseTestClass {
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t(' has been created.'), 'Node created');
$nid = 1; //$matches[1];
$node = node_load($nid);
$this->assertEqual($url, $node->{$field_name}['und'][0]['url']);
}
}
class LinkValidateTest extends LinkValidateTestCase {
function getInfo() {
public static function getInfo() {
return array(
'name' => t('Link Validation Tests'),
'description' => t('Tests the field validation.'),
'group' => t('Link'),
'name' => 'Link Validation Tests',
'description' => 'Tests the field validation.',
'group' => 'Link',
);
}
function test_link_validate_basic_url() {
$this->link_test_validate_url('http://www.example.com');
}
/**
* Test if we're stopped from posting a bad url on default validation.
*/
......@@ -93,23 +90,23 @@ class LinkValidateTest extends LinkValidateTestCase {
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name .'[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('Not a valid URL.'));
}
/**