silverstripe-textextraction/tests/FileTextExtractableTest.php

54 lines
1.5 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\Extension\FileTextExtractable;
2015-11-18 05:07:31 +01:00
class FileTextExtractableTest extends SapphireTest
{
protected $usesDatabase = true;
2015-11-18 05:07:31 +01:00
protected static $required_extensions = [
File::class => [
FileTextExtractable::class,
],
];
protected function setUp()
2015-11-18 05:07:31 +01:00
{
parent::setUp();
// Ensure that html is a valid extension
Config::modify()->merge(File::class, 'allowed_extensions', ['html']);
2015-11-18 05:07:31 +01:00
}
public function testExtractFileAsText()
{
// Create a copy of the file, as it may be clobbered by the test
// ($file->extractFileAsText() calls $file->write)
copy(
dirname(__FILE__) . '/fixtures/test1.html',
dirname(__FILE__) . '/fixtures/test1-copy.html'
);
2015-11-18 05:07:31 +01:00
// Use HTML, since the extractor is always available
$file = new File([
2015-11-18 05:07:31 +01:00
'Name' => 'test1-copy.html',
'Filename' => dirname(__FILE__) . '/fixtures/test1-copy.html'
]);
2015-11-18 05:07:31 +01:00
$file->write();
2015-11-18 05:07:31 +01:00
$content = $file->extractFileAsText();
$this->assertContains('Test Headline', $content);
$this->assertContains('Test Text', $content);
$this->assertEquals($content, $file->FileContentCache);
if (file_exists(dirname(__FILE__) . '/fixtures/test1-copy.html')) {
unlink(dirname(__FILE__) . '/fixtures/test1-copy.html');
2015-11-18 05:07:31 +01:00
}
}
}