mirror of
https://github.com/silverstripe/silverstripe-textextraction
synced 2024-10-22 11:06:00 +02:00
Seperate Tika tests, group them for phpunit, further reduce log level, make Extractors injectable
This commit is contained in:
parent
397e7a5d40
commit
9e8ed243d0
@ -6,6 +6,7 @@ use SilverStripe\Assets\File;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Injector\Injectable;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\TextExtraction\Extractor\FileTextExtractor\Exception;
|
||||
|
||||
@ -16,6 +17,7 @@ use SilverStripe\TextExtraction\Extractor\FileTextExtractor\Exception;
|
||||
abstract class FileTextExtractor
|
||||
{
|
||||
use Configurable;
|
||||
use Injectable;
|
||||
|
||||
/**
|
||||
* Set priority from 0-100.
|
||||
|
@ -58,7 +58,7 @@ class TikaRestClient extends Client
|
||||
}
|
||||
} catch (RequestException $ex) {
|
||||
$msg = sprintf("Tika unavailable - %s", $ex->getMessage());
|
||||
Injector::inst()->get(LoggerInterface::class)->notice($msg);
|
||||
Injector::inst()->get(LoggerInterface::class)->info($msg);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -139,7 +139,7 @@ class TikaRestClient extends Client
|
||||
$msg .= ' Body: ' . $body;
|
||||
}
|
||||
|
||||
Injector::inst()->get(LoggerInterface::class)->notice($msg);
|
||||
Injector::inst()->get(LoggerInterface::class)->info($msg);
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
36
tests/TikaServerTextExtractor.php
Normal file
36
tests/TikaServerTextExtractor.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\TextExtraction\Tests;
|
||||
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\TextExtraction\Extractor\TikaServerTextExtractor;
|
||||
|
||||
/**
|
||||
* @group tika-tests
|
||||
*/
|
||||
class TikaServerTextExtractorTest extends SapphireTest
|
||||
{
|
||||
protected $usesDatabase = true;
|
||||
|
||||
public function testServerExtraction()
|
||||
{
|
||||
$extractor = TikaServerTextExtractor::create();
|
||||
if (!$extractor->isAvailable()) {
|
||||
$this->markTestSkipped('tika server not available');
|
||||
}
|
||||
|
||||
// Check file
|
||||
$file = new File();
|
||||
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
|
||||
$file->write();
|
||||
|
||||
$content = $extractor->getContent($file);
|
||||
$this->assertContains('This is a test file with a link', $content);
|
||||
|
||||
// Check mime validation
|
||||
$this->assertTrue($extractor->supportsMime('application/pdf'));
|
||||
$this->assertTrue($extractor->supportsMime('text/html'));
|
||||
$this->assertFalse($extractor->supportsMime('application/not-supported'));
|
||||
}
|
||||
}
|
@ -4,11 +4,12 @@ namespace SilverStripe\TextExtraction\Tests;
|
||||
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\TextExtraction\Extractor\TikaServerTextExtractor;
|
||||
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
|
||||
|
||||
/**
|
||||
* Tests the {@see TikaTextExtractor} class
|
||||
*
|
||||
* @group tika-tests
|
||||
*/
|
||||
class TikaTextExtractorTest extends SapphireTest
|
||||
{
|
||||
@ -16,7 +17,7 @@ class TikaTextExtractorTest extends SapphireTest
|
||||
|
||||
public function testExtraction()
|
||||
{
|
||||
$extractor = new TikaTextExtractor();
|
||||
$extractor = TikaTextExtractor::create();
|
||||
if (!$extractor->isAvailable()) {
|
||||
$this->markTestSkipped('tika cli not available');
|
||||
}
|
||||
@ -34,25 +35,4 @@ class TikaTextExtractorTest extends SapphireTest
|
||||
$this->assertTrue($extractor->supportsMime('text/html'));
|
||||
$this->assertFalse($extractor->supportsMime('application/not-supported'));
|
||||
}
|
||||
|
||||
public function testServerExtraction()
|
||||
{
|
||||
$extractor = new TikaServerTextExtractor();
|
||||
if (!$extractor->isAvailable()) {
|
||||
$this->markTestSkipped('tika server not available');
|
||||
}
|
||||
|
||||
// Check file
|
||||
$file = new File();
|
||||
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
|
||||
$file->write();
|
||||
|
||||
$content = $extractor->getContent($file);
|
||||
$this->assertContains('This is a test file with a link', $content);
|
||||
|
||||
// Check mime validation
|
||||
$this->assertTrue($extractor->supportsMime('application/pdf'));
|
||||
$this->assertTrue($extractor->supportsMime('text/html'));
|
||||
$this->assertFalse($extractor->supportsMime('application/not-supported'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user