function LocaleLookupTest::testResolveCacheMissWithPersist

Same name and namespace in other branches
  1. 8.9.x core/modules/locale/tests/src/Unit/LocaleLookupTest.php \Drupal\Tests\locale\Unit\LocaleLookupTest::testResolveCacheMissWithPersist()
  2. 10 core/modules/locale/tests/src/Unit/LocaleLookupTest.php \Drupal\Tests\locale\Unit\LocaleLookupTest::testResolveCacheMissWithPersist()
  3. 11.x core/modules/locale/tests/src/Unit/LocaleLookupTest.php \Drupal\Tests\locale\Unit\LocaleLookupTest::testResolveCacheMissWithPersist()

Tests locale lookups with persistent tracking.

@covers ::resolveCacheMiss

File

core/modules/locale/tests/src/Unit/LocaleLookupTest.php, line 218

Class

LocaleLookupTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21locale%21src%21LocaleLookup.php/class/LocaleLookup/9" title="A cache collector to allow for dynamic building of the locale cache." class="local">\Drupal\locale\LocaleLookup</a> @group locale

Namespace

Drupal\Tests\locale\Unit

Code

public function testResolveCacheMissWithPersist() {
    $args = [
        'language' => 'en',
        'source' => 'test',
        'context' => 'irrelevant',
    ];
    $result = (object) [
        'translation' => 'test',
    ];
    $this->storage
        ->expects($this->once())
        ->method('findTranslation')
        ->with($this->equalTo($args))
        ->willReturn($result);
    $this->configFactory = $this->getConfigFactoryStub([
        'locale.settings' => [
            'cache_strings' => TRUE,
        ],
    ]);
    $locale_lookup = $this->getMockBuilder('Drupal\\locale\\LocaleLookup')
        ->setConstructorArgs([
        'en',
        'irrelevant',
        $this->storage,
        $this->cache,
        $this->lock,
        $this->configFactory,
        $this->languageManager,
        $this->requestStack,
    ])
        ->onlyMethods([
        'persist',
    ])
        ->getMock();
    $locale_lookup->expects($this->once())
        ->method('persist');
    $this->assertSame('test', $locale_lookup->get('test'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.