willReturnMap example

$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);

    $route_match = $this->createMock('Drupal\Core\Routing\RouteMatchInterface');
    $route_match->expects($this->once())
      ->method('getRouteName')
      ->willReturn($route_name);
    $route_match->expects($this->any())
      ->method('getParameter')
      ->willReturnMap($parameter_map);

    $this->assertEquals($expected$builder->applies($route_match));
  }

  /** * Provides test data for testApplies(). * * Note that this test is incomplete, because we can't mock NodeInterface. * * @return array * Array of datasets for testApplies(). Structured as such: * - ForumNodeBreadcrumbBuilder::applies() expected result. * - ForumNodeBreadcrumbBuilder::applies() $attributes input array. */
'route_name' => 'test_route2',
        'options' => ['key' => 'value'],
      ],
    ];

    $this->pluginDiscovery->expects($this->once())
      ->method('getDefinitions')
      ->willReturn($definitions);

    $this->accessManager->expects($this->any())
      ->method('checkNamedRoute')
      ->willReturnMap([
        ['test_route', ['key' => 'value']$this->account, FALSE, TRUE],
        ['test_route2', ['key' => 'value']$this->account, FALSE, FALSE],
      ]);

    $result = $this->contextualLinkManager->getContextualLinksArrayByGroup('group1', ['key' => 'value']);

    // Ensure that access checking was respected.     $this->assertTrue(isset($result['test_plugin1']));
    $this->assertFalse(isset($result['test_plugin2']));
  }

  


        if (null === $kernel) {
            $returnValues = [
                ['foo', $this->getBundle($this->translationDir)],
                ['test', $this->getBundle('test')],
            ];
            $kernel = $this->createMock(KernelInterface::class);
            $kernel
                ->expects($this->any())
                ->method('getBundle')
                ->willReturnMap($returnValues);
        }

        $kernel
            ->expects($this->any())
            ->method('getBundles')
            ->willReturn([new ExtensionPresentBundle()]);

        $container = new Container();
        $kernel
            ->expects($this->any())
            ->method('getContainer')
            
->method('hasPermission')
      ->willReturn(FALSE);
    $this->viewer
      ->expects($this->any())
      ->method('id')
      ->willReturn(1);

    $this->owner = $this->createMock('\Drupal\user\UserInterface');
    $this->owner
      ->expects($this->any())
      ->method('hasPermission')
      ->willReturnMap([
        ['administer users', FALSE],
        ['change own username', TRUE],
      ]);

    $this->owner
      ->expects($this->any())
      ->method('id')
      ->willReturn(2);

    $this->admin = $this->createMock('\Drupal\user\UserInterface');
    $this->admin
      
$requestStack = $this->createMock(RequestStack::class);
        $firewallMap = $this->createMock(FirewallMap::class);
        $firewall = new FirewallConfig('main', 'main');
        $userAuthenticator = $this->createMock(UserAuthenticatorInterface::class);
        $user = $this->createMock(UserInterface::class);
        $userChecker = $this->createMock(UserCheckerInterface::class);

        $container = $this->createMock(ContainerInterface::class);
        $container
            ->expects($this->atLeastOnce())
            ->method('get')
            ->willReturnMap([
                ['request_stack', $requestStack],
                ['security.firewall.map', $firewallMap],
                ['security.authenticator.managers_locator', $this->createContainer('main', $userAuthenticator)],
                ['security.user_checker', $userChecker],
            ])
        ;

        $requestStack->expects($this->once())->method('getCurrentRequest')->willReturn($request);
        $firewallMap->expects($this->once())->method('getFirewallConfig')->willReturn($firewall);
        $userAuthenticator->expects($this->once())->method('authenticateUser')->with($user$authenticator$request);
        $userChecker->expects($this->once())->method('checkPreAuth')->with($user);

        

  protected function setupFactory($mock_plugin) {
    $map = [];
    foreach ($this->getLocalTaskFixtures() as $info) {
      $map[] = [$info['id'][]$mock_plugin];
    }
    $this->factory->expects($this->any())
      ->method('createInstance')
      ->willReturnMap($map);
  }

  /** * Returns an expected result for getLocalTasksForRoute. * * @param \PHPUnit\Framework\MockObject\MockObject $mock_plugin * The mock plugin. * * @return array * The expected result, keyed by local task level. */
  
'status' => 1,
      'info' => [
        'name' => 'test_c',
      ],
    ];
    $theme_handler = $this->createMock('Drupal\Core\Extension\ThemeHandlerInterface');
    $theme_handler->expects($this->any())
      ->method('listInfo')
      ->willReturn($themes);
    $theme_handler->expects($this->any())
      ->method('hasUi')
      ->willReturnMap([
        ['test_a', FALSE],
        ['test_b', TRUE],
        ['test_c', TRUE],
      ]);

    $container = new ContainerBuilder();
    $container->set('config.factory', $config_factory);
    $container->set('theme_handler', $theme_handler);
    $container->setParameter('app.root', $this->root);
    \Drupal::setContainer($container);
  }

  
$system_path_map = [
      // Set up one proper alias that can be resolved to a system path.       ['/foo', NULL, '/user/1'],
      // Passing in anything else should return the same string.       ['/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'],
            
return Markup::create($link);
        }
      );
  }

  /** * Sets up a display with empty arguments and fields. */
  protected function setupDisplayWithEmptyArgumentsAndFields() {
    $this->display->expects($this->any())
      ->method('getHandlers')
      ->willReturnMap([
        ['argument', []],
        ['field', []],
      ]);
  }

  /** * Tests rendering as a link without a path. * * @covers ::renderAsLink */
  public function testRenderAsLinkWithoutPath() {
    
yield ['application/json', '{"title": "An error occurred", "detail": {"field_name": ["Some details"]}}', $errorWithoutMessage];
    }

    /** * @dataProvider provideParseError */
    public function testParseError(string $mimeType, string $json, string $expectedMessage)
    {
        $response = $this->createMock(ResponseInterface::class);
        $response
            ->method('getInfo')
            ->willReturnMap([
                ['http_code', 400],
                ['url', 'http://example.com'],
                ['response_headers', [
                    'HTTP/1.1 400 Bad Request',
                    'Content-Type: '.$mimeType,
                ]],
            ]);
        $response->method('getContent')->willReturn($json);

        $e = new TestException($response);
        $this->assertSame(400, $e->getCode());
        
'route_name' => '<none>',
        'return' => $none_route,
      ],
    ];
    foreach ($return_map_values as $values) {
      $route_name_return_map[] = [$values['route_name']$values['return']];
      $routes_names_return_map[] = [[$values['route_name']]$values['return']];
    }
    $this->provider = $provider;
    $this->provider->expects($this->any())
      ->method('getRouteByName')
      ->willReturnMap($route_name_return_map);
    $provider->expects($this->any())
      ->method('getRoutesByNames')
      ->willReturnMap($routes_names_return_map);

    // Create an alias manager stub.     $alias_manager = $this->getMockBuilder('Drupal\path_alias\AliasManager')
      ->disableOriginalConstructor()
      ->getMock();

    $alias_manager->expects($this->any())
      ->method('getAliasByPath')
      

  public function testCalculateDependencies() {
    // Mock the interfaces necessary to create a dependency on a bundle entity.     $target_entity_type = $this->createMock('\Drupal\Core\Entity\EntityTypeInterface');
    $target_entity_type->expects($this->any())
      ->method('getBundleConfigDependency')
      ->willReturn(['type' => 'config', 'name' => 'test.test_entity_type.id']);

    $this->entityTypeManager->expects($this->any())
      ->method('getDefinition')
      ->willReturnMap([
        [$this->entityTypeId, TRUE, $this->entityType],
        ['test_entity_type', TRUE, $target_entity_type],
      ]);

    $this->fieldTypePluginManager->expects($this->any())
      ->method('getDefinition')
      ->with('test_field')
      ->willReturn(['provider' => 'test_module', 'config_dependencies' => ['module' => ['test_module2']], 'class' => '\Drupal\Tests\field\Unit\DependencyFieldItem']);

    $this->fieldStorage->expects($this->once())
      ->method('getConfigDependencyName')
      
->method('applies')
      ->willReturn(TRUE);

    $negotiators['test_negotiator_2'] = $negotiator;

    foreach ($negotiators as $id => $negotiator) {
      $this->container->set($id$negotiator);
    }

    $this->themeAccessCheck->expects($this->exactly(2))
      ->method('checkAccess')
      ->willReturnMap([
        ['example_test', FALSE],
        ['example_test2', TRUE],
      ]);

    $route_match = new RouteMatch('test_route', new Route('/test-route')[][]);
    $theme = $this->createThemeNegotiator(array_keys($negotiators))->determineActiveTheme($route_match);

    $this->assertEquals('example_test2', $theme);
  }

  /** * Tests determining with two negotiators of which one does not apply. * * @see \Drupal\Core\Theme\ThemeNegotiatorInterface */
$plugin->expects($this->any())
        ->method('getWeight')
        ->willReturn($plugin_definition['weight']);
      $this->argumentResolver->expects($this->any())
        ->method('getArguments')
        ->with($this->request, [$plugin, 'getTitle'])
        ->willReturn([]);
      $map[] = [$plugin_id[]$plugin];
    }
    $this->factory->expects($this->any())
      ->method('createInstance')
      ->willReturnMap($map);

    $this->assertEquals($expected_actions$this->localActionManager->getActionsForRoute($route_appears));
  }

  public static function getActionsForRouteProvider() {
    $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class);
    $cache_contexts_manager->assertValidTokens(Argument::any())
      ->willReturn(TRUE);

    $container = new Container();
    $container->set('cache_contexts_manager', $cache_contexts_manager->reveal());
    
$importMapRenderer = $this->createMock(ImportMapRenderer::class);
        $expected = '<script type="importmap">{ "imports": {}}</script>';
        $importMapRenderer->expects($this->once())
            ->method('render')
            ->with('application')
            ->willReturn($expected);
        $runtime = new ImportMapRuntime($importMapRenderer);

        $mockRuntimeLoader = $this->createMock(RuntimeLoaderInterface::class);
        $mockRuntimeLoader
            ->method('load')
            ->willReturnMap([
                [ImportMapRuntime::class$runtime],
            ])
        ;
        $twig->addRuntimeLoader($mockRuntimeLoader);

        $this->assertSame($expected$twig->render('template'));
    }
}
Home | Imprint | This part of the site doesn't use cookies.