2012-08-22 18:23:06 +02:00
|
|
|
<?php
|
2015-11-18 05:07:31 +01:00
|
|
|
class FileTextExtractableTest extends SapphireTest
|
|
|
|
{
|
|
|
|
protected $requiredExtensions = array(
|
|
|
|
'File' => array('FileTextExtractable')
|
|
|
|
);
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Ensure that html is a valid extension
|
|
|
|
Config::inst()
|
|
|
|
->nest()
|
|
|
|
->update('File', 'allowed_extensions', array('html'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
Config::unnest();
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractFileAsText()
|
|
|
|
{
|
|
|
|
// Create a copy of the file, as it may be clobbered by the test
|
|
|
|
// ($file->extractFileAsText() calls $file->write)
|
|
|
|
copy(BASE_PATH.'/textextraction/tests/fixtures/test1.html', BASE_PATH.'/textextraction/tests/fixtures/test1-copy.html');
|
2018-11-29 03:55:52 +01:00
|
|
|
|
2015-11-18 05:07:31 +01:00
|
|
|
// Use HTML, since the extractor is always available
|
2018-11-29 03:55:52 +01:00
|
|
|
/** @var File&FileTextExtractable $file */
|
2015-11-18 05:07:31 +01:00
|
|
|
$file = new File(array(
|
|
|
|
'Name' => 'test1-copy.html',
|
|
|
|
'Filename' => 'textextraction/tests/fixtures/test1-copy.html'
|
|
|
|
));
|
|
|
|
$file->write();
|
2018-11-29 03:55:52 +01:00
|
|
|
|
|
|
|
$content = (string) $file->extractFileAsText();
|
2015-11-18 05:07:31 +01:00
|
|
|
$this->assertContains('Test Headline', $content);
|
|
|
|
$this->assertContains('Test Text', $content);
|
|
|
|
$this->assertEquals($content, $file->FileContentCache);
|
|
|
|
|
|
|
|
if (file_exists(BASE_PATH.'/textextraction/tests/fixtures/test1-copy.html')) {
|
|
|
|
unlink(BASE_PATH.'/textextraction/tests/fixtures/test1-copy.html');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|