Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Access / AccessResultTest.php
index 60a17a0fb68b7564a15a85f107a9173c5b275681..f8245892292d85b5bdccab09a09194d2e2a8923c 100644 (file)
@@ -269,8 +269,12 @@ class AccessResultTest extends UnitTestCase {
    */
   public function testOrIf() {
     $neutral = AccessResult::neutral('neutral message');
+    $neutral_other = AccessResult::neutral('other neutral message');
+    $neutral_reasonless = AccessResult::neutral();
     $allowed = AccessResult::allowed();
     $forbidden = AccessResult::forbidden('forbidden message');
+    $forbidden_other = AccessResult::forbidden('other forbidden message');
+    $forbidden_reasonless = AccessResult::forbidden();
     $unused_access_result_due_to_lazy_evaluation = $this->getMock('\Drupal\Core\Access\AccessResultInterface');
     $unused_access_result_due_to_lazy_evaluation->expects($this->never())
       ->method($this->anything());
@@ -304,6 +308,18 @@ class AccessResultTest extends UnitTestCase {
     $this->assertTrue($access->isNeutral());
     $this->assertEquals('neutral message', $access->getReason());
     $this->assertDefaultCacheability($access);
+    // Reason inheritance edge case: first reason is kept.
+    $access = $neutral->orIf($neutral_other);
+    $this->assertEquals('neutral message', $access->getReason());
+    $access = $neutral_other->orIf($neutral);
+    $this->assertEquals('other neutral message', $access->getReason());
+    // Reason inheritance edge case: one of the operands is reasonless.
+    $access = $neutral->orIf($neutral_reasonless);
+    $this->assertEquals('neutral message', $access->getReason());
+    $access = $neutral_reasonless->orIf($neutral);
+    $this->assertEquals('neutral message', $access->getReason());
+    $access = $neutral_reasonless->orIf($neutral_reasonless);
+    $this->assertNull($access->getReason());
 
     // NEUTRAL || ALLOWED === ALLOWED.
     $access = $neutral->orIf($allowed);
@@ -329,7 +345,7 @@ class AccessResultTest extends UnitTestCase {
     $this->assertDefaultCacheability($access);
 
     // FORBIDDEN || NEUTRAL === FORBIDDEN.
-    $access = $forbidden->orIf($allowed);
+    $access = $forbidden->orIf($neutral);
     $this->assertFalse($access->isAllowed());
     $this->assertTrue($access->isForbidden());
     $this->assertFalse($access->isNeutral());
@@ -337,12 +353,24 @@ class AccessResultTest extends UnitTestCase {
     $this->assertDefaultCacheability($access);
 
     // FORBIDDEN || FORBIDDEN === FORBIDDEN.
-    $access = $forbidden->orIf($allowed);
+    $access = $forbidden->orIf($forbidden);
     $this->assertFalse($access->isAllowed());
     $this->assertTrue($access->isForbidden());
     $this->assertFalse($access->isNeutral());
     $this->assertEquals('forbidden message', $access->getReason());
     $this->assertDefaultCacheability($access);
+    // Reason inheritance edge case: first reason is kept.
+    $access = $forbidden->orIf($forbidden_other);
+    $this->assertEquals('forbidden message', $access->getReason());
+    $access = $forbidden_other->orIf($forbidden);
+    $this->assertEquals('other forbidden message', $access->getReason());
+    // Reason inheritance edge case: one of the operands is reasonless.
+    $access = $forbidden->orIf($forbidden_reasonless);
+    $this->assertEquals('forbidden message', $access->getReason());
+    $access = $forbidden_reasonless->orIf($forbidden);
+    $this->assertEquals('forbidden message', $access->getReason());
+    $access = $forbidden_reasonless->orIf($forbidden_reasonless);
+    $this->assertNull($access->getReason());
 
     // FORBIDDEN || * === FORBIDDEN.
     $access = $forbidden->orIf($unused_access_result_due_to_lazy_evaluation);
@@ -957,6 +985,7 @@ class UncacheableTestAccessResult implements AccessResultInterface {
   public function __construct($value) {
     $this->value = $value;
   }
+
   /**
    * {@inheritdoc}
    */