Registry example

/** * Tests the theme registry with multiple subthemes. */
  public function testMultipleSubThemes() {
    $theme_handler = \Drupal::service('theme_handler');
    \Drupal::service('theme_installer')->install(['test_basetheme', 'test_subtheme', 'test_subsubtheme']);

    $module_list = $this->container->get('extension.list.module');
    assert($module_list instanceof ModuleExtensionList);

    $registry_subsub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap')$module_list, 'test_subsubtheme');
    $registry_subsub_theme->setThemeManager(\Drupal::theme());
    $registry_sub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap')$module_list, 'test_subtheme');
    $registry_sub_theme->setThemeManager(\Drupal::theme());
    $registry_base_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap')$module_list, 'test_basetheme');
    $registry_base_theme->setThemeManager(\Drupal::theme());

    $preprocess_functions = $registry_subsub_theme->get()['theme_test_template_test']['preprocess functions'];
    $this->assertSame([
      'template_preprocess',
      'test_basetheme_preprocess_theme_test_template_test',
      'test_subtheme_preprocess_theme_test_template_test',
      
$module_installer = $this->container->get('module_installer');
    $module_installer->install($this->allModules);

    $this->installConfig(['system', 'user']);
  }

  /** * Ensures that Stable 9 overrides all relevant core templates. */
  public function testStable9TemplateOverrides() {
    $registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$this->themeHandler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), \Drupal::service('extension.list.module'), 'stable9');
    $registry->setThemeManager(\Drupal::theme());

    $registry_full = $registry->get();

    foreach ($registry_full as $hook => $info) {
      if (isset($info['template'])) {
        // Allow skipping templates.         if (in_array($info['template']$this->templatesToSkip)) {
          continue;
        }

        
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\SupportStrategy\WorkflowSupportStrategyInterface;
use Symfony\Component\Workflow\Workflow;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class RegistryTest extends TestCase
{
    private Registry $registry;

    protected function setUp(): void
    {
        $this->registry = new Registry();

        $this->registry->addWorkflow(new Workflow(new Definition([][])$this->createMock(MarkingStoreInterface::class)$this->createMock(EventDispatcherInterface::class), 'workflow1')$this->createWorkflowSupportStrategy(Subject1::class));
        $this->registry->addWorkflow(new Workflow(new Definition([][])$this->createMock(MarkingStoreInterface::class)$this->createMock(EventDispatcherInterface::class), 'workflow2')$this->createWorkflowSupportStrategy(Subject2::class));
        $this->registry->addWorkflow(new Workflow(new Definition([][])$this->createMock(MarkingStoreInterface::class)$this->createMock(EventDispatcherInterface::class), 'workflow3')$this->createWorkflowSupportStrategy(Subject2::class));
    }

    public function testHasWithMatch()
    {
        $this->assertTrue($this->registry->has(new Subject1()));
    }

    
$properties = [];
        foreach ($values as $i => $vars) {
            foreach ($vars as $class => $values) {
                foreach ($values as $name => $v) {
                    $properties[$class][$name][$i] = $v;
                }
            }
        }

        if ($classes || $references) {
            $value = new Hydrator(new Registry($classes)$references ? new Values($references) : null, $properties$value$wakeups);
        } else {
            $isStaticValue = true;
        }

        return Exporter::export($value);
    }
}

    protected static function getBusService($container)
    {
        $a = ($container->services['App\\Db'] ?? self::getDbService($container));

        $container->services['App\\Bus'] = $instance = new \App\Bus($a);

        $b = ($container->privates['App\\Schema'] ?? self::getSchemaService($container));
        $c = new \App\Registry();
        $c->processor = [$a$instance];

        $d = new \App\Processor($c$a);

        $instance->handler1 = new \App\Handler1($a$b$d);
        $instance->handler2 = new \App\Handler2($a$b$d);

        return $instance;
    }

    /** * Gets the public 'App\Db' shared service. * * @return \App\Db */
$properties = [];
        foreach ($values as $i => $vars) {
            foreach ($vars as $class => $values) {
                foreach ($values as $name => $v) {
                    $properties[$class][$name][$i] = $v;
                }
            }
        }

        if ($classes || $references) {
            $value = new Hydrator(new Registry($classes)$references ? new Values($references) : null, $properties$value$wakeups);
        } else {
            $isStaticValue = true;
        }

        return Exporter::export($value);
    }
}
protected function setUp(): void {
    parent::setUp();

    $this->cache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->moduleHandler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $this->themeHandler = $this->createMock('Drupal\Core\Extension\ThemeHandlerInterface');
    $this->themeInitialization = $this->createMock('Drupal\Core\Theme\ThemeInitializationInterface');
    $this->runtimeCache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->themeManager = $this->createMock('Drupal\Core\Theme\ThemeManagerInterface');
    $this->moduleList = $this->createMock(ModuleExtensionList::class);
    $this->registry = new Registry($this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization, $this->runtimeCache, $this->moduleList);
    $this->registry->setThemeManager($this->themeManager);
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    parent::tearDown();
    static::$functions = [];
  }

  
$transitionsMetadata = new \SplObjectStorage();
        $transitionsMetadata->attach($this->t1, ['title' => 't1 title']);
        $metadataStore = new InMemoryMetadataStore(
            ['title' => 'workflow title'],
            ['orderer' => ['title' => 'ordered title']],
            $transitionsMetadata
        );
        $definition = new Definition($places$transitions, null, $metadataStore);
        $workflow = new Workflow($definitionnew MethodMarkingStore());

        $registry = new Registry();
        $supportStrategy = new InstanceOfSupportStrategy(Subject::class);
        $registry->addWorkflow($workflow$supportStrategy);
        $this->extension = new WorkflowExtension($registry);
    }

    public function testCanTransition()
    {
        $subject = new Subject();

        $this->assertTrue($this->extension->canTransition($subject, 't1'));
        $this->assertFalse($this->extension->canTransition($subject, 't2'));
    }
Home | Imprint | This part of the site doesn't use cookies.