2015-02-18 03:31:38 +01:00
|
|
|
<?php
|
|
|
|
|
2018-07-03 01:35:24 +02:00
|
|
|
namespace SilverStripe\TextExtraction\Tests;
|
|
|
|
|
2018-07-03 06:30:05 +02:00
|
|
|
use SilverStripe\Assets\File;
|
2018-07-03 01:35:24 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
|
|
|
|
|
2015-02-18 03:31:38 +01:00
|
|
|
/**
|
|
|
|
* Tests the {@see TikaTextExtractor} class
|
2018-07-03 07:15:16 +02:00
|
|
|
*
|
|
|
|
* @group tika-tests
|
2015-02-18 03:31:38 +01:00
|
|
|
*/
|
2015-11-18 05:07:31 +01:00
|
|
|
class TikaTextExtractorTest extends SapphireTest
|
|
|
|
{
|
2018-07-03 06:30:05 +02:00
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
2015-11-18 05:07:31 +01:00
|
|
|
public function testExtraction()
|
|
|
|
{
|
2018-07-03 07:15:16 +02:00
|
|
|
$extractor = TikaTextExtractor::create();
|
2015-11-18 05:07:31 +01:00
|
|
|
if (!$extractor->isAvailable()) {
|
|
|
|
$this->markTestSkipped('tika cli not available');
|
|
|
|
}
|
2015-02-18 03:31:38 +01:00
|
|
|
|
2015-11-18 05:07:31 +01:00
|
|
|
// Check file
|
2018-07-03 06:30:05 +02:00
|
|
|
$file = new File();
|
|
|
|
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
|
|
|
|
$file->write();
|
|
|
|
|
2015-11-18 05:07:31 +01:00
|
|
|
$content = $extractor->getContent($file);
|
2021-10-27 07:16:05 +02:00
|
|
|
$this->assertStringContainsString('This is a test file with a link', $content);
|
2015-02-18 03:31:38 +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
|
|
|
}
|