returnValue example

use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/** * @group time-sensitive */
class InlineFragmentRendererTest extends TestCase
{
    public function testRender()
    {
        $strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo'))));

        $this->assertEquals('foo', $strategy->render('/', Request::create('/'))->getContent());
    }

    public function testRenderWithControllerReference()
    {
        $strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo'))));

        $this->assertEquals('foo', $strategy->render(new ControllerReference('main_controller', [][]), Request::create('/'))->getContent());
    }

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

    \Drupal::setContainer($container);
  }

  /** * @covers ::weekDaysOrdered * @dataProvider providerTestWeekDaysOrdered */

    public function testFragmentWithError()
    {
        $this->expectException(\Twig\Error\RuntimeError::class);
        $renderer = $this->getFragmentHandler($this->throwException(new \Exception('foo')));

        $this->renderTemplate($renderer);
    }

    public function testRenderFragment()
    {
        $renderer = $this->getFragmentHandler($this->returnValue(new Response('html')));

        $response = $this->renderTemplate($renderer);

        $this->assertEquals('html', $response);
    }

    public function testUnknownFragmentRenderer()
    {
        $context = $this->createMock(RequestStack::class);
        $renderer = new FragmentHandler($context);

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

    // Set up some languages to be used by the language-based path processor.     $language_de = $this->createMock(LanguageInterface::class);
    $language_de->expects($this->any())
      ->method('getId')
      ->will($this->returnValue('de'));
    $language_de->expects($this->any())
      ->method('getName')
      ->will($this->returnValue('German'));
    $language_en = $this->createMock(LanguageInterface::class);
    $language_en->expects($this->any())
      ->method('getId')
      ->will($this->returnValue('en'));
    $language_en->expects($this->any())
      ->method('getName')
      ->will($this->returnValue('English'));
    $this->languages = [
      

        if (!interface_exists(ValidatorInterface::class)) {
            throw new \Exception('In order to use the "ValidatorExtensionTrait", the symfony/validator component must be installed.');
        }

        if (!$this instanceof TypeTestCase) {
            throw new \Exception(sprintf('The trait "ValidatorExtensionTrait" can only be added to a class that extends "%s".', TypeTestCase::class));
        }

        $this->validator = $this->createMock(ValidatorInterface::class);
        $metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->onlyMethods(['addPropertyConstraint'])->getMock();
        $this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
        $this->validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList()));

        return new ValidatorExtension($this->validator, false);
    }
}
->willThrowException($exception);
    $linkItem->expects($this->any())
      ->method('__get')
      ->with('options')
      ->willReturn([]);
    $fieldDefinition = $this->createMock(FieldDefinitionInterface::class);
    $fieldList = new FieldItemList($fieldDefinition, '', $linkItem);

    $fieldTypePluginManager = $this->createMock(FieldTypePluginManagerInterface::class);
    $fieldTypePluginManager->expects($this->once())
      ->method('createFieldItem')
      ->will($this->returnValue($linkItem));
    $urlGenerator = $this->createMock(UrlGenerator::class);
    $urlGenerator->expects($this->once())
      ->method('generateFromRoute')
      ->with('<none>', [][], FALSE)
      ->willReturn('http://example.com');
    $container = new ContainerBuilder();
    $container->set('plugin.manager.field.field_type', $fieldTypePluginManager);
    $container->set('url_generator', $urlGenerator);
    \Drupal::setContainer($container);
    $fieldList->setValue([$linkItem]);

    
public function testRenderWhenRendererDoesNotExist()
    {
        $this->expectException(\InvalidArgumentException::class);
        $handler = new FragmentHandler($this->requestStack);
        $handler->render('/', 'foo');
    }

    public function testRenderWithUnknownRenderer()
    {
        $this->expectException(\InvalidArgumentException::class);
        $handler = $this->getHandler($this->returnValue(new Response('foo')));

        $handler->render('/', 'bar');
    }

    public function testDeliverWithUnsuccessfulResponse()
    {
        $handler = $this->getHandler($this->returnValue(new Response('foo', 404)));
        try {
            $handler->render('/', 'foo');
            $this->fail('->render() throws a \RuntimeException exception if response is not successful');
        } catch (\Exception $e) {
            
$this->themeHandler->expects($this->any())
      ->method('hasUi')
      ->with('olivero')
      ->willReturn(TRUE);
    $this->container->set('theme_handler', $this->themeHandler);

    $fooEntityDefinition = $this->createMock(EntityTypeInterface::class);
    $fooEntityDefinition
      ->expects($this->once())
      ->method('hasLinkTemplate')
      ->with('version-history')
      ->will($this->returnValue(TRUE));
    $entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $entityTypeManager->expects($this->any())
      ->method('getDefinitions')
      ->willReturn([
        'foo' => $fooEntityDefinition,
      ]);
    $this->container->set('entity_type.manager', $entityTypeManager);
  }

  /** * Tests local task existence. * * @dataProvider getSystemAdminRoutes */
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->sourceStorage = $this->createMock('Drupal\Core\Config\StorageInterface');
    $this->targetStorage = $this->createMock('Drupal\Core\Config\StorageInterface');

    $this->sourceStorage->expects($this->atLeastOnce())
      ->method('getCollectionName')
      ->will($this->returnValue(StorageInterface::DEFAULT_COLLECTION));
    $this->targetStorage->expects($this->atLeastOnce())
      ->method('getCollectionName')
      ->will($this->returnValue(StorageInterface::DEFAULT_COLLECTION));

    $this->storageComparer = new StorageComparer($this->sourceStorage, $this->targetStorage);
  }

  protected function getConfigData() {
    $uuid = new Php();
    // Mock data using minimal data to use ConfigDependencyManger.     $this->configData = [
      
/** * Tests the query() method. * * @see \Drupal\views\Plugin\views\pager\SqlBase::query() */
  public function testQuery() {
    $request = new Request([
      'items_per_page' => 'All',
    ]);
    $this->view->expects($this->any())
      ->method('getRequest')
      ->will($this->returnValue($request));

    $options = [];
    $this->pager->init($this->view, $this->display, $options);
    $this->pager->query();
    $this->assertSame(10, $this->pager->options['items_per_page']);

    $options = [
      'expose' => [
        'items_per_page' => TRUE,
        'items_per_page_options_all' => TRUE,
      ],
    ];
Home | Imprint | This part of the site doesn't use cookies.