getModule example

protected function setUp(): void {
    parent::setUp();
    // Check that the validation class is available.     if (!class_exists("\\JsonSchema\\Validator")) {
      $this->fail('The JSON Schema validator is missing. You can install it with `composer require justinrainbow/json-schema`.');
    }

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $module = $this->prophesize(Extension::class);
    $module_path = dirname(__DIR__, 4);
    $module->getPath()->willReturn($module_path);
    $module_handler->getModule('jsonapi')->willReturn($module->reveal());
    $subscriber = new ResourceResponseValidator(
      $this->prophesize(LoggerInterface::class)->reveal(),
      $module_handler->reveal(),
      ''
    );
    $subscriber->setValidator();
    $this->subscriber = $subscriber;
  }

  /** * @covers ::doValidateResponse */
/** * {@inheritdoc} */
  public function getGroupProviders($group) {
    $providers = [];
    $breakpoints = $this->getBreakpointsByGroup($group);
    foreach ($breakpoints as $breakpoint) {
      $provider = $breakpoint->getProvider();
      $extension = FALSE;
      if ($this->moduleHandler->moduleExists($provider)) {
        $extension = $this->moduleHandler->getModule($provider);
      }
      elseif ($this->themeHandler->themeExists($provider)) {
        $extension = $this->themeHandler->getTheme($provider);
      }
      if ($extension) {
        $providers[$extension->getName()] = $extension->getType();
      }
    }
    return $providers;
  }

  
// Do not use Json::decode here since it coerces the response into an     // associative array, which creates validation errors.     $response_data = json_decode($response->getContent());
    if (empty($response_data)) {
      return TRUE;
    }

    $schema_ref = sprintf(
      'file://%s/schema.json',
      implode('/', [
        $this->appRoot,
        $this->moduleHandler->getModule('jsonapi')->getPath(),
      ])
    );
    $generic_jsonapi_schema = (object) ['$ref' => $schema_ref];

    return $this->validateSchema($generic_jsonapi_schema$response_data);
  }

  /** * Validates a string against a JSON Schema. It logs any possible errors. * * @param object $schema * The JSON Schema object. * @param string $response_data * The JSON string to validate. * * @return bool * TRUE if the string is a valid instance of the schema. FALSE otherwise. */
->importContentFromFile('block_content', 'disclaimer_block')
      ->importContentFromFile('block_content', 'footer_promo_block')
      ->importContentFromFile('block_content', 'banner_block');
  }

  /** * Set module_path variable. * * @return $this */
  protected function getModulePath() {
    $this->module_path = $this->moduleHandler->getModule('demo_umami_content')->getPath();
    return $this;
  }

  /** * Read multilingual content. * * @param string $filename * Filename to import. * * @return array * An array of two items: * 1. All multilingual content that was read from the files. * 2. List of language codes that need to be imported. */

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->moduleHandler->loadInclude('update', 'inc', 'update.manager');
    $projects = [];
    foreach (['projects', 'disabled_projects'] as $type) {
      if (!$form_state->isValueEmpty($type)) {
        $projects = array_merge($projectsarray_keys(array_filter($form_state->getValue($type))));
      }
    }
    $batch_builder = (new BatchBuilder())
      ->setFile($this->moduleHandler->getModule('update')->getPath() . '/update.manager.inc')
      ->setTitle($this->t('Downloading updates'))
      ->setInitMessage($this->t('Preparing to download selected updates'))
      ->setFinishCallback('update_manager_download_batch_finished');
    foreach ($projects as $project) {
      $batch_builder->addOperation('update_manager_batch_project_get', [
        $project,
        $form_state->getValue(['project_downloads', $project]),
      ]);
    }
    batch_set($batch_builder->toArray());
  }

}
$expected = [
      'locale_test.no_translation',
      'locale_test.translation',
      'locale_test.translation_multiple',
      'locale_test_translate.settings',
      'block.block.test_default_config',
    ];
    $actual = $storage->getComponentNames(
      'module',
      [
        \Drupal::moduleHandler()->getModule('locale_test'),
        \Drupal::moduleHandler()->getModule('locale_test_translate'),
      ],
    );
    $this->assertSame($expected$actual);
  }

}

    protected $modules_container = [];

    /** * @param string $name * @param mixed|null $value */
    public function __call($name$value = null)
    {
        return $this->getModule($name);
    }

    /** * Set class property * * @param \sSystem $system * * @return void */
    public function setSystem($system)
    {
        

  public function showModuleInfo(string $module, string $function) {
    $module_handler = \Drupal::moduleHandler();
    $module_message = $module . ': ';
    if ($module_handler->moduleExists($module)) {
      $module_message .= \Drupal::moduleHandler()->getModule($module)->getPath();
    }
    else {
      $module_message .= 'not installed';
    }
    $function_message = $function . ': ' . var_export(function_exists($function), TRUE);

    return [
      '#theme' => 'item_list',
      '#items' => [$module_message$function_message],
    ];
  }

}
$this->assertEquals($this->getModuleHandler()->getModuleList()[
      'module_handler_test' => new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'),
    ]);
  }

  /** * Confirm we get back a module from the module list. * * @covers ::getModule */
  public function testGetModuleWithExistingModule() {
    $this->assertEquals($this->getModuleHandler()->getModule('module_handler_test')new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'));
  }

  /** * @covers ::getModule */
  public function testGetModuleWithNonExistingModule() {
    $this->expectException(UnknownExtensionException::class);
    $this->getModuleHandler()->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist');
  }

  /** * Ensure setting the module list replaces the module list and resets internal structures. * * @covers ::setModuleList */

  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);

    if (!$definition instanceof LayoutDefinition) {
      throw new InvalidPluginDefinitionException($plugin_idsprintf('The "%s" layout definition must extend %s', $plugin_id, LayoutDefinition::class));
    }

    // Add the module or theme path to the 'path'.     $provider = $definition->getProvider();
    if ($this->moduleHandler->moduleExists($provider)) {
      $base_path = $this->moduleHandler->getModule($provider)->getPath();
    }
    elseif ($this->themeHandler->themeExists($provider)) {
      $base_path = $this->themeHandler->getTheme($provider)->getPath();
    }
    else {
      $base_path = '';
    }

    $path = $definition->getPath();
    $path = !empty($path) ? $base_path . '/' . $path : $base_path;
    $definition->setPath($path);

    

  private function makePathRelativeToLibraryRoot(string $path): string {
    $library_provider_root = $this->moduleHandler
      ->getModule('sdc')
      ->getPath();
    $num_dots = count(
      array_filter(explode(DIRECTORY_SEPARATOR, $library_provider_root))
    );
    $dots = str_repeat('../', $num_dots);
    $path_from_root = str_starts_with($path$this->appRoot)
      ? substr($pathstrlen($this->appRoot) + 1)
      : $path;
    return $dots . $path_from_root;
  }

}
$tour[$entity_id] = $entity->getTips();
      $total_tips += count($tour[$entity_id]);
      $cache_tags = Cache::mergeTags($cache_tags$entity->getCacheTags());
    }

    $items = [];
    foreach ($tour as $tour_id => $tips) {
      $tourEntity = $entities[$tour_id];

      foreach ($tips as $index => $tip) {
        $classes = [
          'tip-module-' . Html::getClass($tourEntity->getModule()),
          'tip-type-' . Html::getClass($tip->getPluginId()),
          'tip-' . Html::getClass($tip->id()),
        ];

        $selector = $tip->getSelector();
        $location = $tip->getLocation();

        $body_render_array = $tip->getBody();
        $body = (string) \Drupal::service('renderer')->renderPlain($body_render_array);
        $output = [
          'body' => $body,
          
$this->assertSession()->addressEquals('user/1');
    $this->assertSession()->statusCodeEquals(200);

    // Assert that in the settings.php the database connection array has the     // correct values set.     $contents = file_get_contents($this->container->getParameter('app.root') . '/' . $this->siteDirectory . '/settings.php');
    $this->assertStringContainsString("'namespace' => 'Drupal\\\\driver_test\\\\Driver\\\\Database\\\\{$this->testDriverName}',", $contents);
    $this->assertStringContainsString("'driver' => '{$this->testDriverName}',", $contents);
    $this->assertStringContainsString("'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/{$this->testDriverName}/',", $contents);

    // Assert that the module "driver_test" has been installed.     $this->assertEquals(\Drupal::service('module_handler')->getModule('driver_test')new Extension($this->root, 'module', 'core/modules/system/tests/modules/driver_test/driver_test.info.yml'));

    // Change the default database connection to use the database driver from     // the module "driver_test".     $connection_info = Database::getConnectionInfo();
    $driver_test_connection = $connection_info['default'];
    $driver_test_connection['driver'] = $this->testDriverName;
    $driver_test_connection['namespace'] = 'Drupal\\driver_test\\Driver\\Database\\' . $this->testDriverName;
    $driver_test_connection['autoload'] = "core/modules/system/tests/modules/driver_test/src/Driver/Database/{$this->testDriverName}/";
    Database::renameConnection('default', 'original_database_connection');
    Database::addConnectionInfo('default', 'default', $driver_test_connection);

    
$container->set('string_translation', $this->getStringTranslationStub());
    \Drupal::setContainer($container);

    $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);

    $this->moduleHandler->moduleExists('module_a')->willReturn(TRUE);
    $this->moduleHandler->moduleExists('theme_a')->willReturn(FALSE);
    $this->moduleHandler->moduleExists('core')->willReturn(FALSE);
    $this->moduleHandler->moduleExists('invalid_provider')->willReturn(FALSE);

    $module_a = new Extension('vfs://root', 'module', 'modules/module_a/module_a.layouts.yml');
    $this->moduleHandler->getModule('module_a')->willReturn($module_a);
    $this->moduleHandler->getModuleDirectories()->willReturn(['module_a' => vfsStream::url('root/modules/module_a')]);
    $this->moduleHandler->alter('layout', Argument::type('array'))->shouldBeCalled();

    $this->themeHandler = $this->prophesize(ThemeHandlerInterface::class);

    $this->themeHandler->themeExists('theme_a')->willReturn(TRUE);
    $this->themeHandler->themeExists('core')->willReturn(FALSE);
    $this->themeHandler->themeExists('invalid_provider')->willReturn(FALSE);

    $theme_a = new Extension('vfs://root', 'theme', 'themes/theme_a/theme_a.layouts.yml');
    $this->themeHandler->getTheme('theme_a')->willReturn($theme_a);
    
$this->assertEquals([[self::$message, self::$domain]]$visitor->getMessages());
    }

    /** @dataProvider getDefaultDomainAssignmentTestData */
    public function testNewModuleWithoutDefaultDomainTag(Node $node)
    {
        $env = new Environment($this->createMock(LoaderInterface::class)['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
        $visitor = new TranslationDefaultDomainNodeVisitor();

        // visit trans_default_domain tag         $newModule = TwigNodeProvider::getModule('test');
        $visitor->enterNode($newModule$env);
        $visitor->leaveNode($newModule$env);

        // visit tested node         $enteredNode = $visitor->enterNode($node$env);
        $leavedNode = $visitor->leaveNode($node$env);
        $this->assertSame($node$enteredNode);
        $this->assertSame($node$leavedNode);

        // extracting tested node messages         $visitor = new TranslationNodeVisitor();
        
Home | Imprint | This part of the site doesn't use cookies.