/** * Tests the getAllBundleInfo() method. * * @covers ::getAllBundleInfo */ public function testGetAllBundleInfo() { $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]); $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL); $apple = $this->prophesize(EntityTypeInterface::class); $apple->getLabel()->willReturn('Apple'); $apple->getBundleOf()->willReturn(NULL); $banana = $this->prophesize(EntityTypeInterface::class); $banana->getLabel()->willReturn('Banana'); $banana->getBundleOf()->willReturn(NULL); $this->setUpEntityManager(array('apple' => $apple, 'banana' => $banana)); $this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE); $this->cacheBackend->get('entity_type')->willReturn(FALSE); $this->cacheBackend->set('entity_type', Argument::any(), Cache::PERMANENT, ['entity_types'])->shouldBeCalled(); $this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])->will(function () { $this->get('entity_bundle_info:en')->willReturn((object) ['data' => 'cached data'])->shouldBeCalled(); })->shouldBeCalled(); $this->cacheTagsInvalidator->invalidateTags(['entity_types'])->shouldBeCalled(); $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled(); $this->cacheTagsInvalidator->invalidateTags(['entity_field_info'])->shouldBeCalled(); $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled(); $expected = array('apple' => array('apple' => array('label' => 'Apple')), 'banana' => array('banana' => array('label' => 'Banana'))); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame($expected, $bundle_info); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame($expected, $bundle_info); $this->entityManager->clearCachedDefinitions(); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame('cached data', $bundle_info); }
/** * Tests the getAllBundleInfo() method. * * @covers ::getAllBundleInfo */ public function testGetAllBundleInfo() { $apple = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $apple->expects($this->once())->method('getLabel')->will($this->returnValue('Apple')); $banana = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $banana->expects($this->once())->method('getLabel')->will($this->returnValue('Banana')); $this->setUpEntityManager(array('apple' => $apple, 'banana' => $banana)); $this->cacheBackend->expects($this->at(0))->method('get')->with("entity_bundle_info:en", FALSE)->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(1))->method('get')->with("entity_type", FALSE)->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(2))->method('set')->with("entity_type"); $this->cacheBackend->expects($this->at(3))->method('set')->with("entity_bundle_info:en"); $this->cacheTagsInvalidator->expects($this->at(0))->method('invalidateTags')->with(array('entity_types')); $this->cacheTagsInvalidator->expects($this->at(1))->method('invalidateTags')->with(array('entity_bundles')); $this->cacheTagsInvalidator->expects($this->at(2))->method('invalidateTags')->with(array('entity_field_info')); $this->cacheBackend->expects($this->at(4))->method('get')->with("entity_bundle_info:en", FALSE)->will($this->returnValue((object) array('data' => 'cached data'))); $expected = array('apple' => array('apple' => array('label' => 'Apple')), 'banana' => array('banana' => array('label' => 'Banana'))); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame($expected, $bundle_info); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame($expected, $bundle_info); $this->entityManager->clearCachedDefinitions(); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame('cached data', $bundle_info); }