diff --git a/core/modules/filter/tests/src/Unit/FilterFormatRepositoryTest.php b/core/modules/filter/tests/src/Unit/FilterFormatRepositoryTest.php index 5a501ba..ee85bcd 100644 --- a/core/modules/filter/tests/src/Unit/FilterFormatRepositoryTest.php +++ b/core/modules/filter/tests/src/Unit/FilterFormatRepositoryTest.php @@ -95,27 +95,30 @@ protected function tearDown() { * @covers ::loadFormats */ public function testGetAllFormatsFromStorage() { - $this->cacheBackend->get('filter_formats:en')->willReturn(NULL); - $filter_format_prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $filter_format = $filter_format_prophecy->reveal(); + $this->cacheBackend->get('filter_formats:en') + ->willReturn(NULL) + ->shouldBeCalledTimes(1); + $this->cacheBackend->set('filter_formats:en', [$filter_format], -1, ['entity_type_list'])->shouldBeCalled(); + $entity_storage_prophecy = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface'); $entity_storage_prophecy->loadByProperties(['status' => TRUE]) - ->willReturn([$filter_format]); + ->willReturn([$filter_format]) + ->shouldBeCalledTimes(1); $this->entityManager->getStorage('filter_format') - ->willReturn($entity_storage_prophecy->reveal()); + ->willReturn($entity_storage_prophecy->reveal()) + ->shouldBeCalledTimes(1); $this->entityManager->getDefinition('filter_format') ->willReturn(new EntityType([ 'id' => 'entity_type', 'class' => '\Drupal\filter\Entity\FilterFormat', - ])); + ])) + ->shouldBeCalled(); - $this->cacheBackend->set('filter_formats:en', $filter_format, Cache::PERMANENT, ['entity_type_list']); - $this->cacheBackend->get('filter_formats:en') - ->willReturn((object) ['data' => [$filter_format]]); $expected = [$filter_format]; $formats = $this->filterFormatRepository->getAllFormats(); @@ -135,12 +138,14 @@ public function testGetAllFormatsFromCache() { $filter_format = $prophecy->reveal(); $this->cacheBackend->get('filter_formats:en') - ->willReturn((object) ['data' => [$filter_format]]); + ->willReturn((object) ['data' => [$filter_format]]) + ->shouldBeCalledTimes(1); $this->entityManager->getStorage(Argument::any())->shouldNotBeCalled(); $expected = [$filter_format]; $formats = $this->filterFormatRepository->getAllFormats(); $this->assertSame($expected, $formats); + // Ensure a second call doesn't load from storage or the cache backend. $formats = $this->filterFormatRepository->getAllFormats(); $this->assertSame($expected, $formats); @@ -156,12 +161,16 @@ public function testGetFormatsForAccount() { $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->willReturn('filter_format_1'); - $prophecy->access('use', $account)->willReturn(TRUE); + $prophecy->access('use', $account) + ->willReturn(TRUE) + ->shouldBeCalled(); $filter_format1 = $prophecy->reveal(); $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->willReturn('filter_format_2'); - $prophecy->access('use', $account)->willReturn(FALSE); + $prophecy->access('use', $account) + ->willReturn(FALSE) + ->shouldBeCalled(); $filter_format2 = $prophecy->reveal(); $this->cacheBackend->get('filter_formats:en') @@ -185,12 +194,16 @@ public function testGetFormatsForAccount() { public function testGetFormatsByRole() { $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->willReturn('filter_format_1'); - $prophecy->getRoles()->willReturn(['anonymous' => 'anonymous', 'admin' => 'admin']); + $prophecy->getRoles() + ->willReturn(['anonymous' => 'anonymous', 'admin' => 'admin']) + ->shouldBeCalled(); $filter_format1 = $prophecy->reveal(); $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->shouldNotBeCalled(); - $prophecy->getRoles()->willReturn(['anonymous' => 'anonymous']); + $prophecy->getRoles() + ->willReturn(['anonymous' => 'anonymous']) + ->shouldBeCalled(); $filter_format2 = $prophecy->reveal(); $this->cacheBackend->get('filter_formats:en') @@ -214,12 +227,16 @@ public function testGetDefaultFormatWithAccount() { $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->willReturn('filter_format_1'); - $prophecy->access('use', $account)->willReturn(TRUE); + $prophecy->access('use', $account) + ->willReturn(TRUE) + ->shouldBeCalled(); $filter_format1 = $prophecy->reveal(); $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->willReturn('filter_format_2'); - $prophecy->access('use', $account)->willReturn(TRUE); + $prophecy->access('use', $account) + ->willReturn(TRUE) + ->shouldBeCalled(); $filter_format2 = $prophecy->reveal(); $this->cacheBackend->get('filter_formats:en') @@ -238,12 +255,16 @@ public function testGetDefaultFormatWithAccount() { public function testGetDefaultFormatWithoutAccount() { $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->willReturn('filter_format_1'); - $prophecy->access('use', $this->account)->willReturn(TRUE); + $prophecy->access('use', $this->account) + ->willReturn(TRUE) + ->shouldBeCalled(); $filter_format1 = $prophecy->reveal(); $prophecy = $this->prophesize('\Drupal\filter\FilterFormatInterface'); $prophecy->id()->willReturn('filter_format_2'); - $prophecy->access('use', $this->account)->willReturn(TRUE); + $prophecy->access('use', $this->account) + ->willReturn(TRUE) + ->shouldBeCalled(); $filter_format2 = $prophecy->reveal(); $this->cacheBackend->get('filter_formats:en') @@ -252,7 +273,9 @@ public function testGetDefaultFormatWithoutAccount() { 'filter_format_1' => $filter_format1, ]]); - $this->account->id()->willReturn(5); + $this->account->id() + ->willReturn(5) + ->shouldBeCalled(); $format = $this->filterFormatRepository->getDefaultFormat(); $this->assertSame($filter_format2, $format); @@ -263,8 +286,12 @@ public function testGetDefaultFormatWithoutAccount() { */ public function testGetFallbackFormatId() { $config_object = $this->prophesize('\Drupal\Core\Config\Config'); - $config_object->get('fallback_format')->willReturn('the_filter_format_id'); - $this->configFactory->get('filter.settings')->willReturn($config_object->reveal()); + $config_object->get('fallback_format') + ->willReturn('the_filter_format_id') + ->shouldBeCalled(); + $this->configFactory->get('filter.settings') + ->willReturn($config_object->reveal()) + ->shouldBeCalled(); $expected = 'the_filter_format_id'; $format_id = $this->filterFormatRepository->getFallbackFormatId();