AccessResultNeutral example


class AccessResultNeutralTest extends UnitTestCase {

  /** * Tests the construction of an AccessResultForbidden object. * * @covers ::__construct * @covers ::getReason */
  public function testConstruction() {
    $a = new AccessResultNeutral();
    $this->assertEquals('', $a->getReason());

    $reason = $this->getRandomGenerator()->string();
    $b = new AccessResultNeutral($reason);
    $this->assertEquals($reason$b->getReason());
  }

  /** * Tests setReason() * * @covers ::setReason */

  public static function neutral($reason = NULL) {
    assert(is_string($reason) || is_null($reason));
    return new AccessResultNeutral($reason);
  }

  /** * Creates an AccessResultInterface object with isAllowed() === TRUE. * * @return \Drupal\Core\Access\AccessResultAllowed * isAllowed() will be TRUE. */
  public static function allowed() {
    return new AccessResultAllowed();
  }

  

  public function testConstruction() {
    $verify = function DAccessResult $access) {
      $this->assertFalse($access->isAllowed());
      $this->assertFalse($access->isForbidden());
      $this->assertTrue($access->isNeutral());
      $this->assertDefaultCacheability($access);
    };

    // Verify the object when using the constructor.     $a = new AccessResultNeutral();
    $verify($a);

    // Verify the object when using the ::create() convenience method.     $b = AccessResult::neutral();
    $verify($b);

    $this->assertEquals($a$b);
  }

  /** * @covers ::allowed * @covers ::isAllowed * @covers ::isForbidden * @covers ::isNeutral */

    ];
    return [
      'block plugin with forms, forms[settings_tray] set to class' => [
        TRUE,
        $annotation_forms_settings_tray_class,
        new AccessResultAllowed(),
      ],
      'block plugin with forms, forms[settings_tray] not set' => [
        TRUE,
        $annotation_forms_settings_tray_not_set,
        new AccessResultNeutral(),
      ],
      'block plugin with forms, forms[settings_tray] set to FALSE' => [
        TRUE,
        $annotation_forms_settings_tray_false,
        new AccessResultNeutral(),
      ],
      // In practice, all block plugins extend BlockBase, which means they all       // implement PluginWithFormsInterface, but this may change in the future.       // This ensures Settings Tray will continue to work correctly.       'block plugin without forms, forms[settings_tray] set to class' => [
        FALSE,
        
Home | Imprint | This part of the site doesn't use cookies.