silverstripe-textextraction/tests/TikaTextExtractorTest.php

44 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Tests the {@see TikaTextExtractor} class
*/
2015-11-18 05:07:31 +01:00
class TikaTextExtractorTest extends SapphireTest
{
public function testExtraction()
{
$extractor = new TikaTextExtractor();
if (!$extractor->isAvailable()) {
$this->markTestSkipped('tika cli not available');
}
2015-11-18 05:07:31 +01:00
// Check file
$file = Director::baseFolder() . '/textextraction/tests/fixtures/test1.pdf';
$content = $extractor->getContent($file);
$this->assertContains('This is a test file with a link', $content);
2015-11-18 05:07:31 +01:00
// Check mime validation
$this->assertTrue($extractor->supportsMime('application/pdf'));
$this->assertTrue($extractor->supportsMime('text/html'));
$this->assertFalse($extractor->supportsMime('application/not-supported'));
}
2015-11-18 05:07:31 +01:00
public function testServerExtraction()
{
$extractor = new TikaServerTextExtractor();
if (!$extractor->isAvailable()) {
$this->markTestSkipped('tika server not available');
}
2015-02-25 02:44:03 +01:00
2015-11-18 05:07:31 +01:00
// Check file
$file = Director::baseFolder() . '/textextraction/tests/fixtures/test1.pdf';
$content = $extractor->getContent($file);
$this->assertContains('This is a test file with a link', $content);
2015-02-25 02:44:03 +01:00
2015-11-18 05:07:31 +01:00
// Check mime validation
$this->assertTrue($extractor->supportsMime('application/pdf'));
$this->assertTrue($extractor->supportsMime('text/html'));
$this->assertFalse($extractor->supportsMime('application/not-supported'));
}
2015-02-25 02:44:03 +01:00
}