BreadcrumbsTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Block\Html;
  7. use Magento\Framework\Serialize\SerializerInterface;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. /**
  10. * @magentoAppArea frontend
  11. */
  12. class BreadcrumbsTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Theme\Block\Html\Breadcrumbs
  16. */
  17. private $block;
  18. /**
  19. * @var SerializerInterface
  20. */
  21. private $serializer;
  22. protected function setUp()
  23. {
  24. Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
  25. $this->block = Bootstrap::getObjectManager()
  26. ->get(\Magento\Framework\View\LayoutInterface::class)
  27. ->createBlock(\Magento\Theme\Block\Html\Breadcrumbs::class);
  28. $this->serializer = Bootstrap::getObjectManager()->get(SerializerInterface::class);
  29. }
  30. public function testAddCrumb()
  31. {
  32. $this->assertEmpty($this->block->toHtml());
  33. $info = ['label' => 'test label', 'title' => 'test title', 'link' => 'test link'];
  34. $this->block->addCrumb('test', $info);
  35. $html = $this->block->toHtml();
  36. $this->assertContains('test label', $html);
  37. $this->assertContains('test title', $html);
  38. $this->assertContains('test link', $html);
  39. }
  40. public function testGetCacheKeyInfo()
  41. {
  42. $crumbs = ['test' => ['label' => 'test label', 'title' => 'test title', 'link' => 'test link']];
  43. foreach ($crumbs as $crumbName => &$crumb) {
  44. $this->block->addCrumb($crumbName, $crumb);
  45. $crumb += ['first' => null, 'last' => null, 'readonly' => null];
  46. }
  47. $cacheKeyInfo = $this->block->getCacheKeyInfo();
  48. $crumbsFromCacheKey = $this->serializer->unserialize(base64_decode($cacheKeyInfo['crumbs']));
  49. $this->assertEquals($crumbs, $crumbsFromCacheKey);
  50. }
  51. }