Commit e7007338 authored by Jonathan Smith's avatar Jonathan Smith Committed by Jonathan Smith
Browse files

Issue #2872885 by jonathan1055: Fix coding standards in 7.x for...

Issue #2872885 by jonathan1055: Fix coding standards in 7.x for tests/scheduler_api.test and scheduler_handler_field_scheduler_countdown.inc (which also required a change in scheduler.views.inc).
parent 1b4bb640
Loading
Loading
Loading
Loading
+4 −17
Changes for scheduler.views.inc: 4 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -73,9 +73,9 @@ function scheduler_views_data() {
  // Describe the two extra derived fields provided for Views.
  $tables['scheduler']['publish_countdown'] = array(
    'title' => t('Publish countdown'),
    'help' => t('Time until the article will be automatically published'),
    'help' => t('Time until the content will be published'),
    'field' => array(
      'handler' => 'scheduler_handler_field_scheduler_countdown',
      'handler' => 'SchedulerHandlerFieldSchedulerCountdown',
      'click sortable' => FALSE,
      'timestamp_field' => 'publish_on',
    ),
@@ -83,9 +83,9 @@ function scheduler_views_data() {

  $tables['scheduler']['unpublish_countdown'] = array(
    'title' => t('Unpublish countdown'),
    'help' => t('Time until the article will be automatically unpublished'),
    'help' => t('Time until the content will be unpublished'),
    'field' => array(
      'handler' => 'scheduler_handler_field_scheduler_countdown',
      'handler' => 'SchedulerHandlerFieldSchedulerCountdown',
      'click sortable' => FALSE,
      'timestamp_field' => 'unpublish_on',
    ),
@@ -93,16 +93,3 @@ function scheduler_views_data() {

  return $tables;
}

/**
 * Implements hook_views_handlers().
 */
function scheduler_views_handlers() {
  return array(
    'handlers' => array(
      'scheduler_handler_field_scheduler_countdown' => array(
        'parent' => 'views_handler_field',
      ),
    ),
  );
}
+27 −15
Changes for scheduler_handler_field_scheduler_countdown.inc: 27 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -10,16 +10,19 @@
/**
 * Field handler to display a countdown until a scheduled action.
 *
 * Defines class scheduler_handler_field_scheduler_countdown.
 * Defines class SchedulerHandlerFieldSchedulerCountdown.
 * The structure is [module]_handler_[type]_[tablename]_[fieldname]
 * However, for standards compliance, CamelCase is now used where possible.
 *
 * @see http://www.ericschaefer.org/blog/2011/01/09/custom-field-handlers-for-views-2-drupal
 */
class scheduler_handler_field_scheduler_countdown extends views_handler_field {
  CONST SECOND_SCALE = 1;
  CONST MINUTE_SCALE = 60;
  CONST HOUR_SCALE = 3600;
  CONST DAY_SCALE = 86400;
  CONST WEEK_SCALE = 604800;
class SchedulerHandlerFieldSchedulerCountdown extends views_handler_field {

  const SECOND_SCALE = 1;
  const MINUTE_SCALE = 60;
  const HOUR_SCALE = 3600;
  const DAY_SCALE = 86400;
  const WEEK_SCALE = 604800;

  /**
   * Add the timestamp_field into the SQL query.
@@ -28,7 +31,7 @@ class scheduler_handler_field_scheduler_countdown extends views_handler_field {
   * of seconds from now until publishing. If publish_on is in the past then
   * NULL is returned.
   */
  function query() {
  public function query() {
    $this->ensure_my_table();
    $this->node_table = $this->query->ensure_table('node', $this->relationship);
    $time_field = $this->definition['timestamp_field'];
@@ -41,7 +44,12 @@ class scheduler_handler_field_scheduler_countdown extends views_handler_field {
   * @return array
   *   An associative array containing the options.
   */
  function option_definition() {
  // @codingStandardsIgnoreStart
  // The name fails Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  // However, it is defined in Views module and cannot be corrected, hence we
  // need to ignore this fault and not report it.
  public function option_definition() {
  // @codingStandardsIgnoreEnd
    $options = parent::option_definition();
    $options['countdown_display'] = array('default' => 'smart');
    $options['units_display'] = array('default' => 'long');
@@ -51,7 +59,9 @@ class scheduler_handler_field_scheduler_countdown extends views_handler_field {
  /**
   * Defines the form for the user to select the display options.
   */
  function options_form(&$form, &$form_state) {
  // @codingStandardsIgnoreStart. Same as above.
  public function options_form(&$form, &$form_state) {
  // @codingStandardsIgnoreEnd
    parent::options_form($form, $form_state);
    $form['countdown_display'] = array(
      '#title' => t('Display countdown as'),
@@ -79,17 +89,19 @@ class scheduler_handler_field_scheduler_countdown extends views_handler_field {
  }

  /**
   * Callback function to keep only the array scale values which are smaller
   * than the countdown value being displayed.
   * Callback function for array_filter.
   *
   * Keep only the array scale values which are smaller than the countdown
   * value being displayed.
   */
  function scale_filter_callback($array_value) {
  public function scaleFilterCallback($array_value) {
    return ($this->raw_value >= $array_value);
  }

  /**
   * Renders the countdown value in the units required.
   */
  function render($values) {
  public function render($values) {
    $countdown_display = $this->options['countdown_display'];
    $this->raw_value = $values->{$this->field_alias};

@@ -102,7 +114,7 @@ class scheduler_handler_field_scheduler_countdown extends views_handler_field {
    );
    // If the field has been set to 'Smart', determine the right timescale.
    if ($countdown_display == 'smart') {
      $scales = array_filter($scales, array($this, 'scale_filter_callback'));
      $scales = array_filter($scales, array($this, 'scaleFilterCallback'));
      $scale = empty($scales) ? self::SECOND_SCALE : reset($scales);
    }
    // Otherwise use the fixed display requested.
+17 −13
Changes for tests/scheduler_api.test: 17 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@
 * @file
 * Tests for the Scheduler API.
 */

/**
 * Tests to cover the Scheduler API functions.
 */
class SchedulerApiTestCase extends DrupalWebTestCase {

  /**
@@ -27,7 +31,7 @@ class SchedulerApiTestCase extends DrupalWebTestCase {
  /**
   * {@inheritdoc}
   */
  function setUp() {
  public function setUp() {
    parent::setUp('scheduler', 'scheduler_test');

    // Add scheduler functionality to the 'scheduler_test' node type.
@@ -46,7 +50,7 @@ class SchedulerApiTestCase extends DrupalWebTestCase {
   * @todo Create and update the nodes through the interface so we can check if
   *   the correct messages are displayed.
   */
  function testAllowedPublishing() {
  public function testAllowedPublishing() {
    // Create a node that is not approved for publication. Then simulate a cron
    // run, and check that the node is not published.
    $node = $this->createUnapprovedNode();
@@ -101,14 +105,14 @@ class SchedulerApiTestCase extends DrupalWebTestCase {
  /**
   * Check to see if a node is not published.
   *
   * @param $nid
   *   The nid of the node to check.
   * @param $message
   * @param int $nid
   *   The id of the node to check.
   * @param string $message
   *   The message to display along with the assertion.
   * @param $group
   * @param string $group
   *   The type of assertion - examples are "Browser", "PHP".
   *
   * @return
   * @return bool
   *   TRUE if the assertion succeeded, FALSE otherwise.
   */
  public function assertNodeNotPublished($nid, $message = NULL, $group = 'Other') {
@@ -119,14 +123,14 @@ class SchedulerApiTestCase extends DrupalWebTestCase {
  /**
   * Check to see if a node is published.
   *
   * @param $nid
   *   The nid of the node to check.
   * @param $message
   * @param int $nid
   *   The id of the node to check.
   * @param string $message
   *   The message to display along with the assertion.
   * @param $group
   * @param string $group
   *   The type of assertion - examples are "Browser", "PHP".
   *
   * @return
   * @return bool
   *   TRUE if the assertion succeeded, FALSE otherwise.
   */
  public function assertNodePublished($nid, $message = NULL, $group = 'Other') {
@@ -138,7 +142,7 @@ class SchedulerApiTestCase extends DrupalWebTestCase {
   * Returns the publication status of a node.
   *
   * @param int $nid
   *   The nid of the node for which the publication status is desired.
   *   The id of the node for which the publication status is desired.
   *
   * @return bool
   *   TRUE if the node is published, FALSE otherwise.