expectWarningMessage example

// Test imported configuration with explicit language code.     $data = $storage->read('config_test.dynamic.dotted.french');
    $this->assertEquals('fr', $data['langcode']);
    $this->assertEquals('fr', $this->config('config_test.dynamic.dotted.french')->get('langcode'));
  }

  /** * Tests installing configuration where the filename and ID do not match. */
  public function testIdMisMatch() {
    $this->expectWarning();
    $this->expectWarningMessage('The configuration name "config_test.dynamic.no_id_match" does not match the ID "does_not_match"');
    $this->installModules(['config_test_id_mismatch']);
  }

  /** * Installs a module. * * @param array $modules * The module names. */
  protected function installModules(array $modules) {
    $this->container->get('module_installer')->install($modules);
    

  public function testOnRouteBuildingInvalidVariables(Route $route) {
    $route_collection = new RouteCollection();
    $route_collection->add('test', $route);

    $event = new RouteBuildEvent($route_collection);
    $subscriber = new SpecialAttributesRouteSubscriber();
    $this->expectWarning();
    $this->expectWarningMessage('uses reserved variable names');
    $subscriber->onAlterRoutes($event);
  }

}
$display['display_options']['filters']['roles_target_id'] = [
      'id' => 'roles_target_id',
      'table' => 'user__roles',
      'field' => 'roles_target_id',
      'value' => ['test_user_role' => 'test_user_role'],
      'plugin_id' => 'user_roles',
    ];
    // Ensure no warning is triggered before the role is deleted.     $view->calculateDependencies();
    $role->delete();
    $this->expectWarning();
    $this->expectWarningMessage('The test_user_role role does not exist. You should review and fix the configuration of the test_user_name view.');
    $view->calculateDependencies();
  }

}
/** * @covers ::createDirectory */
  public function testCreateDirectoryFailWarning() {
    $directory = new vfsStreamDirectory('permissionDenied', 0200);
    $storage = new FileStorage([
      'directory' => $directory->url(),
      'bin' => 'test',
    ]);
    $code = "<?php\n echo 'here';";
    $this->expectWarning();
    $this->expectWarningMessage('mkdir(): Permission Denied');
    $storage->save('subdirectory/foo.php', $code);
  }

}

  public function testSilencedDeprecation($callback) {
    $this->expectDeprecation('Drupal\Tests\Core\Security\UntrustedObject::callback is not trusted');
    $this->doTrustedCallback($callback[], '%s is not trusted', TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION);
  }

  /** * @dataProvider errorTypeProvider */
  public function testWarning($callback) {
    $this->expectWarning();
    $this->expectWarningMessage('Drupal\Tests\Core\Security\UntrustedObject::callback is not trusted');
    $this->doTrustedCallback($callback[], '%s is not trusted', TrustedCallbackInterface::TRIGGER_WARNING);
  }

  /** * Data provider for tests of ::doTrustedCallback $error_type argument. */
  public function errorTypeProvider() {
    $tests['untrusted_object'] = [[new UntrustedObject(), 'callback']];
    $tests['untrusted_object_static_string'] = ['Drupal\Tests\Core\Security\UntrustedObject::callback'];
    $tests['untrusted_object_static_array'] = [[UntrustedObject::class, 'callback']];
    return $tests;
  }
Home | Imprint | This part of the site doesn't use cookies.