replace example

$request->headers->set('FORWARDED', 'proto=https, proto=http');
        $this->assertTrue($request->isSecure());
    }

    /** * @dataProvider iisRequestUriProvider */
    public function testIISRequestUri($headers$server$expectedRequestUri)
    {
        $request = new Request();
        $request->headers->replace($headers);
        $request->server->replace($server);

        $this->assertEquals($expectedRequestUri$request->getRequestUri(), '->getRequestUri() is correct');

        $subRequestUri = '/bar/foo';
        $subRequest = Request::create($subRequestUri, 'get', [][][]$request->server->all());
        $this->assertEquals($subRequestUri$subRequest->getRequestUri(), '->getRequestUri() is correct in sub request');
    }

    public static function iisRequestUriProvider()
    {
        
class ProductListingResolvePreviewEventTest extends TestCase
{
    public function testReplace(): void
    {
        $event = new ProductListingResolvePreviewEvent(
            $this->createMock(SalesChannelContext::class),
            new Criteria(),
            ['p1' => 'p1'],
            true
        );

        $event->replace('p1', 'p2');
        static::assertSame(['p1' => 'p2']$event->getMapping());
    }

    public function testReplaceException(): void
    {
        $event = new ProductListingResolvePreviewEvent(
            $this->createMock(SalesChannelContext::class),
            new Criteria(),
            ['p1' => 'p1'],
            true
        );

        

  public function getConfigurationOrNot() {
    $image = [
      '#theme' => 'image',
      '#uri' => $this->get('url'),
      '#alt' => $this->get('alt'),
    ];

    return [
      'title' => Html::escape($this->get('label')),
      'body' => $this->token->replace(\Drupal::service('renderer')->renderPlain($image)),
    ];
  }

}
$metadata_tests['[view:title]'] = $base_bubbleable_metadata;
    $metadata_tests['[view:url]'] = $base_bubbleable_metadata;
    $metadata_tests['[view:total-rows]'] = $base_bubbleable_metadata;
    $metadata_tests['[view:base-table]'] = $base_bubbleable_metadata;
    $metadata_tests['[view:base-field]'] = $base_bubbleable_metadata;
    $metadata_tests['[view:items-per-page]'] = $base_bubbleable_metadata;
    $metadata_tests['[view:current-page]'] = $base_bubbleable_metadata;
    $metadata_tests['[view:page-count]'] = $base_bubbleable_metadata;

    foreach ($expected as $token => $expected_output) {
      $bubbleable_metadata = new BubbleableMetadata();
      $output = $token_handler->replace($token['view' => $view][]$bubbleable_metadata);
      $this->assertSame($expected_output$outputnew FormattableMarkup('Token %token replaced correctly.', ['%token' => $token]));
      $this->assertEquals($metadata_tests[$token]$bubbleable_metadata);
    }
  }

  /** * Tests core token replacements generated from a view. */
  public function testTokenReplacementWithMiniPager() {
    $token_handler = \Drupal::token();
    $view = Views::getView('test_tokens');
    
public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition) {
    return new static($configuration$plugin_id$plugin_definition$container->get('token'));
  }

  /** * {@inheritdoc} */
  public function getBody(): array {
    return [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this->token->replace($this->get('body')),
      '#attributes' => [
        'class' => ['tour-tip-body'],
      ],
    ];
  }

}
public function setQuery($spec$value = null)
    {
        if (!\is_array($spec) && $value === null) {
            unset($_GET[$spec]);
            $this->query->remove($spec);

            return $this;
        }

        if (\is_array($spec) && empty($spec)) {
            $_GET = [];
            $this->query->replace([]);

            return $this;
        }

        if (($value === null) && !\is_array($spec)) {
            throw new RuntimeException('Invalid value passed to setQuery(); must be either array of values or key/value pair');
        }

        if (($value === null) && \is_array($spec)) {
            foreach ($spec as $key => $specValue) {
                $this->setQuery($key$specValue);
            }
    $this->drupalGet($this->assertLinkToCreatedMedia());

    // Assert the image element is present inside the media element and that its     // src attribute uses the large image style, the label is visually hidden,     // and there is no link to the image file.     $label = $assert_session->elementExists('xpath', '//div[contains(@class, "visually-hidden") and text()="Image"]');
    // The field is the parent div of the label.     $field = $label->getParent();
    $image_element = $field->find('css', 'img');
    /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
    $file_url_generator = \Drupal::service('file_url_generator');
    $expected_image_src = $file_url_generator->generateString(\Drupal::token()->replace('public://styles/large/public/[date:custom:Y]-[date:custom:m]/example_1.jpeg'));
    $this->assertStringContainsString($expected_image_src$image_element->getAttribute('src'));
    $assert_session->elementNotExists('css', 'a', $field);

    // Ensure the image has the correct alt attribute.     $this->assertSame('Image Alt Text 1', $image_element->getAttribute('alt'));

    // Load the media and check that all fields are properly populated.     $media = Media::load(1);
    $this->assertSame('example_1.jpeg', $media->getName());
    $this->assertSame('200', $media->get('field_string_width')->value);
    $this->assertSame('89', $media->get('field_string_height')->value);

    
if (!$response instanceof StorefrontResponse) {
            throw StorefrontException::unSupportStorefrontResponse();
        }

        $host = $request->attributes->get(RequestTransformer::STOREFRONT_URL);

        $seoUrlReplacer = $this->container->get(SeoUrlPlaceholderHandlerInterface::class);
        $content = $response->getContent();
        if ($content !== false) {
            $response->setContent(
                $seoUrlReplacer->replace($content$host$salesChannelContext)
            );
        }

        $response->setData($parameters);
        $response->setContext($salesChannelContext);

        $response->headers->set('Content-Type', 'text/html');

        return $response;
    }

    

  protected function getUploadLocation(array $settings) {
    $destination = trim($settings['file_directory'], '/');

    // Replace tokens. As the tokens might contain HTML we convert it to plain     // text.     $destination = PlainTextOutput::renderFromHtml($this->token->replace($destination[]));
    return $settings['uri_scheme'] . '://' . $destination;
  }

  /** * Retrieves the upload validators for a field definition. * * This is copied from \Drupal\file\Plugin\Field\FieldType\FileItem as there * is no entity instance available here that a FileItem would exist for. * * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition for which to get validators. * * @return array * An array suitable for passing to file_save_upload() or the file field * element's '#upload_validators' property. */

function wp_cache_replace( $key$data$group = '', $expire = 0 ) {
    global $wp_object_cache;

    return $wp_object_cache->replace( $key$data$group(int) $expire );
}

/** * Saves the data to the cache. * * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data. * * @since 2.0.0 * * @see WP_Object_Cache::set() * @global WP_Object_Cache $wp_object_cache Object cache global instance. * * @param int|string $key The cache key to use for retrieval later. * @param mixed $data The contents to store in the cache. * @param string $group Optional. Where to group the cache contents. Enables the same key * to be used across groups. Default empty. * @param int $expire Optional. When to expire the cache contents, in seconds. * Default 0 (no expiration). * @return bool True on success, false on failure. */

        $tmp = $this->_memcache->get($id);
        if (isset($tmp[0]$tmp[1]$tmp[2])) {
            $data     = $tmp[0];
            $mtime    = $tmp[1];
            $lifetime = $tmp[2];
            $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
            if ($newLifetime <=0) {
                return false;
            }
            // #ZF-5702 : we try replace() first becase set() seems to be slower             if (!($result = $this->_memcache->replace($id, array($datatime()$newLifetime)$newLifetime))) {
                $result = $this->_memcache->set($id, array($datatime()$newLifetime)$newLifetime);
                if ($result === false) {
                    $rsCode = $this->_memcache->getResultCode();
                    $rsMsg  = $this->_memcache->getResultMessage();
                    $this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
                }
            }
            return $result;
        }
        return false;
    }

    
$this->assertSame([]$this->request->query->all());
        $this->assertSame('', $this->request->server->get('QUERY_STRING'));
        $this->assertInstanceOf(UsernamePasswordToken::class$this->tokenStorage->getToken());
    }

    public function testSwitchUserKeepsOtherQueryStringParameters()
    {
        $token = new UsernamePasswordToken(new InMemoryUser('username', '', ['ROLE_FOO']), 'key', ['ROLE_FOO']);

        $this->tokenStorage->setToken($token);
        $this->request->query->replace([
            '_switch_user' => 'kuba',
            'page' => 3,
            'section' => 2,
        ]);

        $targetsUser = $this->callback(fn ($user) => 'kuba' === $user->getUserIdentifier());
        $this->accessDecisionManager->expects($this->once())
            ->method('decide')->with($token['ROLE_ALLOWED_TO_SWITCH']$targetsUser)
            ->willReturn(true);

        $this->userChecker->expects($this->once())
            
$content = CacheValueCompressor::compress(['cart' => $cart, 'rule_ids' => []]);

        $cartSerializationCleaner = $this->createMock(CartSerializationCleaner::class);

        $redis = new RedisStub();
        $redis->set(RedisCartPersister::PREFIX . $oldToken, \serialize(['compressed' => true, 'content' => $content]));

        $context = $this->createMock(SalesChannelContext::class);

        $persister = new RedisCartPersister($redis$dispatcher$cartSerializationCleaner, true, 90);

        $persister->replace($oldToken$newToken$context);

        static::assertFalse($redis->exists(RedisCartPersister::PREFIX . $oldToken));
        static::assertTrue($redis->exists(RedisCartPersister::PREFIX . $newToken));
    }

    public function testReplaceCopyRuleIds(): void
    {
        $oldToken = Uuid::randomHex();
        $newToken = Uuid::randomHex();
        $cart = new Cart($oldToken);
        $cart->add(new LineItem('test', 'test'));

        
$this->bag->set('hello', 'fabien');
        $array = $this->array;
        $array['hello'] = 'fabien';
        $this->assertEquals($array$this->bag->all());
    }

    public function testReplace()
    {
        $array = [];
        $array['name'] = 'jack';
        $array['foo.bar'] = 'beep';
        $this->bag->replace($array);
        $this->assertEquals($array$this->bag->all());
        $this->assertNull($this->bag->get('hello'));
        $this->assertNull($this->bag->get('always'));
        $this->assertNull($this->bag->get('user.login'));
    }

    public function testRemove()
    {
        $this->assertEquals('world', $this->bag->get('hello'));
        $this->bag->remove('hello');
        $this->assertNull($this->bag->get('hello'));

        
                $propertyPathBuilder->remove($i);
            } else {
                /* @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */
                $propertyPath = $scope->getPropertyPath();

                if (null === $propertyPath) {
                    // Property path of a mapped form is null                     // Should not happen, bail out                     break;
                }

                $propertyPathBuilder->replace($i, 1, $propertyPath);
                $i += $propertyPath->getLength();
            }
        }

        $finalPath = $propertyPathBuilder->getPropertyPath();

        return null !== $finalPath ? new RelativePath($origin$finalPath) : null;
    }

    private function acceptsErrors(FormInterface $form): bool
    {
        
Home | Imprint | This part of the site doesn't use cookies.