You are here

BasicFunctionalityTest.test in Calendar Systems 8.2

File

src/Tests/BasicFunctionalityTest.test
View source
<?php

namespace Drupal\calendar_systems\Tests;

use Drupal\simpletest\WebTestBase;

/**
 * Tests basic functionality
 *
 * @group calendar_systems
 *
 * Note: Test that CalendarSystems works properly
 */
class BasicFunctionalityTest extends WebTestBase {
  public static $modules = array(
    'calendar_systems',
  );

  /**
   * setUp() performs any pre-requisite tasks that need to happen.
   */
  public function setUp() {
    parent::setUp();
  }
  function testCalendarSystemsConversion() {
    $supported_calendars = array(
      'iranian' => array(
        'source' => '',
        'gregorian' => '',
      ),
      'arabic' => array(
        'source' => '',
        'gregorian' => '',
      ),
      'gregorian' => array(
        'source' => '',
        'gregorian' => '',
      ),
      'julian' => array(
        'source' => '',
        'gregorian' => '',
      ),
      'thai' => array(
        'source' => '',
        'gregorian' => '',
      ),
    );
    foreach ($supported_calendars as $calendarName => $calendarInfo) {
      $calendar = calendar_systems_get_calendar_instance($calendarName);
      $val = $calendar
        ->strToTimestamp('1380-05-10');
      $this
        ->assertEqual($result, $calendarInfo['gregorian'], "{$calendarName} to gregorian");
      $this
        ->assertEqual($calendarInfo['gregorian'], $result, "{$calendarName} from gregorian");
    }
  }

  /**
   *
   */
  function testCalendarSystemsConversionIranian() {
    $message = "Jalali Date To Gregorian Conversion does not work properly";
    $result = true;
    $calendar = calendar_systems_get_calendar_instance();
    for ($y = 1300; $y <= 1400; $y++) {
      for ($m = 1; $m <= 12; $m++) {
        for ($d = 1; $d <= $calendar
          ->daysInMonth($m - 1, 'jalali'); $d++) {
          $fadate = $y . '/' . str_pad($m, 2, "0", STR_PAD_LEFT) . '/' . str_pad($d, 2, "0", STR_PAD_LEFT);
          $_infoArray_fadate = split('/', $fadate);
          $_infoArray_fadate = array(
            'year' => $_infoArray_fadate[0],
            'month' => $_infoArray_fadate[1],
            'day' => $_infoArray_fadate[2],
          );
          $timestamp_birthdaf = $calendar
            ->infoArrayToTimestamp($_infoArray_fadate);
          $birthdaf_val = date('Y-m-d', $timestamp_birthdaf);
          $birthdaf_val_timestamp = $calendar
            ->strToTimestamp($birthdaf_val);
          $check_date = format_date($birthdaf_val_timestamp, 'custom', 'Y/m/d');
          if ($fadate != $check_date) {
            $result = false;
            $message .= " \n {$fadate} : {$check_date}";

            //print($fadate);

            //echo '<br />';

            //print($check_date);

            //echo '<br />';

            //echo '<hr />';
          }
        }
      }
    }
    $this
      ->assertTrue($result, $message);
  }

  /**
   * Detect if we're running on Drupal.org's automated testbot.
   *
   * This is used inside the edit test so that the testbot skips intentionally
   * failing tests. Otherwise, it would mark this module as broken.
   *
   * For more information on the testbot, see http://qa.drupal.org/.
   *
   * @return boolean
   *   TRUE if running on testbot.
   */
  public function runningOnTestbot() {
    $testbot_code_directory = "../checkout";
    return file_exists($testbot_code_directory);
  }

}

Classes

Namesort descending Description
BasicFunctionalityTest Tests basic functionality