2012-08-22 18:23:06 +02:00
|
|
|
<?php
|
2018-07-03 01:35:24 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\TextExtraction\Tests;
|
|
|
|
|
2018-07-03 05:55:02 +02:00
|
|
|
use SilverStripe\Assets\File;
|
|
|
|
use SilverStripe\Core\Config\Config;
|
2018-07-03 01:35:24 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\TextExtraction\Extractor\HTMLTextExtractor;
|
|
|
|
|
2015-11-18 05:07:31 +01:00
|
|
|
class HTMLTextExtractorTest extends SapphireTest
|
|
|
|
{
|
2018-07-03 05:55:02 +02:00
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
2021-10-27 07:16:05 +02:00
|
|
|
protected function setUp(): void
|
2018-07-03 05:55:02 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2018-07-03 05:55:02 +02:00
|
|
|
$file = new File();
|
|
|
|
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.html');
|
|
|
|
$file->write();
|
|
|
|
|
|
|
|
$content = $extractor->getContent($file);
|
2018-07-03 01:35:24 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|