Commit 0c2d3b04 authored by Damien McKenna's avatar Damien McKenna Committed by Damien McKenna
Browse files

Issue #3276311 by DamienMcKenna: Test coverage for Date Repeat Field submodule.

parent 0bf66bb3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ Date 7.x-2.x-dev, xxxx-xx-xx
#3273734 by DamienMcKenna: Verify rdf functions exist before using them.
#3276288 by DamienMcKenna: Change test group to "date" to make running all
  tests easier.
#3276311 by DamienMcKenna: Test coverage for Date Repeat Field submodule.


Date 7.x-2.12, 2021-10-07
+2 −0
Original line number Diff line number Diff line
@@ -8,3 +8,5 @@ dependencies[] = date:date
dependencies[] = date:date_repeat

stylesheets[all][] = date_repeat_field.css

files[] = tests/DateRepeatFieldTestCase.test
+82 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Test the handling of the Date Repeat Field module.
 */

/**
 * Test the handling of the Date Repeat Field module.
 */
class DateRepeatFieldTestCase extends DateFieldTestBase {

  /**
   * {@inheritdoc}
   */
  public function setUp(array $modules = array()) {
    $modules[] = 'date_repeat_test_feature';
    parent::setUp($modules);
  }

  /**
   * Date Field.
   */
  public static function getInfo() {
    return array(
      'name' => 'Date Repeat Field',
      'description' => 'Test handling of repeating date fields.',
      'group' => 'date',
    );
  }

  /**
   * Test the rrule output.
   */
  public function testRruleOutput() {
    // Create a node with a repeating date value.
    $this->drupalGet('node/add/date-repeat-test');
    $this->assertResponse(200);
    $edit = array(
      'title' => $this->randomName(8),
      'body[und][0][value]' => $this->randomName(16),
      // "From" date - 2021-01-14 @ 7:16pm.
      'field_date_repeat[und][0][value][year]' => 2021,
      'field_date_repeat[und][0][value][month]' => 1,
      'field_date_repeat[und][0][value][day]' => 14,
      'field_date_repeat[und][0][value][hour]' => 19,
      'field_date_repeat[und][0][value][minute]' => 16,
      // The repeat rules. For this test repeat the event every day.
      'field_date_repeat[und][0][show_repeat_settings]' => TRUE,
      'field_date_repeat[und][0][rrule][FREQ]' => 'DAILY',
      'field_date_repeat[und][0][rrule][daily][byday_radios]' => 'INTERVAL',
      'field_date_repeat[und][0][rrule][daily][INTERVAL_child]' => 1,
      'field_date_repeat[und][0][rrule][range_of_repeat]' => 'COUNT',
      'field_date_repeat[und][0][rrule][count_child]' => 10,
    );
    $this->drupalPost(NULL, $edit, 'Save');
    $this->assertResponse(200);
    $this->assertText('Date Repeat Test ' . $edit['title'] . ' has been created.');

    // Verify the default output.
    $this->assertText('Repeats every day 10 times.');
    $this->assertText('Thu, 01/14/2021 - 19:16');
    $this->assertText('Fri, 01/15/2021 - 19:16');
    $this->assertText('Sat, 01/16/2021 - 19:16');
    $this->assertText('Sun, 01/17/2021 - 19:16');
    $this->assertText('Mon, 01/18/2021 - 19:16');
    $this->assertText('Tue, 01/19/2021 - 19:16');
    $this->assertText('Wed, 01/20/2021 - 19:16');
    $this->assertText('Thu, 01/21/2021 - 19:16');
    $this->assertText('Fri, 01/22/2021 - 19:16');
    $this->assertText('Sat, 01/23/2021 - 19:16');

    // Make sure there isn't an 11th occurrence.
    $this->assertNoText('Sun, 01/24/2021 - 19:16');

    // Examine the stored data.
    $node = node_load(1);
    $this->verbose($node);
    $this->assertTrue(count($node->field_date_repeat[LANGUAGE_NONE]), 10);
  }

}
+68 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * date_repeat_test_feature.features.field_base.inc
 */

/**
 * Implements hook_field_default_field_bases().
 */
function date_repeat_test_feature_field_default_field_bases() {
  $field_bases = array();

  // Exported field_base: 'body'.
  $field_bases['body'] = array(
    'active' => 1,
    'cardinality' => 1,
    'deleted' => 0,
    'entity_types' => array(
      0 => 'node',
    ),
    'field_name' => 'body',
    'indexes' => array(
      'format' => array(
        0 => 'format',
      ),
    ),
    'locked' => 0,
    'module' => 'text',
    'settings' => array(),
    'translatable' => 1,
    'type' => 'text_with_summary',
  );

  // Exported field_base: 'field_date_repeat'.
  $field_bases['field_date_repeat'] = array(
    'active' => 1,
    'cardinality' => -1,
    'deleted' => 0,
    'entity_types' => array(),
    'field_name' => 'field_date_repeat',
    'indexes' => array(
      'value' => array(
        0 => 'value',
      ),
    ),
    'locked' => 0,
    'module' => 'date',
    'settings' => array(
      'granularity' => array(
        'day' => 'day',
        'hour' => 'hour',
        'minute' => 'minute',
        'month' => 'month',
        'second' => 0,
        'year' => 'year',
      ),
      'repeat' => 1,
      'timezone_db' => '',
      'todate' => '',
      'tz_handling' => 'none',
    ),
    'translatable' => 1,
    'type' => 'date',
  );

  return $field_bases;
}
+124 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * date_repeat_test_feature.features.field_instance.inc
 */

/**
 * Implements hook_field_default_field_instances().
 */
function date_repeat_test_feature_field_default_field_instances() {
  $field_instances = array();

  // Exported field_instance: 'node-date_repeat_test-body'.
  $field_instances['node-date_repeat_test-body'] = array(
    'bundle' => 'date_repeat_test',
    'default_value' => NULL,
    'deleted' => 0,
    'description' => '',
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'module' => 'text',
        'settings' => array(),
        'type' => 'text_default',
        'weight' => 0,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'module' => 'text',
        'settings' => array(
          'trim_length' => 600,
        ),
        'type' => 'text_summary_or_trimmed',
        'weight' => 0,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'body',
    'label' => 'Body',
    'required' => FALSE,
    'settings' => array(
      'display_summary' => TRUE,
      'text_processing' => 1,
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'module' => 'text',
      'settings' => array(
        'rows' => 20,
        'summary_rows' => 5,
      ),
      'type' => 'text_textarea_with_summary',
      'weight' => 1,
    ),
  );

  // Exported field_instance: 'node-date_repeat_test-field_date_repeat'.
  $field_instances['node-date_repeat_test-field_date_repeat'] = array(
    'bundle' => 'date_repeat_test',
    'default_value' => NULL,
    'deleted' => 0,
    'description' => '',
    'display' => array(
      'default' => array(
        'label' => 'above',
        'module' => 'date',
        'settings' => array(
          'custom_date_format' => '',
          'format_type' => 'medium',
          'fromto' => 'both',
          'multiple_from' => '',
          'multiple_number' => '',
          'multiple_to' => '',
          'show_remaining_days' => FALSE,
          'show_repeat_rule' => 'show',
        ),
        'type' => 'date_default',
        'weight' => 7,
      ),
      'teaser' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_date_repeat',
    'label' => 'Date with repeat',
    'required' => 0,
    'settings' => array(
      'default_value' => 'now',
      'default_value2' => 'blank',
      'default_value_code' => '',
      'default_value_code2' => '',
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'active' => 1,
      'module' => 'date',
      'settings' => array(
        'display_all_day' => 0,
        'increment' => 1,
        'input_format' => 'm/d/Y - H:i:s',
        'input_format_custom' => '',
        'label_position' => 'above',
        'no_fieldset' => 0,
        'repeat_collapsed' => 1,
        'text_parts' => array(),
        'year_range' => '-3:+3',
      ),
      'type' => 'date_select',
      'weight' => 8,
    ),
  );

  // Translatables
  // Included for use with string extractors like potx.
  t('Body');
  t('Date with repeat');

  return $field_instances;
}
Loading