diff --git a/tests/link.attribute.test b/tests/link.attribute.test index 1a205d3..39be3a6 100644 --- a/tests/link.attribute.test +++ b/tests/link.attribute.test @@ -5,6 +5,9 @@ * Basic simpletests to test options on link module. */ +/** + * Attribute Crud Test. + */ class LinkAttributeCrudTest extends DrupalWebTestCase { private $zebra; @@ -19,6 +22,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { 'access administration pages', ); + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link Attribute Tests', @@ -27,7 +33,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { ); } - function setup() { + /** + * Setup. + */ + public function setup() { parent::setup('field_ui', 'link'); $this->zebra = 0; // Create and login user. @@ -35,6 +44,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->drupalLogin($this->web_user); } + /** + * Create Link. + */ protected function createLink($url, $title, $attributes = array()) { return array( 'url' => $url, @@ -43,6 +55,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { ); } + /** + * Assert Link On Node. + */ protected function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') { $this->zebra++; $zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd'; @@ -53,10 +68,13 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { } /** - * 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. + * Test Basic. + * + * 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() { + public function testBasic() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); $title = $this->randomName(20); @@ -141,6 +159,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->assertLinkByHref('http://www.example.com'); } + /** + * Create Simple Link Field. + */ protected function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) { $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/fields'); $edit = array( @@ -166,6 +187,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->assertTrue($type_exists, 'The new content type has been created in the database.'); } + /** + * Create Node Type User. + */ protected function createNodeTypeUser($content_type_machine) { $permission = 'create ' . $content_type_machine . ' content'; // Reset the permissions cache. @@ -178,6 +202,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->drupalLogin($this->web_user); } + /** + * Create Node For Testing. + */ protected function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') { $this->drupalGet('node/add/' . $content_type_machine); @@ -202,7 +229,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { /** * Test the link_plain formatter and it's output. */ - function testFormatterPlain() { + public function testFormatterPlain() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); @@ -214,7 +241,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { // 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; + // $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: @@ -226,7 +253,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->drupalPost(NULL, $edit, t('Save')); $this->createNodeTypeUser($content_type_machine); - + $link_tests = array( 'plain' => array( 'text' => 'Display', @@ -246,14 +273,17 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $link_text = $link_test['text']; $link_url = $link_test['url']; $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 testFormatterHost() { + /** + * Formatter Host. + */ + public function testFormatterHost() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); @@ -262,18 +292,17 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { '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; + // $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'); + $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_host', + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_host', ); $this->drupalPost(NULL, $edit, t('Save')); @@ -288,7 +317,13 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->assertNoLinkByHref($link_url); } - function testFormatterURL() { + /** + * Formatter URL. + * + * @codingStandardsIgnoreStart + */ + public function testFormatterURL() { + // @codingStandardsIgnoreEnd $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); @@ -300,7 +335,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { // 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; + // $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: @@ -312,7 +347,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->drupalPost(NULL, $edit, t('Save')); $this->createNodeTypeUser($content_type_machine); - + $link_tests = array( 'plain' => array( 'text' => 'Display', @@ -332,13 +367,16 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $link_text = $link_test['text']; $link_url = $link_test['url']; $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() { + /** + * Formatter Short. + */ + public function testFormatterShort() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); @@ -350,7 +388,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { // 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; + // $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: @@ -382,14 +420,17 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $link_text = $link_test['text']; $link_url = $link_test['url']; $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() { + /** + * Formatter Label. + */ + public function testFormatterLabel() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); @@ -401,7 +442,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { // 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; + // $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: @@ -431,16 +472,19 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { foreach ($link_tests as $link_test) { $link_text = $link_test['text']; - $link_url = $link_test['url']; + $link_url = $link_test['url']; $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() { + /** + * Formatter Separate. + */ + public function testFormatterSeparate() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); @@ -452,7 +496,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { // 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; + // $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: @@ -485,28 +529,31 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $link_text = $link_test['text']; $link_url = $link_test['url']; $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - + $this->assertText($link_text); $this->assertLink($plain_url); $this->assertLinkByHref($link_url); } } - - function testFormatterPlainTitle() { + + /** + * Formatter Plain Title. + */ + public function testFormatterPlainTitle() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); - + $this->drupalCreateContentType(array( 'type' => $content_type_machine, '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; + // $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( @@ -514,15 +561,16 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { '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); } + } diff --git a/tests/link.crud.test b/tests/link.crud.test index 3a3580e..83de9f9 100644 --- a/tests/link.crud.test +++ b/tests/link.crud.test @@ -2,11 +2,20 @@ /** * @file - * Basic CRUD simpletests for the link module, based off of content.crud.test in CCK. + * File for Crud Tests. + * + * Basic CRUD simpletests for the link module, based off of content.crud.test in + * CCK. */ +/** + * Content Crud. + */ class LinkContentCrudTest extends DrupalWebTestCase { + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link CRUD - Basic API tests', @@ -15,15 +24,23 @@ class LinkContentCrudTest extends DrupalWebTestCase { ); } - function setUp() { + /** + * Setup. + */ + public function setUp() { parent::setUp('field_ui', 'link'); } /** - * All we're doing here is creating a content type, creating a simple link field - * on that content type. + * Create Field API. + * + * All we're doing here is creating a content type, creating a simple link + * field on that content type. + * + * @codingStandardsIgnoreStart */ - function testLinkCreateFieldAPI() { + public function testLinkCreateFieldAPI() { + // @codingStandardsIgnoreEnd $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); @@ -68,4 +85,5 @@ class LinkContentCrudTest extends DrupalWebTestCase { $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.'); } + } diff --git a/tests/link.crud_browser.test b/tests/link.crud_browser.test index 786e1d3..f498b33 100644 --- a/tests/link.crud_browser.test +++ b/tests/link.crud_browser.test @@ -6,25 +6,28 @@ */ /** - * Testing that users can not input bad URLs or labels + * Testing that users can not input bad URLs or labels. */ class LinkUITest extends DrupalWebTestcase { /** - * Link supposed to be good + * Link supposed to be good. */ const LINK_INPUT_TYPE_GOOD = 0; /** - * Link supposed to have a bad title + * Link supposed to have a bad title. */ const LINK_INPUT_TYPE_BAD_TITLE = 1; /** - * Link supposed to have a bad URL + * Link supposed to have a bad URL. */ const LINK_INPUT_TYPE_BAD_URL = 2; + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link CRUD - browser test', @@ -33,15 +36,18 @@ class LinkUITest extends DrupalWebTestcase { ); } - function setUp() { + /** + * Setup. + */ + public function setUp() { parent::setUp('field_ui', 'link'); } /** * Creates a link field for the "page" type and creates a page with a link. */ - function testLinkCreate() { - //libxml_use_internal_errors(true); + public function testLinkCreate() { + // libxml_use_internal_errors(true); $this->web_user = $this->drupalCreateUser(array( 'administer content types', 'administer fields', @@ -49,11 +55,11 @@ class LinkUITest extends DrupalWebTestcase { 'administer filters', 'access content', 'create page content', - 'access administration pages' + 'access administration pages', )); $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -73,8 +79,8 @@ class LinkUITest extends DrupalWebTestcase { $permission = 'create page content'; $this->checkPermissions(array($permission), TRUE); - // create page form - //$this->drupalGet('node/add'); + // Create page form + // $this->drupalGet('node/add');. $this->drupalGet('node/add/page'); $field_name = 'field_' . $name; $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found'); @@ -85,37 +91,37 @@ class LinkUITest extends DrupalWebTestcase { 'href' => 'http://example.com/' . $this->randomName(), 'label' => $this->randomName(), 'msg' => 'Link found', - 'type' => self::LINK_INPUT_TYPE_GOOD + 'type' => self::LINK_INPUT_TYPE_GOOD, ), array( 'href' => 'http://example.com/' . $this->randomName(), 'label' => $this->randomName() . '', 'msg' => 'js label', - 'type' => self::LINK_INPUT_TYPE_BAD_TITLE + 'type' => self::LINK_INPUT_TYPE_BAD_TITLE, ), array( 'href' => 'http://example.com/' . $this->randomName(), 'label' => $this->randomName() . '', 'msg' => 'js label', - 'type' => self::LINK_INPUT_TYPE_BAD_TITLE + 'type' => self::LINK_INPUT_TYPE_BAD_TITLE, ), array( 'href' => 'http://example.com/' . $this->randomName(), 'label' => $this->randomName() . '" onmouseover="alert(\'hi\')', 'msg' => 'js label', - 'type' => self::LINK_INPUT_TYPE_BAD_TITLE + 'type' => self::LINK_INPUT_TYPE_BAD_TITLE, ), array( 'href' => 'http://example.com/' . $this->randomName(), 'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')', 'msg' => 'js label', - 'type' => self::LINK_INPUT_TYPE_BAD_TITLE + 'type' => self::LINK_INPUT_TYPE_BAD_TITLE, ), array( 'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")', 'label' => $this->randomName(), 'msg' => 'js url', - 'type' => self::LINK_INPUT_TYPE_BAD_URL + 'type' => self::LINK_INPUT_TYPE_BAD_URL, ), array( 'href' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-', @@ -154,13 +160,13 @@ class LinkUITest extends DrupalWebTestcase { } $url = $this->getUrl(); - // change to Anonymous user. + // Change to Anonymous user. $this->drupalLogout(); $this->drupalGet($url); - //debug($this); - // If simpletest starts using something to override the error system, this will flag - // us and let us know it's broken. + // debug($this); + // If simpletest starts using something to override the error system, this + // will flag us and let us know it's broken. $this->assertFalse(libxml_use_internal_errors(TRUE)); if (isset($input['expected_href'])) { $path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]'; @@ -172,18 +178,27 @@ class LinkUITest extends DrupalWebTestcase { libxml_use_internal_errors(FALSE); $this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']); } - //libxml_use_internal_errors(FALSE); + // libxml_use_internal_errors(FALSE); } /** + * Static Link Create. + * * Testing that if you use in a static title for your link, that the * title actually displays . */ - function testStaticLinkCreate() { - $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content')); + public function testStaticLinkCreate() { + + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); + $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $field_name = 'field_' . $name; $edit = array( @@ -196,17 +211,18 @@ class LinkUITest extends DrupalWebTestcase { $this->drupalPost(NULL, array(), t('Save field settings')); $this->drupalPost(NULL, array( 'instance[settings][title]' => 'value', - 'instance[settings][title_value]' => '' . $name . ''), t('Save settings')); + 'instance[settings][title_value]' => '' . $name . '', + ), t('Save settings')); // Is field created? $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); - // create page form + // 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() + 'href' => 'http://example.com/' . $this->randomName(), ); $edit = array( @@ -217,21 +233,32 @@ class LinkUITest extends DrupalWebTestcase { $url = $this->getUrl(); - // change to anonymous user + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); $this->assertRaw(l('' . $name . '', $input['href'], array('html' => TRUE))); } - + /** - * Testing that if you have the title but no url, the title is not sanitized twice. + * CRUD Title Only Title No Link. + * + * Testing that if you have the title but no url, the title is not sanitized + * twice. + * + * @codingStandardsIgnoreStart */ - function testCRUDTitleOnlyTitleNoLink() { - $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content')); + public function testCRUDTitleOnlyTitleNoLink() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $field_name = 'field_' . $name; $edit = array( @@ -248,8 +275,8 @@ class LinkUITest extends DrupalWebTestcase { // Is field created? $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); - - // create page form + + // Create page form. $this->drupalGet('node/add/page'); $this->assertField($field_name . '[und][0][url]', 'URL found'); @@ -266,8 +293,8 @@ class LinkUITest extends DrupalWebTestcase { $this->drupalPost(NULL, $edit, t('Save')); $url = $this->getUrl(); - - // change to anonymous user + + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); @@ -275,14 +302,26 @@ class LinkUITest extends DrupalWebTestcase { } /** - * 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. + * CRUD Create Field Defaults. + * + * 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. + * + * @codingStandardsIgnoreStart */ - function testCRUDCreateFieldDefaults() { - $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content')); + public function testCRUDCreateFieldDefaults() { + // @codingStandardsIgnoreEnd + + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); + $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -313,16 +352,26 @@ class LinkUITest extends DrupalWebTestcase { $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.'); } - + /** - * 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. + * CRUD Create Field With Class. + * + * 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. + * + * @codingStandardsIgnoreStart */ - function testCRUDCreateFieldWithClass() { - $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content')); + public function testCRUDCreateFieldWithClass() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -357,9 +406,9 @@ class LinkUITest extends DrupalWebTestcase { $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.'); $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); - + // Now, let's create a node with this field and make sure the link shows up: - // create page form + // create page form. $field_name = 'field_' . $name; $this->drupalGet('node/add/page'); $this->assertField($field_name . '[und][0][url]', 'URL found'); @@ -377,8 +426,8 @@ class LinkUITest extends DrupalWebTestcase { $this->drupalPost(NULL, $edit, t('Save')); $url = $this->getUrl(); - - // change to anonymous user + + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); @@ -386,15 +435,25 @@ class LinkUITest extends DrupalWebTestcase { $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page."); } -/** - * 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. + /** + * CRUD Create Field With Two Classes. + * + * 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. + * + * @codingStandardsIgnoreStart */ - function testCRUDCreateFieldWithTwoClasses() { - $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content')); + public function testCRUDCreateFieldWithTwoClasses() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -429,9 +488,9 @@ class LinkUITest extends DrupalWebTestcase { $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.'); $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); - + // Now, let's create a node with this field and make sure the link shows up: - // create page form + // create page form. $field_name = 'field_' . $name; $this->drupalGet('node/add/page'); $this->assertField($field_name . '[und][0][url]', 'URL found'); @@ -449,12 +508,13 @@ class LinkUITest extends DrupalWebTestcase { $this->drupalPost(NULL, $edit, t('Save')); $url = $this->getUrl(); - - // change to anonymous user + + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); $this->assertRaw('This & That'); $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page."); } + } diff --git a/tests/link.entity_token.test b/tests/link.entity_token.test index 6c9f652..681eb70 100644 --- a/tests/link.entity_token.test +++ b/tests/link.entity_token.test @@ -6,10 +6,13 @@ */ /** - * Testing that tokens can be used in link titles + * Testing that tokens can be used in link titles. */ class LinkEntityTokenTest extends LinkBaseTestClass { + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link entity tokens test', @@ -19,24 +22,27 @@ class LinkEntityTokenTest extends LinkBaseTestClass { ); } - function setUp($modules = array()) { + /** + * Setup. + */ + public function setUp($modules = array()) { parent::setUp(array('token', 'entity', 'entity_token')); } - + /** * Creates a link field, fills it, then uses a loaded node to test tokens. */ - function testFieldTokenNodeLoaded() { - // create field + public function testFieldTokenNodeLoaded() { + // Create field. $settings = array( 'instance[settings][enable_tokens]' => 0, ); $field_name = $this->createLinkField('page', $settings); - // create page form + // Create page form. $this->drupalGet('node/add/page'); - //$field_name = 'field_' . $name; + // $field_name = 'field_' . $name;. $this->assertField($field_name . '[und][0][title]', 'Title found'); $this->assertField($field_name . '[und][0][url]', 'URL found'); @@ -58,10 +64,11 @@ class LinkEntityTokenTest extends LinkBaseTestClass { 'label' => $this->randomName(), ), ); - // $this->assert('pass', '
' . print_r($token_url_tests, TRUE) . '
');
+    // @codingStandardsIgnoreLine
+    // $this->assert('pass', '
' . print_r($token_url_tests, TRUE) . '
');.
     foreach ($token_url_tests as &$input) {
       $this->drupalGet('node/add/page');
-  
+
       $edit = array(
         'title' => $input['label'],
         $field_name . '[und][0][title]' => $input['label'],
@@ -72,9 +79,9 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
       $input['url'] = $url;
     }
 
-    // change to anonymous user
+    // Change to anonymous user.
     $this->drupalLogout();
-    
+
     foreach ($token_url_tests as $index => $input2) {
       $node = node_load($index);
       $this->assertNotEqual(NULL, $node, "Do we have a node?");
@@ -85,21 +92,24 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
       $this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
     }
   }
-  
+
   /**
-   * Creates a link field, fills it, then uses a loaded and node_view'd node to test tokens.
+   * Field Token Node Viewed.
+   *
+   * Creates a link field, fills it, then uses a loaded and node_view'd node to
+   * test tokens.
    */
-  function testFieldTokenNodeViewed() {
-    // create field
+  public function testFieldTokenNodeViewed() {
+    // Create field.
     $settings = array(
       'instance[settings][enable_tokens]' => 0,
     );
     $field_name = $this->createLinkField('page',
                                         $settings);
 
-    // create page form
+    // Create page form.
     $this->drupalGet('node/add/page');
-    //$field_name = 'field_' . $name;
+    // $field_name = 'field_' . $name;.
     $this->assertField($field_name . '[und][0][title]', 'Title found');
     $this->assertField($field_name . '[und][0][url]', 'URL found');
 
@@ -122,10 +132,11 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
       ),
     );
 
-//$this->assert('pass', '
' . print_r($token_url_tests, TRUE) . '
');
+    //@codingStandardsIgnoreLine
+    // $this->assert('pass', '
' . print_r($token_url_tests, TRUE) . '
');.
     foreach ($token_url_tests as &$input) {
       $this->drupalGet('node/add/page');
-  
+
       $edit = array(
         'title' => $input['label'],
         $field_name . '[und][0][title]' => $input['label'],
@@ -136,9 +147,9 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
       $input['url'] = $url;
     }
 
-    // change to anonymous user
+    // Change to anonymous user.
     $this->drupalLogout();
-    
+
     foreach ($token_url_tests as $index => $input2) {
       $node = node_load($index);
       $this->assertNotEqual(NULL, $node, "Do we have a node?");
@@ -149,5 +160,5 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
       $this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
     }
   }
-  
-}
\ No newline at end of file
+
+}
diff --git a/tests/link.test b/tests/link.test
index 9a346b2..976a099 100644
--- a/tests/link.test
+++ b/tests/link.test
@@ -5,6 +5,9 @@
  * Link base test file - contains common functions for testing links.
  */
 
+/**
+ * Base Test Class.
+ */
 class LinkBaseTestClass extends DrupalWebTestCase {
   protected $permissions = array(
     'access content',
@@ -18,17 +21,23 @@ class LinkBaseTestClass extends DrupalWebTestCase {
     'create page content',
   );
 
-  function setUp() {
+  /**
+   * Setup.
+   */
+  public function setUp() {
     $modules = func_get_args();
     $modules = (isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules);
     $modules[] = 'field_ui';
     $modules[] = 'link';
     parent::setUp($modules);
-    
+
     $this->web_user = $this->drupalCreateUser($this->permissions);
     $this->drupalLogin($this->web_user);
   }
 
+  /**
+   * Create Link Field.
+   */
   protected function createLinkField($node_type = 'page', $settings = array()) {
     $name = strtolower($this->randomName());
     $edit = array(
@@ -49,4 +58,5 @@ class LinkBaseTestClass extends DrupalWebTestCase {
 
     return $field_name;
   }
+
 }
diff --git a/tests/link.token.test b/tests/link.token.test
index 75d8eaf..543aeae 100644
--- a/tests/link.token.test
+++ b/tests/link.token.test
@@ -6,10 +6,13 @@
  */
 
 /**
- * Testing that tokens can be used in link titles
+ * Testing that tokens can be used in link titles.
  */
 class LinkTokenTest extends LinkBaseTestClass {
 
+  /**
+   * Get Info.
+   */
   public static function getInfo() {
     return array(
       'name' => 'Link tokens - browser test',
@@ -19,34 +22,38 @@ class LinkTokenTest extends LinkBaseTestClass {
     );
   }
 
-  function setUp($modules = array()) {
+  /**
+   * Setup.
+   */
+  public function setUp($modules = array()) {
     parent::setUp(array('token'));
   }
 
   /**
    * Creates a link field with a required title enabled for user-entered tokens.
+   *
    * Creates a node with a token in the link title and checks the value.
    */
-  function testUserTokenLinkCreate() {
-    // create field
+  public function testUserTokenLinkCreate() {
+    // Create field.
     $settings = array(
       'instance[settings][enable_tokens]' => 1,
     );
     $field_name = $this->createLinkField('page',
                                         $settings);
 
-    // create page form
+    // Create page form.
     $this->drupalGet('node/add/page');
-    //$field_name = 'field_' . $name;
+    // $field_name = 'field_' . $name;.
     $this->assertField($field_name . '[und][0][title]', 'Title found');
     $this->assertField($field_name . '[und][0][url]', 'URL found');
 
     $input = array(
-        'href' => 'http://example.com/' . $this->randomName(),
-        'label' => $this->randomName(),
+      'href' => 'http://example.com/' . $this->randomName(),
+      'label' => $this->randomName(),
     );
 
-    //$this->drupalLogin($this->web_user);
+    // $this->drupalLogin($this->web_user);.
     $this->drupalGet('node/add/page');
 
     $edit = array(
@@ -57,36 +64,37 @@ class LinkTokenTest extends LinkBaseTestClass {
     $this->drupalPost(NULL, $edit, t('Save'));
     $url = $this->getUrl();
 
-    // change to anonymous user
+    // Change to anonymous user.
     $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.
    */
-  function testStaticTokenLinkCreate() {
+  public function testStaticTokenLinkCreate() {
 
-    // create field
+    // Create field.
     $name = $this->randomName();
     $settings = array(
       'instance[settings][title]' => 'value',
-      'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]');
+      'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]',
+    );
     $field_name = $this->createLinkField('page', $settings);
 
-    // create page form
+    // 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()
+      'href' => 'http://example.com/' . $this->randomName(),
     );
 
-    //$this->drupalLogin($this->web_user);
+    // $this->drupalLogin($this->web_user);.
     $this->drupalGet('node/add/page');
 
     $edit = array(
@@ -97,7 +105,7 @@ class LinkTokenTest extends LinkBaseTestClass {
 
     $url = $this->getUrl();
 
-    // change to anonymous user
+    // Change to anonymous user.
     $this->drupalLogout();
     $this->drupalGet($url);
 
@@ -106,30 +114,32 @@ class LinkTokenTest extends LinkBaseTestClass {
 
   /**
    * Creates a link field with a static title and an admin-entered token.
+   *
    * Creates a node with a link and checks the title value.
    *
    * Basically, I want to make sure the [title-raw] token works, because it's a
    * token that changes from node to node, where [type]'s always going to be the
    * same.
    */
-  function testStaticTokenLinkCreate2() {
+  public function testStaticTokenLinkCreate2() {
 
-    // create field
+    // Create field.
     $name = $this->randomName();
     $settings = array(
       'instance[settings][title]' => 'value',
-      'instance[settings][title_value]' => $name . ' [node:title]');
+      'instance[settings][title_value]' => $name . ' [node:title]',
+    );
     $field_name = $this->createLinkField('page', $settings);
 
-    // create page form
+    // 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()
+      'href' => 'http://example.com/' . $this->randomName(),
     );
 
-    //$this->drupalLogin($this->web_user);
+    // $this->drupalLogin($this->web_user);.
     $this->drupalGet('node/add/page');
 
     $edit = array(
@@ -140,27 +150,32 @@ class LinkTokenTest extends LinkBaseTestClass {
 
     $url = $this->getUrl();
 
-    // change to anonymous user
+    // Change to anonymous user.
     $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);
+  /**
+   * This test doesn't seem to actually work, due to lack of 'title' in url.
+   *
+   * @codingStandardsIgnoreStart
+   */
+  public function _test_Link_With_Title_Attribute_token_url_form() {
+    // @codingStandardsIgnoreEnd
+    /* $this->loginWithPermissions($this->permissions);
     $this->acquireContentTypes(1);
     $field_settings = array(
-      'type' => 'link',
-      'widget_type' => 'link',
-      'type_name' => $this->content_types[0]->name,
-      'attributes' => array(
-        'class' => '',
-        'target' => 'default',
-        'rel' => 'nofollow',
-        'title' => '',
-      ),
+    'type' => 'link',
+    'widget_type' => 'link',
+    'type_name' => $this->content_types[0]->name,
+    'attributes' => array(
+    'class' => '',
+    'target' => 'default',
+    'rel' => 'nofollow',
+    'title' => '',
+    ),
     );
 
     $field = $this->createField($field_settings, 0);
@@ -170,10 +185,10 @@ class LinkTokenTest extends LinkBaseTestClass {
     $url_type = str_replace('_', '-', $this->content_types[0]->type);
 
     $edit = array('attributes[title]' => '['. $field_name .'-url]',
-                  'enable_tokens' => TRUE);
-
+    'enable_tokens' => TRUE);
+    // @codingStandardsIgnoreLine
     $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
-                      $edit, t('Save field settings'));
+    $edit, t('Save field settings'));
     $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));*/
     $name = $this->randomName();
     $settings = array(
@@ -185,7 +200,7 @@ class LinkTokenTest extends LinkBaseTestClass {
     // 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);
+    // $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;
@@ -197,23 +212,28 @@ class LinkTokenTest extends LinkBaseTestClass {
     $this->drupalPost(NULL, $edit, t('Save'));
 
     // Make sure we get a new version!
-    //$node = node_load($this->nodes[0]->nid, NULL, TRUE);
+    // $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->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?");
     $this->assertNoRaw(' title="[' . $field_name . '-url]"');
     $this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
-    //$this->fail($this->content);
+    // $this->fail($this->content);.
   }
 
   /**
+   * Link With Title Attribute token title form.
+   *
    * If the title of the link is set to the title attribute, then the title
    * attribute isn't supposed to show.
+   *
+   * @codingStandardsIgnoreStart
    */
-  function _test_Link_With_Title_Attribute_token_title_form() {
+  public function _test_Link_With_Title_Attribute_token_title_form() {
+    // @codingStandardsIgnoreEnd
     $this->loginWithPermissions($this->permissions);
     $this->acquireContentTypes(1);
     $field_settings = array(
@@ -232,8 +252,10 @@ class LinkTokenTest extends LinkBaseTestClass {
     $field_name = $field['field_name'];
     $url_type = str_replace('_', '-', $this->content_types[0]->type);
 
-    $edit = array('attributes[title]' => '[' . $field_name . '-title]',
-                  'enable_tokens' => TRUE);
+    $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'));
@@ -256,24 +278,35 @@ class LinkTokenTest extends LinkBaseTestClass {
     // 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)));
+                        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?");
     $this->assertNoRaw(' title="[' . $field_name . '-title]"');
-    //$this->fail($this->content);
+    // $this->fail($this->content);.
   }
 
   /**
-   *  Trying to set the url to contain a token.
+   * Trying to set the url to contain a token.
+   *
+   * @codingStandardsIgnoreStart
    */
-  function _testUserTokenLinkCreateInURL() {
-    $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content'));
+  public function _testUserTokenLinkCreateInURL() {
+    //@codingStandardsIgnoreEnd
+
+    $this->web_user = $this->drupalCreateUser(array(
+      'administer content types',
+      'administer fields',
+      'access content',
+      'create page content',
+    ));
     $this->drupalLogin($this->web_user);
 
-    // create field
+    // Create field.
     $name = strtolower($this->randomName());
     $edit = array(
       '_add_new_field[label]' => $name,
@@ -284,20 +317,21 @@ class LinkTokenTest extends LinkBaseTestClass {
     $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
     $this->drupalPost(NULL, array(
       'title' => 'required',
-      'enable_tokens' => 1), t('Save field settings'));
+      'enable_tokens' => 1,
+    ), t('Save field settings'));
 
     // Is field created?
     $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
 
-    // create page form
+    // Create page form.
     $this->drupalGet('node/add/page');
     $field_name = 'field_' . $name;
     $this->assertField($field_name . '[0][title]', 'Title found');
     $this->assertField($field_name . '[0][url]', 'URL found');
 
     $input = array(
-        'href' => 'http://example.com/' . $this->randomName(),
-        'label' => $this->randomName(),
+      'href' => 'http://example.com/' . $this->randomName(),
+      'label' => $this->randomName(),
     );
 
     $this->drupalLogin($this->web_user);
@@ -311,22 +345,31 @@ class LinkTokenTest extends LinkBaseTestClass {
     $this->drupalPost(NULL, $edit, t('Save'));
     $url = $this->getUrl();
 
-    // change to anonymous user
+    // Change to anonymous user.
     $this->drupalLogout();
     $this->drupalGet($url);
 
     $this->assertRaw(l($input['label'], $input['href'] . '/page'));
-    //$this->fail($this->content);
+    // $this->fail($this->content);.
   }
 
   /**
-   *  Trying to set the url to contain a token.
+   * Trying to set the url to contain a token.
+   *
+   * @codingStandardsIgnoreStart
    */
-  function _testUserTokenLinkCreateInURL2() {
-    $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content'));
+  public function _testUserTokenLinkCreateInURL2() {
+    // @codingStandardsIgnoreEnd
+
+    $this->web_user = $this->drupalCreateUser(array(
+      'administer content types',
+      'administer fields',
+      'access content',
+      'create page content',
+    ));
     $this->drupalLogin($this->web_user);
 
-    // create field
+    // Create field.
     $name = strtolower($this->randomName());
     $edit = array(
       '_add_new_field[label]' => $name,
@@ -337,20 +380,21 @@ class LinkTokenTest extends LinkBaseTestClass {
     $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
     $this->drupalPost(NULL, array(
       'title' => 'required',
-      'enable_tokens' => 1), t('Save field settings'));
+      'enable_tokens' => 1,
+    ), t('Save field settings'));
 
     // Is field created?
     $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
 
-    // create page form
+    // Create page form.
     $this->drupalGet('node/add/page');
     $field_name = 'field_' . $name;
     $this->assertField($field_name . '[0][title]', 'Title found');
     $this->assertField($field_name . '[0][url]', 'URL found');
 
     $input = array(
-        'href' => 'http://example.com/' . $this->randomName(),
-        'label' => $this->randomName(),
+      'href' => 'http://example.com/' . $this->randomName(),
+      'label' => $this->randomName(),
     );
 
     $this->drupalLogin($this->web_user);
@@ -364,22 +408,34 @@ class LinkTokenTest extends LinkBaseTestClass {
     $this->drupalPost(NULL, $edit, t('Save'));
     $url = $this->getUrl();
 
-    // change to anonymous user
+    // Change to anonymous user.
     $this->drupalLogout();
     $this->drupalGet($url);
 
     $this->assertRaw(l($input['label'], $input['href'] . '/' . $this->web_user->uid));
   }
-  
+
   /**
-   *  Test that if you have a title and no url on a field which does not have tokens enabled,
-   *  that the title is sanitized once.
+   * CRUD Title Only Title No Link.
+   *
+   * Test that if you have a title and no url on a field which does not have
+   * tokens enabled, that the title is sanitized once.
+   *
+   * @codingStandardsIgnoreStart
    */
-  function testCRUDTitleOnlyTitleNoLink2() {
-    $this->web_user = $this->drupalCreateUser(array('administer content types', 'administer fields', 'access content', 'create page content'));
+  public function testCRUDTitleOnlyTitleNoLink2() {
+    //@codingStandardsIgnoreEnd
+
+    $this->web_user = $this->drupalCreateUser(array(
+      'administer content types',
+      'administer fields',
+      'access content',
+      'create page content',
+    ));
+
     $this->drupalLogin($this->web_user);
 
-    // create field
+    // Create field.
     $name = strtolower($this->randomName());
     $field_name = 'field_' . $name;
     $edit = array(
@@ -397,8 +453,8 @@ class LinkTokenTest extends LinkBaseTestClass {
 
     // Is field created?
     $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
-    
-    // create page form
+
+    // Create page form.
     $this->drupalGet('node/add/page');
     $this->assertField($field_name . '[und][0][url]', 'URL found');
 
@@ -415,13 +471,12 @@ class LinkTokenTest extends LinkBaseTestClass {
     $this->drupalPost(NULL, $edit, t('Save'));
 
     $url = $this->getUrl();
-    
-    // change to anonymous user
+
+    // Change to anonymous user.
     $this->drupalLogout();
     $this->drupalGet($url);
 
     $this->assertRaw('This & That');
   }
-  
-  
+
 }
diff --git a/tests/link.validate.test b/tests/link.validate.test
index 8532b4f..89265ef 100644
--- a/tests/link.validate.test
+++ b/tests/link.validate.test
@@ -5,8 +5,14 @@
  * Tests that exercise the validation functions in the link module.
  */
 
+/**
+ * Validate Test Case.
+ */
 class LinkValidateTestCase extends LinkBaseTestClass {
 
+  /**
+   * Create Link.
+   */
   protected function createLink($url, $title, $attributes = array()) {
     return array(
       'url' => $url,
@@ -17,8 +23,11 @@ class LinkValidateTestCase extends LinkBaseTestClass {
 
   /**
    * Takes a url, and sees if it can validate that the url is valid.
+   *
+   * @codingStandardsIgnoreStart
    */
   protected function link_test_validate_url($url) {
+    // @codingStandardsIgnoreEnd
 
     $field_name = $this->createLinkField();
 
@@ -26,11 +35,11 @@ class LinkValidateTestCase extends LinkBaseTestClass {
     $settings = array(
       'title' => $label,
       $field_name => array(
-        LANGUAGE_NONE=> array(
+        LANGUAGE_NONE => array(
           array(
             'title' => $label,
             'url' => $url,
-          )
+          ),
         ),
       ),
     );
@@ -41,10 +50,16 @@ class LinkValidateTestCase extends LinkBaseTestClass {
 
     $this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
   }
-}
 
+}
+/**
+ * Class for Validate Test.
+ */
 class LinkValidateTest extends LinkValidateTestCase {
 
+  /**
+   * Get Info.
+   */
   public static function getInfo() {
     return array(
       'name' => 'Link Validation Tests',
@@ -53,24 +68,34 @@ class LinkValidateTest extends LinkValidateTestCase {
     );
   }
 
-  function test_link_validate_basic_url() {
+  /**
+   * Validate basic URL.
+   *
+   * @codingStandardsIgnoreStart
+   */
+  public function test_link_validate_basic_url() {
+    // @codingStandardsIgnoreEnd
     $this->link_test_validate_url('http://www.example.com');
   }
 
   /**
    * Test if we're stopped from posting a bad url on default validation.
+   *
+   * @codingStandardsIgnoreStart
    */
-  function test_link_validate_bad_url_validate_default() {
+  public function test_link_validate_bad_url_validate_default() {
+    // @codingStandardsIgnoreEnd
     $this->web_user = $this->drupalCreateUser(array('administer content types',
-                                             'administer fields',
-                                             'administer nodes',
-                                             'administer filters',
-                                             'access content',
-                                             'create page content',
-                                             'access administration pages'));
+      'administer fields',
+      'administer nodes',
+      'administer filters',
+      'access content',
+      'create page content',
+      'access administration pages',
+    ));
     $this->drupalLogin($this->web_user);
 
-    // create field
+    // Create field.
     $name = strtolower($this->randomName());
     $edit = array(
       'fields[_add_new_field][label]' => $name,
@@ -87,13 +112,12 @@ class LinkValidateTest extends LinkValidateTestCase {
     node_types_rebuild();
     menu_rebuild();
 
-    // create page form
+    // 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',
@@ -105,18 +129,22 @@ class LinkValidateTest extends LinkValidateTestCase {
 
   /**
    * Test if we're stopped from posting a bad url with validation on.
+   *
+   * @codingStandardsIgnoreStart
    */
-  function test_link_validate_bad_url_validate_on() {
+  public function test_link_validate_bad_url_validate_on() {
+    // @codingStandardsIgnoreEnd
     $this->web_user = $this->drupalCreateUser(array('administer content types',
-                                             'administer fields',
-                                             'administer nodes',
-                                             'administer filters',
-                                             'access content',
-                                             'create page content',
-                                             'access administration pages'));
+      'administer fields',
+      'administer nodes',
+      'administer filters',
+      'access content',
+      'create page content',
+      'access administration pages',
+    ));
     $this->drupalLogin($this->web_user);
 
-    // create field
+    // Create field.
     $name = strtolower($this->randomName());
     $edit = array(
       'fields[_add_new_field][label]' => $name,
@@ -133,13 +161,12 @@ class LinkValidateTest extends LinkValidateTestCase {
     node_types_rebuild();
     menu_rebuild();
 
-    // create page form
+    // 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',
@@ -152,18 +179,22 @@ class LinkValidateTest extends LinkValidateTestCase {
 
   /**
    * Test if we can post a bad url if the validation is expressly turned off.
+   *
+   * @codingStandardsIgnoreStart
    */
-  function test_link_validate_bad_url_validate_off() {
+  public function test_link_validate_bad_url_validate_off() {
+    // @codingStandardsIgnoreEnd
     $this->web_user = $this->drupalCreateUser(array('administer content types',
-                                             'administer fields',
-                                             'administer nodes',
-                                             'administer filters',
-                                             'access content',
-                                             'create page content',
-                                             'access administration pages'));
+      'administer fields',
+      'administer nodes',
+      'administer filters',
+      'access content',
+      'create page content',
+      'access administration pages',
+    ));
     $this->drupalLogin($this->web_user);
 
-    // create field
+    // Create field.
     $name = strtolower($this->randomName());
     $edit = array(
       'fields[_add_new_field][label]' => $name,
@@ -175,6 +206,7 @@ class LinkValidateTest extends LinkValidateTestCase {
     $this->drupalPost(NULL, array(), t('Save field settings'));
     $this->drupalPost(NULL, array('instance[settings][validate_url]' => FALSE), t('Save settings'));
 
+    // @codingStandardsIgnoreLine
     /*$instance_details = db_query("SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = 'page'", array(':field_name' => 'field_'. $name))->fetchObject();
     $this->fail('
'. print_r($instance_details, TRUE) .'
'); $this->fail('
'. print_r(unserialize($instance_details->data), TRUE) .'
');*/ @@ -184,13 +216,12 @@ class LinkValidateTest extends LinkValidateTestCase { node_types_rebuild(); menu_rebuild(); - // create page form + // 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', @@ -201,24 +232,32 @@ class LinkValidateTest extends LinkValidateTestCase { } /** - * Test if a bad url can sneak through un-filtered if we play with the validation... + * Validate switching between validation status. + * + * Test if a bad url can sneak through un-filtered if we play with the + * validation... + * + * @codingStandardsIgnoreStart */ - function x_test_link_validate_switching_between_validation_status() { + public function x_test_link_validate_switching_between_validation_status() { + // @codingStandardsIgnoreEnd $this->acquireContentTypes(1); $this->web_user = $this->drupalCreateUser(array('administer content types', - 'administer fields', - 'administer nodes', - 'access administration pages', - 'access content', - 'create ' . $this->content_types[0]->type . ' content', - 'edit any ' . $this->content_types[0]->type . ' content')); + 'administer fields', + 'administer nodes', + 'access administration pages', + 'access content', + 'create ' . $this->content_types[0]->type . ' content', + 'edit any ' . $this->content_types[0]->type . ' content', + )); $this->drupalLogin($this->web_user); 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 + // <-- This is needed or we have an error. + 'attributes' => array(), 'validate_url' => 0, ); @@ -237,7 +276,7 @@ class LinkValidateTest extends LinkValidateTestCase { $edit[$field['field_name'] . '[0][title]'] = $title; $this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save')); - // $this->pass($this->content); + // $this->pass($this->content);. // @codingStandardsIgnoreLine $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($url)))); @@ -251,8 +290,9 @@ class LinkValidateTest extends LinkValidateTestCase { // Turn the array validation back _on_. $edit = array('validate_url' => TRUE); $node_type_link = str_replace('_', '-', $node->type); - //$this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']); - //$this->fail($this->content); + // @codingStandardsIgnoreLine + // $this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']); + // $this->fail($this->content);. $this->drupalPost('admin/content/node-type/' . $node_type_link . '/fields/' . $field['field_name'], $edit, t('Save field settings')); $this->drupalGet('node/' . $node->nid); @@ -260,16 +300,26 @@ class LinkValidateTest extends LinkValidateTestCase { // url() function. But we should have a test that makes sure it continues // to work. $this->assertNoRaw($url, 'Make sure Javascript does not display.'); - // $this->fail($this->content); + // $this->fail($this->content);. } - // Validate that '' is a valid url. - function test_link_front_url() { + /** + * Validate that '' is a valid url. + * + * @codingStandardsIgnoreStart + */ + public function test_link_front_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url(''); } - // Validate that an internal url would be accepted. - function test_link_internal_url() { + /** + * Validate that an internal url would be accepted. + * + * @codingStandardsIgnoreStart + */ + public function test_link_internal_url() { + // @codingStandardsIgnoreEnd // Create the content first. $node = $this->drupalCreateNode(); @@ -279,22 +329,45 @@ class LinkValidateTest extends LinkValidateTestCase { $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.'); } - // Validate a simple mailto. - function test_link_mailto() { + /** + * Validate a simple mailto. + * + * @codingStandardsIgnoreStart + */ + public function test_link_mailto() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('mailto:jcfiala@gmail.com'); } - function test_link_external_https() { + /** + * Check link external https. + * + * @codingStandardsIgnoreStart + */ + public function test_link_external_https() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('https://www.example.com/'); } - function test_link_ftp() { + /** + * Check link FTP. + * + * @codingStandardsIgnoreStart + */ + public function test_link_ftp() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('ftp://www.example.com/'); } -} +} +/** + * Validate Test News. + */ class LinkValidateTestNews extends LinkValidateTestCase { + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link News Validation Tests', @@ -303,18 +376,35 @@ class LinkValidateTestNews extends LinkValidateTestCase { ); } - // Validate a news link to a message group - function test_link_news() { + /** + * Validate a news link to a message group. + * + * @codingStandardsIgnoreStart + */ + public function test_link_news() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('news:comp.infosystems.www.misc'); } - // Validate a news link to a message id. Said ID copied off of google groups. - function test_link_news_message() { + /** + * Validate a news link to a message id. Said ID copied off of google groups. + * + * @codingStandardsIgnoreStart + */ + public function test_link_news_message() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org'); } -} +} +/** + * Validate Specific URL. + */ class LinkValidateSpecificURL extends LinkValidateTestCase { + + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link Specific URL Validation Tests', @@ -323,24 +413,53 @@ class LinkValidateSpecificURL extends LinkValidateTestCase { ); } - // Lets throw in a lot of umlouts for testing! - function test_umlout_url() { + /** + * Lets throw in a lot of umlouts for testing! + * + * @codingStandardsIgnoreStart + */ + public function test_umlout_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://üÜü.exämple.com/nöde'); } - function test_umlout_mailto() { + /** + * Check umlout mailto. + * + * @codingStandardsIgnoreStart + */ + public function test_umlout_mailto() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('mailto:Üser@exÅmple.com'); } - function test_german_b_url() { + /** + * Check german b in url. + * + * @codingStandardsIgnoreStart + */ + public function test_german_b_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://www.test.com/ßstuff'); } - function test_special_n_url() { + /** + * Check Special in url. + * + * @codingStandardsIgnoreStart + */ + public function test_special_n_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://www.testÑñ.com/'); } - function test_curly_brackets_in_query() { + /** + * Curly Brackets in query. + * + * @codingStandardsIgnoreStart + */ + public function test_curly_brackets_in_query() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}'); } @@ -348,8 +467,10 @@ class LinkValidateSpecificURL extends LinkValidateTestCase { * Here, we're testing that a very long url is stored properly in the db. * * Basically, trying to test http://drupal.org/node/376818 + * @codingStandardsIgnoreStart */ - function testLinkURLFieldIsBig() { + public function testLinkURLFieldIsBig() { + // @codingStandardsIgnoreEnd $long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A'; $this->link_test_validate_url($long_url); } @@ -357,12 +478,18 @@ class LinkValidateSpecificURL extends LinkValidateTestCase { } /** - * A series of tests of links, only going against the link_validate_url function in link.module. + * Validate Url Light. + * + * A series of tests of links, only going against the link_validate_url function + * in link.module. * * Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 ! */ class LinkValidateUrlLight extends DrupalWebTestCase { + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link Light Validation Tests', @@ -370,72 +497,107 @@ class LinkValidateUrlLight extends DrupalWebTestCase { 'group' => 'Link', ); } - - function setUp() { + + /** + * Setup. + */ + public function setUp() { parent::setUp('link'); } /** - * Translates the LINK type constants to english for display and debugging of tests + * Name Link Type. + * + * Translates the LINK type constants to english for display and debugging of + * tests. + * + * @codingStandardsIgnoreStart */ - function name_Link_Type($type) { + public function name_Link_Type($type) { + // @codingStandardsIgnoreEnd switch ($type) { case LINK_FRONT: return "Front"; + case LINK_EMAIL: return "Email"; + case LINK_NEWS: return "Newsgroup"; + case LINK_INTERNAL: return "Internal Link"; + case LINK_EXTERNAL: return "External Link"; + case FALSE: return "Invalid Link"; + default: return "Bad Value:" . $type; } } - // Make sure that a link labeled works. - function testValidateFrontLink() { + /** + * Make sure that a link labeled works. + */ + public function testValidateFrontLink() { $valid = link_validate_url(''); $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified'); } - function testValidateEmailLink() { + /** + * Validate Email Link. + */ + public function testValidateEmailLink() { $valid = link_validate_url('mailto:bob@example.com'); $this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified"); } - function testValidateEmailLinkBad() { + /** + * Validate Email Link Bad. + */ + public function testValidateEmailLinkBad() { $valid = link_validate_url(':bob@example.com'); $this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed'); } - function testValidateNewsgroupLink() { + /** + * Validate Newsgroup Link. + */ + public function testValidateNewsgroupLink() { $valid = link_validate_url('news:comp.infosystems.www.misc'); $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.'); } - function testValidateNewsArticleLink() { + /** + * Validate News Article Link. + */ + public function testValidateNewsArticleLink() { $valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org'); $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.'); } - function testValidateBadNewsgroupLink() { + /** + * Validate Bad Newsgroup Link. + */ + public function testValidateBadNewsgroupLink() { $valid = link_validate_url('news:comp.bad_name.misc'); $this->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.'); } - function testValidateInternalLinks() { + /** + * Validate Internal Links. + */ + public function testValidateInternalLinks() { $tempfile = drupal_tempnam('public://files', 'test'); $links = array( 'rss.xml', file_uri_target($tempfile), drupal_realpath($tempfile), ); - + foreach ($links as $link) { $type = link_url_type($link); $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.'); @@ -444,7 +606,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase { } } - function testValidateExternalLinks() { + /** + * Validate External Links. + */ + public function testValidateExternalLinks() { $links = array( 'http://localhost:8080/', 'www.example.com', @@ -460,7 +625,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase { 'www.test-site.com', 'http://example.com/index.php?q=node/123', 'http://example.com/?first_name=Joe Bob&last_name=Smith', - // Anchors + // Anchors. 'http://www.example.com/index.php#test', 'http://www.example.com/index.php#this@that.', 'http://www.example.com/index.php#', @@ -468,8 +633,22 @@ class LinkValidateUrlLight extends DrupalWebTestCase { 'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up', 'http://www.example.com/blah/#this@that?', ); + // Test all of the protocols. - $allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal')); + $allowed_protocols = variable_get('filter_allowed_protocols', array( + 'http', + 'https', + 'ftp', + 'news', + 'nntp', + 'telnet', + 'mailto', + 'irc', + 'ssh', + 'sftp', + 'webcal', + )); + foreach ($allowed_protocols as $protocol) { if ($protocol !== 'news' && $protocol !== 'mailto') { $links[] = $protocol . '://www.example.com'; @@ -480,20 +659,28 @@ class LinkValidateUrlLight extends DrupalWebTestCase { $this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.'); $valid = link_validate_url($link); $this->assertTrue($valid, 'Test ' . $link . ' is valid external link.'); - // The following two lines are commented out and only used for comparisons. - //$valid2 = valid_url($link, TRUE); - //$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link."); + // The following two lines are commented out and only used for + // comparisons. + // $valid2 = valid_url($link, TRUE); + // $this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");. } } - function testInvalidExternalLinks() { + /** + * Check Invalid External Links. + */ + public function testInvalidExternalLinks() { $links = array( 'http://www.ex ample.com/', - 'http://25.0.0/', // bad ip! + // Bad ip! + 'http://25.0.0/', 'http://4827.0.0.2/', - 'http://www.testß.com/', // ß not allowed in domain names! - 'http://.www.foo.bar./', // Bad TLD. - //'http://www.-fudge.com/', // domains can't have sections starting with a dash. + // ß not allowed in domain names! + 'http://www.testß.com/', + // Bad TLD. + 'http://.www.foo.bar./', + // Domains can't have sections starting with a dash. + // 'http://www.-fudge.com/', 'http://example.com/index.php?page=this\that', 'example@example.com', ); @@ -502,4 +689,5 @@ class LinkValidateUrlLight extends DrupalWebTestCase { $this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.'); } } + }