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;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-11-18 05:07:31 +01:00
|
|
|
$this->assertContains('Test Headline', $content);
|
|
|
|
$this->assertNotContains('Test Comment', $content, 'Strips HTML comments');
|
|
|
|
$this->assertNotContains('Test Style', $content, 'Strips non-content style tags');
|
|
|
|
$this->assertNotContains('Test Script', $content, 'Strips non-content script tags');
|
|
|
|
}
|
|
|
|
}
|