mirror of
https://github.com/silverstripe/silverstripe-textextraction
synced 2024-10-22 09:06:00 +00:00
Added rudimentary test coverage
This commit is contained in:
parent
ec0921c6d1
commit
98f847c946
23
tests/FileTextExtractableTest.php
Normal file
23
tests/FileTextExtractableTest.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
class FileTextExtractableTest extends SapphireTest {
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
'File' => array('FileTextExtractable')
|
||||
);
|
||||
|
||||
function testExtractFileAsText() {
|
||||
// Use HTML, since the extractor is always available
|
||||
$file = new File(array(
|
||||
'Name' => 'test1.html',
|
||||
'Filename' => 'textextraction/tests/fixtures/test1.html'
|
||||
));
|
||||
$file->write();
|
||||
|
||||
$content = $file->extractFileAsText();
|
||||
$this->assertContains('Test Headline', $content);
|
||||
$this->assertContains('Test Text', $content);
|
||||
$this->assertEquals($content, $file->FileContentCache);
|
||||
}
|
||||
|
||||
|
||||
}
|
11
tests/HTMLTextExtractorTest.php
Normal file
11
tests/HTMLTextExtractorTest.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
class HTMLTextExtractorTest extends SapphireTest {
|
||||
|
||||
function testExtraction() {
|
||||
$extractor = new HTMLTextExtractor();
|
||||
|
||||
$content = $extractor->getContent(Director::baseFolder() . '/textextraction/tests/fixtures/test1.html');
|
||||
$this->assertContains('Test Headline', $content);
|
||||
}
|
||||
|
||||
}
|
12
tests/PDFTextExtractorTest.php
Normal file
12
tests/PDFTextExtractorTest.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
class PDFTextExtractorTest extends SapphireTest {
|
||||
|
||||
function testExtraction() {
|
||||
$extractor = new PDFTextExtractor();
|
||||
if(!$extractor->isAvailable()) $this->markTestSkipped('pdftotext not available');
|
||||
|
||||
$content = $extractor->getContent(Director::baseFolder() . '/textextraction/tests/fixtures/test1.pdf');
|
||||
$this->assertContains('This is a test file with a link', $content);
|
||||
}
|
||||
|
||||
}
|
8
tests/fixtures/test1.html
vendored
Normal file
8
tests/fixtures/test1.html
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<h1>Test Headline</h1>
|
||||
<p>Test Text</p>
|
||||
</body>
|
||||
</html>
|
BIN
tests/fixtures/test1.pdf
vendored
Normal file
BIN
tests/fixtures/test1.pdf
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user