setValidationConstraintManager example

'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
    ]);
    $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandlerInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $class_resolver = $this->getMockBuilder('Drupal\Core\DependencyInjection\ClassResolverInterface')
      ->disableOriginalConstructor()
      ->getMock();

    $this->typedDataManager = new TypedDataManager($namespaces$cache_backend$module_handler$class_resolver);
    $this->typedDataManager->setValidationConstraintManager(
      new ConstraintManager($namespaces$cache_backend$module_handler)
    );
    // Typed data definitions access the manager in the container.     $container = new ContainerBuilder();
    $container->set('typed_data_manager', $this->typedDataManager);
    \Drupal::setContainer($container);

    $translator = $this->createMock('Drupal\Core\Validation\TranslatorInterface');
    $translator->expects($this->any())
      ->method('trans')
      ->willReturnCallback(function D$id) {
        

    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);

    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });

    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(new ConstraintManager($namespaces$cache_backend$module_handler->reveal()));

    $string_translation = new TranslationManager(new LanguageDefault([]));

    $container = new ContainerBuilder();
    $container->set('typed_data_manager', $type_data_manager);
    $container->set('string_translation', $string_translation);
    \Drupal::setContainer($container);
  }

  /** * Tests that context requirements is satisfied as expected. * * @param bool $expected * The expected outcome. * @param \Drupal\Core\Plugin\Context\ContextDefinition $requirement * The requirement to check against. * @param \Drupal\Core\Plugin\Context\ContextDefinition $definition * The context definition to check. * @param mixed $value * (optional) The value to set on the context, defaults to NULL. * * @covers ::isSatisfiedBy * @covers ::dataTypeMatches * @covers ::getSampleValues * @covers ::getConstraintObjects * * @dataProvider providerTestIsSatisfiedBy */

    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);

    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });

    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(new ConstraintManager($namespaces$cache_backend$module_handler->reveal()));

    $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
    $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);

    $string_translation = new TranslationManager(new LanguageDefault([]));

    $container = new ContainerBuilder();
    $container->set('typed_data_manager', $type_data_manager);
    $container->set('entity_type.manager', $this->entityTypeManager->reveal());
    $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
    $container->set('string_translation', $string_translation);
    
'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
    ]);
    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });
    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(
      new ConstraintManager($namespaces$cache_backend$module_handler->reveal())
    );

    $container = TestKernel::setContainerWithKernel();
    $container->set('typed_data_manager', $type_data_manager);
    \Drupal::setContainer($container);
  }

  /** * @covers ::checkRequirements * * @dataProvider providerTestCheckRequirements */
Home | Imprint | This part of the site doesn't use cookies.