MockBlockManager example

/** * Tests basic context definition and value getters and setters. */
  public function testContext() {
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $type = NodeType::create(['type' => 'page', 'name' => 'Page']);
    $type->save();

    $name = $this->randomMachineName();
    $manager = new MockBlockManager();
    $plugin = $manager->createInstance('user_name');
    // Create a node, add it as context, catch the exception.     $node = Node::create(['type' => 'page', 'title' => $name]);

    // Try to get context that is missing its definition.     try {
      $plugin->getContextDefinition('not_exists');
      $this->fail('The user context should not yet be set.');
    }
    catch (ContextException $e) {
      $this->assertEquals('The not_exists context is not a valid context.', $e->getMessage());
    }
parent::setUp();

    // Real modules implementing plugin types may expose a module-specific API     // for retrieving each type's plugin manager, or make them available in     // Drupal's dependency injection container, but for unit testing, we get     // the managers directly.     // - TestPluginManager is a bare bones manager with no support for     // derivatives, and uses DefaultFactory for plugin instantiation.     // - MockBlockManager is used for testing more advanced functionality such     // as derivatives and ReflectionFactory.     $this->testPluginManager = new TestPluginManager();
    $this->mockBlockManager = new MockBlockManager();
    $module_handler = new ModuleHandler($this->root, []new MemoryBackend());
    $this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler);

    // The expected plugin definitions within each manager. Several tests assert     // that these plugins and their definitions are found and returned by the     // necessary API functions.     // @see TestPluginManager::_construct().     // @see MockBlockManager::_construct().     $this->testPluginExpectedDefinitions = [
      'user_login' => [
        'label' => 'User login',
        
Home | Imprint | This part of the site doesn't use cookies.