function LayoutTempstoreRepositoryTest::testGetLoadedTempstore

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

@covers ::get @covers ::has

File

core/modules/layout_builder/tests/src/Unit/LayoutTempstoreRepositoryTest.php, line 44

Class

LayoutTempstoreRepositoryTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21layout_builder%21src%21LayoutTempstoreRepository.php/class/LayoutTempstoreRepository/9" title="Provides a mechanism for loading layouts from tempstore." class="local">\Drupal\layout_builder\LayoutTempstoreRepository</a> @group layout_builder

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testGetLoadedTempstore() {
    $section_storage = $this->prophesize(SectionStorageInterface::class);
    $section_storage->getStorageType()
        ->willReturn('my_storage_type');
    $section_storage->getStorageId()
        ->willReturn('my_storage_id');
    $tempstore_section_storage = $this->prophesize(SectionStorageInterface::class);
    $tempstore = $this->prophesize(SharedTempStore::class);
    $tempstore->get('my_storage_id')
        ->willReturn([
        'section_storage' => $tempstore_section_storage->reveal(),
    ]);
    $tempstore_factory = $this->prophesize(SharedTempStoreFactory::class);
    $tempstore_factory->get('layout_builder.section_storage.my_storage_type')
        ->willReturn($tempstore->reveal());
    $repository = new LayoutTempstoreRepository($tempstore_factory->reveal());
    $this->assertTrue($repository->has($section_storage->reveal()));
    $result = $repository->get($section_storage->reveal());
    $this->assertSame($tempstore_section_storage->reveal(), $result);
    $this->assertNotSame($section_storage->reveal(), $result);
}

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