silverstripe-textextraction/tests/HTMLTextExtractorTest.php

37 lines
1.1 KiB
PHP
Raw Normal View History

2012-08-22 18:23:06 +02:00
<?php
namespace SilverStripe\TextExtraction\Tests;
use SilverStripe\Assets\File;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\TextExtraction\Extractor\HTMLTextExtractor;
2015-11-18 05:07:31 +01:00
class HTMLTextExtractorTest extends SapphireTest
{
protected $usesDatabase = true;
2021-10-27 07:16:05 +02:00
protected function setUp(): void
{
parent::setUp();
Config::modify()->merge(File::class, 'allowed_extensions', ['html']);
}
2015-11-18 05:07:31 +01:00
public function testExtraction()
{
$extractor = new HTMLTextExtractor();
2012-08-22 18:23:06 +02:00
$file = new File();
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.html');
$file->write();
$content = $extractor->getContent($file);
2021-10-27 07:16:05 +02:00
$this->assertStringContainsString('Test Headline', $content);
$this->assertStringNotContainsString('Test Comment', $content, 'Strips HTML comments');
$this->assertStringNotContainsString('Test Style', $content, 'Strips non-content style tags');
$this->assertStringNotContainsString('Test Script', $content, 'Strips non-content script tags');
2015-11-18 05:07:31 +01:00
}
}