Skip to content
Snippets Groups Projects
Commit 968551b7 authored by Alanna Burke's avatar Alanna Burke Committed by Lachlan Ennis
Browse files

Issue #2748635 by aburke626: Code Standards Cleanup

parent b78a7612
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,8 @@ span.mailto {
/* Hide the extra spans when printing. */
@media print {
span.ext, span.mailto {
span.ext,
span.mailto {
display: none;
padding: 0;
}
......
<?php
/**
* @file
* Install file for External Links module.
*/
/**
* Implements hook_install().
......
......@@ -79,8 +79,8 @@ Drupal.extlink.attach = function (context, settings) {
}
// Do not include area tags with begin with mailto: (this prohibits
// icons from being added to image-maps).
else if (this.tagName != 'AREA'
&& url.indexOf('mailto:') == 0
else if (this.tagName != 'AREA'
&& url.indexOf('mailto:') == 0
&& !(extCssExclude && $(this).parents(extCssExclude).length > 0)
&& !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) {
mailto_links.push(this);
......
<?php
/**
* @file
* External Link module.
*/
/**
* Implements hook_menu().
*/
......@@ -20,25 +25,30 @@ function extlink_menu() {
*/
function extlink_page_build() {
$path = drupal_get_path('module', 'extlink');
drupal_add_js($path .'/extlink.js', array('every_page' => TRUE));
drupal_add_js(array('extlink' => array(
'extTarget' => variable_get('extlink_target', 0),
'extClass' => variable_get('extlink_class', 'ext'),
'extLabel' => check_plain(variable_get('extlink_label', t('(link is external)'))),
'extImgClass' => variable_get('extlink_img_class', 0),
'extIconPlacement' => variable_get('extlink_icon_placement', 'append'),
'extSubdomains' => variable_get('extlink_subdomains', 1),
'extExclude' => variable_get('extlink_exclude', ''),
'extInclude' => variable_get('extlink_include', ''),
'extCssExclude' => variable_get('extlink_css_exclude', ''),
'extCssExplicit' => variable_get('extlink_css_explicit', ''),
'extAlert' => variable_get('extlink_alert', 0),
'extAlertText' => variable_get('extlink_alert_text', 'This link will take you to an external web site. We are not responsible for their content.'),
'mailtoClass' => variable_get('extlink_mailto_class', 'mailto'),
'mailtoLabel' => check_plain(variable_get('extlink_mailto_label', t('(link sends e-mail)'))),
)), 'setting');
drupal_add_js($path . '/extlink.js', array('every_page' => TRUE));
drupal_add_js(array(
'extlink' => array(
'extTarget' => variable_get('extlink_target', 0),
'extClass' => variable_get('extlink_class', 'ext'),
'extLabel' => check_plain(variable_get('extlink_label', t('(link is external)'))),
'extImgClass' => variable_get('extlink_img_class', 0),
'extIconPlacement' => variable_get('extlink_icon_placement', 'append'),
'extSubdomains' => variable_get('extlink_subdomains', 1),
'extExclude' => variable_get('extlink_exclude', ''),
'extInclude' => variable_get('extlink_include', ''),
'extCssExclude' => variable_get('extlink_css_exclude', ''),
'extCssExplicit' => variable_get('extlink_css_explicit', ''),
'extAlert' => variable_get('extlink_alert', 0),
'extAlertText' => variable_get('extlink_alert_text', 'This link will take you to an external web site. We are not responsible for their content.'),
'mailtoClass' => variable_get('extlink_mailto_class', 'mailto'),
'mailtoLabel' => check_plain(variable_get('extlink_mailto_label', t('(link sends e-mail)'))),
),
), 'setting');
}
/**
* Administrative settings.
*/
function extlink_admin_settings() {
$form = array();
......@@ -47,7 +57,15 @@ function extlink_admin_settings() {
'#title' => t('Place an icon next to external links.'),
'#return_value' => 'ext',
'#default_value' => variable_get('extlink_class', 'ext'),
'#description' => t('Places an !icon icon next to external links.', array('!icon' => theme('image', array('path' => drupal_get_path('module', 'extlink') . '/extlink.png', 'alt' => t('External Links icon'))))),
'#description' => t('Places an !icon icon next to external links.',
array(
'!icon' => theme('image',
array(
'path' => drupal_get_path('module', 'extlink') . '/extlink.png',
'alt' => t('External Links icon'),
),
),
)),
);
$form['extlink_mailto_class'] = array(
......@@ -55,7 +73,15 @@ function extlink_admin_settings() {
'#title' => t('Place an icon next to mailto links.'),
'#return_value' => 'mailto',
'#default_value' => variable_get('extlink_mailto_class', 'mailto'),
'#description' => t('Places an !icon icon next to mailto links.', array('!icon' => theme('image',array('path' => drupal_get_path('module', 'extlink') . '/mailto.png', 'alt' => t('Email links icon'))))),
'#description' => t('Places an !icon icon next to mailto links.',
array(
'!icon' => theme('image',
array(
'path' => drupal_get_path('module', 'extlink') . '/mailto.png',
'alt' => t('Email links icon'),
),
),
)),
);
$form['extlink_img_class'] = array(
......@@ -129,12 +155,9 @@ function extlink_admin_settings() {
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
'<p>' . t('External links uses patterns (regular expressions) to match the "href" property of links.') . '</p>' .
t('Here are some common patterns.') .
theme('item_list', array('items' => $patterns)) .
t('Common special characters:') .
theme('item_list', array('items' => $wildcards)) .
'<p>' . t('All special characters (!characters) must also be escaped with backslashes. Patterns are not case-sensitive. Any <a href="http://www.javascriptkit.com/javatutors/redev2.shtml">pattern supported by JavaScript</a> may be used.', array('!characters' => '<code>^ $ . ? ( ) | * +</code>')) . '</p>',
'<p>' . t('External links uses patterns (regular expressions) to match the "href" property of links.') . '</p>' . t('Here are some common patterns.') .
theme('item_list', array('items' => $patterns)) . t('Common special characters:') .
theme('item_list', array('items' => $wildcards)) . '<p>' . t('All special characters (!characters) must also be escaped with backslashes. Patterns are not case-sensitive. Any <a href="http://www.javascriptkit.com/javatutors/redev2.shtml">pattern supported by JavaScript</a> may be used.', array('!characters' => '<code>^ $ . ? ( ) | * +</code>')) . '</p>',
);
$form['patterns']['extlink_exclude'] = array(
......@@ -160,7 +183,7 @@ function extlink_admin_settings() {
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
'<p>' . t('Use CSS selectors to exclude entirely or only look inside explicitly specified classes and IDs for external links. These will be passed straight to jQuery for matching.') . '</p>',
'<p>' . t('Use CSS selectors to exclude entirely or only look inside explicitly specified classes and IDs for external links. These will be passed straight to jQuery for matching.') . '</p>',
);
$form['css_matching']['extlink_css_exclude'] = array(
......@@ -182,22 +205,25 @@ function extlink_admin_settings() {
return system_settings_form($form);
}
/**
* Validation handler for admin settings form.
*/
function extlink_admin_settings_validate($form, &$form_state) {
// Check if the exclude pattern is a valid regular expression
// Check if the exclude pattern is a valid regular expression.
if ($exclude = $form_state['values']['extlink_exclude']) {
// Testing the regex via replace
// Testing the regex via replace.
$regexeval = @preg_replace('/' . $exclude . '/', '', 'Lorem ipsum');
// If the regex returns NULL, then throw an error and reset the variable
// If the regex returns NULL, then throw an error and reset the variable.
if ($regexeval === NULL) {
form_set_error('extlink_exclude', t('Invalid regular expression.'));
variable_set('extlink_exclude', '');
}
}
// Check if the include pattern is a valid regular expression
// Check if the include pattern is a valid regular expression.
if ($include = $form_state['values']['extlink_include']) {
// Testing the regex via replace
$regexeval = @preg_replace('/' . $include . '/', '', 'Lorem ipsum');
// If the regex returns NULL, then throw an error and reset the variable
// Testing the regex via replace.
$regexeval = @preg_replace('/' . $include . '/', '', 'Lorem ipsum');
// If the regex returns NULL, then throw an error and reset the variable.
if ($regexeval === NULL) {
form_set_error('extlink_include', t('Invalid regular expression.'));
variable_set('extlink_include', '');
......
<?php
/**
* @file
* External Link tests.
*/
/**
* Base class for External Link tests.
*
......@@ -9,20 +14,24 @@ class ExtlinkBaseWebTestCase extends DrupalWebTestCase {
* User with various administrative permissions.
* @var Drupal user
*/
protected $admin_user;
protected $adminUser;
/**
* Normal visitor with limited permissions
* Normal visitor with limited permissions.
*
* @var Drupal user;
*/
protected $normal_user;
/**
* Drupal path of the (general) External Links admin page
protected $normalUser;
/**
* Drupal path of the (general) External Links admin page.
*/
const EXTLINK_ADMIN_PATH = 'admin/config/user-interface/extlink';
function setUp() {
/**
* Set up tests.
*/
public function setUp() {
// Enable any module that you will need in your tests.
parent::setUp('extlink');
......@@ -31,15 +40,18 @@ class ExtlinkBaseWebTestCase extends DrupalWebTestCase {
'access comments', 'post comments', 'skip comment approval',
'access content', 'create page content', 'edit own page content',
);
$this->normal_user = $this->drupalCreateUser($permissions);
$this->normalUser = $this->drupalCreateUser($permissions);
// Create an admin user.
$permissions[] = 'administer site configuration';
$permissions[] = 'administer permissions';
$permissions[] = 'administer content types';
$this->admin_user = $this->drupalCreateUser($permissions);
$this->adminUser = $this->drupalCreateUser($permissions);
}
/**
* Generate values for node forms.
*/
protected function getNodeFormValues() {
$edit = array(
'title' => 'node_title ' . $this->randomName(32),
......@@ -47,20 +59,28 @@ class ExtlinkBaseWebTestCase extends DrupalWebTestCase {
);
return $edit;
}
/**
* Test if External Link is present
* Test if External Link is present.
*/
protected function assertExternalLinkPresence() {
$elements = $this->xpath('//span[@class="ext"]');
if (count($elements) > 0)
$this->pass('There should be an External Link on the form.', 'External Links');
else
$this->fail('There should be an External Link on the form.', 'External Links');
if (count($elements) > 0) {
$this->pass('There should be an External Link on the form.', 'External Links');
}
else {
$this->fail('There should be an External Link on the form.', 'External Links');
}
}
}
/**
* Test Case for General External Links functionality.
*/
class ExtlinkTestCase extends ExtlinkBaseWebTestCase {
/**
* Get test info.
*/
public static function getInfo() {
return array(
'name' => t('General External Links functionality'),
......@@ -70,7 +90,13 @@ class ExtlinkTestCase extends ExtlinkBaseWebTestCase {
}
}
/**
* Test Case for External Links administration functionality.
*/
class ExtlinkAdminTestCase extends ExtlinkBaseWebTestCase {
/**
* Get test info.
*/
public static function getInfo() {
return array(
'name' => t('External Links administration functionality'),
......@@ -82,16 +108,15 @@ class ExtlinkAdminTestCase extends ExtlinkBaseWebTestCase {
/**
* Test access to the admin pages.
*/
function testAdminAccess() {
$this->drupalLogin($this->normal_user);
public function testAdminAccess() {
$this->drupalLogin($this->normalUser);
$this->drupalGet(self::EXTLINK_ADMIN_PATH);
file_put_contents('tmp.simpletest.html', $this->drupalGetContent());
$this->assertText(t('Access denied'), 'Normal users should not be able to access the External Links admin pages', 'External Links');
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$this->drupalGet(self::EXTLINK_ADMIN_PATH);
file_put_contents('tmp.simpletest.html', $this->drupalGetContent());
$this->assertNoText(t('Access denied'), 'Admin users should be able to access the External Links admin pages', 'External Links');
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment