silverstripe-textextraction/tests/TikaTextExtractorTest.php

39 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\TextExtraction\Tests;
use SilverStripe\Assets\File;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
/**
* Tests the {@see TikaTextExtractor} class
*
* @group tika-tests
*/
2015-11-18 05:07:31 +01:00
class TikaTextExtractorTest extends SapphireTest
{
protected $usesDatabase = true;
2015-11-18 05:07:31 +01:00
public function testExtraction()
{
$extractor = TikaTextExtractor::create();
2015-11-18 05:07:31 +01:00
if (!$extractor->isAvailable()) {
$this->markTestSkipped('tika cli not available');
}
2015-11-18 05:07:31 +01:00
// Check file
$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-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
}