ExcerptsTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. use Codeception\Util\Fixtures;
  3. use Grav\Common\Helpers\Excerpts;
  4. use Grav\Common\Grav;
  5. use Grav\Common\Uri;
  6. use Grav\Common\Config\Config;
  7. use Grav\Common\Page\Pages;
  8. use Grav\Common\Language\Language;
  9. /**
  10. * Class ExcerptsTest
  11. */
  12. class ExcerptsTest extends \Codeception\TestCase\Test
  13. {
  14. /** @var Parsedown $parsedown */
  15. protected $parsedown;
  16. /** @var Grav $grav */
  17. protected $grav;
  18. /** @var Page $page */
  19. protected $page;
  20. /** @var Pages $pages */
  21. protected $pages;
  22. /** @var Config $config */
  23. protected $config;
  24. /** @var Uri $uri */
  25. protected $uri;
  26. /** @var Language $language */
  27. protected $language;
  28. protected $old_home;
  29. protected function _before()
  30. {
  31. $grav = Fixtures::get('grav');
  32. $this->grav = $grav();
  33. $this->pages = $this->grav['pages'];
  34. $this->config = $this->grav['config'];
  35. $this->uri = $this->grav['uri'];
  36. $this->language = $this->grav['language'];
  37. $this->old_home = $this->config->get('system.home.alias');
  38. $this->config->set('system.home.alias', '/item1');
  39. $this->config->set('system.absolute_urls', false);
  40. $this->config->set('system.languages.supported', []);
  41. unset($this->grav['language']);
  42. $this->grav['language'] = new Language($this->grav);
  43. /** @var UniformResourceLocator $locator */
  44. $locator = $this->grav['locator'];
  45. $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false);
  46. $this->pages->init();
  47. $defaults = [
  48. 'extra' => false,
  49. 'auto_line_breaks' => false,
  50. 'auto_url_links' => false,
  51. 'escape_markup' => false,
  52. 'special_chars' => ['>' => 'gt', '<' => 'lt'],
  53. ];
  54. $this->page = $this->pages->dispatch('/item2/item2-2');
  55. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  56. }
  57. protected function _after()
  58. {
  59. $this->config->set('system.home.alias', $this->old_home);
  60. }
  61. public function testProcessImageHtml()
  62. {
  63. $this->assertRegexp('|<img alt="Sample Image" src="\/images\/.*-sample-image.jpe?g\" data-src="sample-image\.jpg\?cropZoom=300,300" \/>|',
  64. Excerpts::processImageHtml('<img src="sample-image.jpg?cropZoom=300,300" alt="Sample Image" />', $this->page));
  65. $this->assertRegexp('|<img alt="Sample Image" class="foo" src="\/images\/.*-sample-image.jpe?g\" data-src="sample-image\.jpg\?classes=foo" \/>|',
  66. Excerpts::processImageHtml('<img src="sample-image.jpg?classes=foo" alt="Sample Image" />', $this->page));
  67. }
  68. }