Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Datetime / DateTimePlusTest.php
index b755be8325ae7c77fb5457c9fc4318339dfa69c3..b89d351c755c9c3067eb64904fdd91dc16fb9e9d 100644 (file)
@@ -87,7 +87,13 @@ class DateTimePlusTest extends TestCase {
    * @dataProvider providerTestInvalidDateDiff
    */
   public function testInvalidDateDiff($input1, $input2, $absolute) {
-    $this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(\BadMethodCallException::class);
+      $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
+    }
+    else {
+      $this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
+    }
     $interval = $input1->diff($input2, $absolute);
   }
 
@@ -104,7 +110,12 @@ class DateTimePlusTest extends TestCase {
    * @dataProvider providerTestInvalidDateArrays
    */
   public function testInvalidDateArrays($input, $timezone, $class) {
-    $this->setExpectedException($class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException($class);
+    }
+    else {
+      $this->setExpectedException($class);
+    }
     $this->assertInstanceOf(
       '\Drupal\Component\DateTimePlus',
       DateTimePlus::createFromArray($input, $timezone)
@@ -242,7 +253,12 @@ class DateTimePlusTest extends TestCase {
    * @dataProvider providerTestInvalidDates
    */
   public function testInvalidDates($input, $timezone, $format, $message, $class) {
-    $this->setExpectedException($class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException($class);
+    }
+    else {
+      $this->setExpectedException($class);
+    }
     DateTimePlus::createFromFormat($format, $input, $timezone);
   }
 
@@ -800,10 +816,27 @@ class DateTimePlusTest extends TestCase {
 
     // Parse the same date with ['validate_format' => TRUE] and make sure we
     // get the expected exception.
-    $this->setExpectedException(\UnexpectedValueException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(\UnexpectedValueException::class);
+    }
+    else {
+      $this->setExpectedException(\UnexpectedValueException::class);
+    }
     $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]);
   }
 
+  /**
+   * Tests setting the default time for date-only objects.
+   */
+  public function testDefaultDateTime() {
+    $utc = new \DateTimeZone('UTC');
+
+    $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '2017-05-23 22:58:00', $utc);
+    $this->assertEquals('22:58:00', $date->format('H:i:s'));
+    $date->setDefaultDateTime();
+    $this->assertEquals('12:00:00', $date->format('H:i:s'));
+  }
+
   /**
    * Tests that object methods are chainable.
    *
@@ -847,7 +880,13 @@ class DateTimePlusTest extends TestCase {
    * @covers ::__call
    */
   public function testChainableNonCallable() {
-    $this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(\BadMethodCallException::class);
+      $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
+    }
+    else {
+      $this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
+    }
     $date = new DateTimePlus('now', 'Australia/Sydney');
     $date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent();
   }