getConfigFactoryStub example


  protected $pathMatcher;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a stub config factory with all config settings that will be     // checked during this test.     $config_factory_stub = $this->getConfigFactoryStub(
      [
        'system.site' => [
          'page.front' => '/dummy',
        ],
      ]
    );
    $route_match = $this->createMock('Drupal\Core\Routing\RouteMatchInterface');
    $this->pathMatcher = new PathMatcher($config_factory_stub$route_match);
  }

  /** * Tests that standard paths works with multiple patterns. * * @dataProvider getMatchPathData */
$this->storage = $this->createMock('Drupal\locale\StringStorageInterface');
    $this->cache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->languageManager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface');
    $this->requestStack = new RequestStack();
  }

  /** * Tests for \Drupal\locale\LocaleTranslation::destruct(). */
  public function testDestruct() {
    $translation = new LocaleTranslation($this->storage, $this->cache, $this->lock, $this->getConfigFactoryStub()$this->languageManager, $this->requestStack);
    // Prove that destruction works without errors when translations are empty.     $this->assertNull($translation->destruct());
  }

}

  protected LoggerInterface $logger;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->mockConfigFactory = $this->getConfigFactoryStub(['update.settings' => ['fetch_url' => 'http://www.example.com']]);
    $this->mockHttpClient = $this->createMock('\GuzzleHttp\ClientInterface');
    $settings = new Settings([]);
    $this->logger = new TestLogger();
    $this->updateFetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings$this->logger);
    $this->testProject = [
      'name' => 'update_test',
      'project_type' => '',
      'info' => [
        'version' => '',
        'project status url' => 'https://www.example.com',
      ],
      

  protected $requestStack;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->tokenGenerator = $this->prophesize(CsrfTokenGenerator::class);
    $config_factory = $this->getConfigFactoryStub(['system.theme' => ['default' => 'stark']]);
    $this->requestStack = new RequestStack();
    $this->negotiator = new AjaxBasePageNegotiator($this->tokenGenerator->reveal()$config_factory$this->requestStack);
  }

  /** * @covers ::applies * @dataProvider providerTestApplies */
  public function testApplies($request_data$expected) {
    $request = new Request();
    foreach ($request_data as $key => $data) {
      

  protected function setUp(): void {
    parent::setUp();

    $this->controllerBase = $this->getMockForAbstractClass('Drupal\Core\Controller\ControllerBase');
  }

  /** * Tests the config method. */
  public function testGetConfig() {
    $config_factory = $this->getConfigFactoryStub([
      'config_name' => [
        'key' => 'value',
      ],
      'config_name2' => [
        'key2' => 'value2',
      ],
    ]);

    $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
    $container->expects($this->once())
      ->method('get')
      

  public function testApplies($expected$route_name = NULL, $parameter_map = []) {
    // Make some test doubles.     $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
    $config_factory = $this->getConfigFactoryStub([]);

    $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface');
    $forum_manager->expects($this->any())
      ->method('checkNodeType')
      ->willReturn(TRUE);

    $translation_manager = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface');

    // Make an object to test.     $builder = new ForumNodeBreadcrumbBuilder($entity_type_manager$config_factory$forum_manager$translation_manager);

    
->getMock();
    $container = new ContainerBuilder();
    $container->set('plugin.manager.views.access', $this->accessPluginManager);

    $config = [
      'views.settings' => [
        'skip_cache' => TRUE,
        'display_extenders' => [],
      ],
    ];

    $container->set('config.factory', $this->getConfigFactoryStub($config));

    \Drupal::setContainer($container);
  }

  /** * Tests the collectRoutes method. * * @see \Drupal\views\Plugin\views\display\PathPluginBase::collectRoutes() */
  public function testCollectRoutes() {
    [$view] = $this->setupViewExecutableAccessPlugin();

    

  protected $languageManager;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $container = new ContainerBuilder();
    $config = ['system.date' => ['first_day' => 'Sunday']];
    $container->set('config.factory', $this->getConfigFactoryStub($config));

    $this->languageManager = $this->createMock('\Drupal\Core\Language\LanguageManagerInterface');
    $language = new Language(['langcode' => 'en']);
    $this->languageManager->expects($this->any())
      ->method('getDefaultLanguage')
      ->will($this->returnValue($language));
    $this->languageManager->expects($this->any())
      ->method('getCurrentLanguage')
      ->will($this->returnValue($language));
    $container->set('language_manager', $this->languageManager);

    
/** * @coversDefaultClass \Drupal\Core\EventSubscriber\FinalExceptionSubscriber * @group EventSubscriber */
class FinalExceptionSubscriberTest extends UnitTestCase {

  /** * @covers ::onException */
  public function testOnExceptionWithUnknownFormat() {
    $config_factory = $this->getConfigFactoryStub();

    $kernel = $this->prophesize(HttpKernelInterface::class);
    $request = Request::create('/test');
    // \Drupal\Core\StackMiddleware\NegotiationMiddleware normally takes care     // of this so we'll hard code it here.     $request->setRequestFormat('bananas');
    $e = new MethodNotAllowedHttpException(['POST', 'PUT'], 'test message');
    $event = new ExceptionEvent($kernel->reveal()$request, HttpKernelInterface::MAIN_REQUEST, $e);
    $subscriber = new TestDefaultExceptionSubscriber($config_factory);
    $subscriber->setStringTranslation($this->getStringTranslationStub());
    $subscriber->onException($event);
    

class AdminNegotiatorTest extends UnitTestCase {

  /** * @dataProvider getThemes */
  public function testDetermineActiveTheme($admin_theme$expected) {
    $user = $this->prophesize(AccountInterface::class);
    $config_factory = $this->getConfigFactoryStub(['system.theme' => ['admin' => $admin_theme]]);
    $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
    $admin_context = $this->prophesize(AdminContext::class);
    $negotiator = new AdminNegotiator($user->reveal()$config_factory$entity_type_manager->reveal()$admin_context->reveal());
    $route_match = $this->prophesize(RouteMatch::class);
    $this->assertSame($expected$negotiator->determineActiveTheme($route_match->reveal()));
  }

  /** * Provides a list of theme names to test. */
  public function getThemes() {
    


  /** * Tests the loadOverride method. * * @dataProvider providerTestLoadOverride * * @covers ::loadOverride * @covers ::getConfig */
  public function testLoadOverride($overrides$id$expected) {
    $config_factory = $this->getConfigFactoryStub(['core.menu.static_menu_link_overrides' => ['definitions' => $overrides]]);
    $static_override = new StaticMenuLinkOverrides($config_factory);

    $this->assertEquals($expected$static_override->loadOverride($id));
  }

  /** * Provides test data for testLoadOverride. */
  public function providerTestLoadOverride() {
    $data = [];
    // Valid ID.

  protected $accessManager;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => '/access-denied-page', 'page.404' => '/not-found-page']]);

    $this->kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
    $this->logger = $this->createMock('Psr\Log\LoggerInterface');
    $this->redirectDestination = $this->createMock('\Drupal\Core\Routing\RedirectDestinationInterface');
    $this->redirectDestination->expects($this->any())
      ->method('getAsArray')
      ->willReturn(['destination' => 'test']);
    $this->accessUnawareRouter = $this->createMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
    $this->accessUnawareRouter->expects($this->any())
      ->method('match')
      ->willReturn([
        
      ['/fr/foo', NULL, '/fr/foo'],
      ['/fr', NULL, '/fr'],
      ['/user/login', NULL, '/user/login'],
    ];

    $alias_manager->expects($this->any())
      ->method('getPathByAlias')
      ->willReturnMap($system_path_map);

    // Create a stub config factory with all config settings that will be checked     // during this test.     $config_factory_stub = $this->getConfigFactoryStub(
      [
        'system.site' => [
          'page.front' => '/user/login',
        ],
        'language.negotiation' => [
          'url' => [
            'prefixes' => ['fr' => 'fr'],
            'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
          ],
        ],
      ]
    );

  protected $requestStack;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Use the provided config for system.mail.interface settings.     $this->configFactory = $this->getConfigFactoryStub([
      'system.mail' => [
        'interface' => [],
      ],
      'system.site' => [
        'mail' => 'test@example.com',
      ],
    ]);

    $this->request = new Request();

    $this->requestStack = $this->prophesize(RequestStack::class);
    
/** * {@inheritdoc} * * @covers ::__construct */
  protected function setUp(): void {
    parent::setUp();

    $this->requestMatcher = $this->createMock('\Symfony\Component\Routing\Matcher\RequestMatcherInterface');

    $config_factory = $this->getConfigFactoryStub(['system.site' => ['front' => 'test_frontpage']]);

    $this->pathProcessor = $this->createMock('\Drupal\Core\PathProcessor\InboundPathProcessorInterface');
    $this->context = $this->createMock('\Drupal\Core\Routing\RequestContext');

    $this->accessManager = $this->createMock('\Drupal\Core\Access\AccessManagerInterface');
    $this->titleResolver = $this->createMock('\Drupal\Core\Controller\TitleResolverInterface');
    $this->currentUser = $this->createMock('Drupal\Core\Session\AccountInterface');
    $this->currentPath = $this->getMockBuilder('Drupal\Core\Path\CurrentPathStack')
      ->disableOriginalConstructor()
      ->getMock();

    
Home | Imprint | This part of the site doesn't use cookies.