mirror of
https://github.com/silverstripe/silverstripe-textextraction
synced 2024-10-22 11:06:00 +02:00
- Return 0.0.0 if no version
- Add unit test
This commit is contained in:
parent
4429acb6ec
commit
eebb738bd6
@ -71,13 +71,7 @@ class TikaServerTextExtractor extends FileTextExtractor
|
|||||||
public function isAvailable()
|
public function isAvailable()
|
||||||
{
|
{
|
||||||
$version = $this->getVersion();
|
$version = $this->getVersion();
|
||||||
// ensure that the version number has a major, minor and patch number
|
$version = $this->normaliseVersion($version);
|
||||||
// reason being that version_compare('1.7', '1.7.0') will return -1 instead of 0
|
|
||||||
for ($i = 0; $i < 2; $i++) {
|
|
||||||
if (substr_count($version, '.') < 2) {
|
|
||||||
$version .= '.0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->getServerEndpoint() &&
|
return $this->getServerEndpoint() &&
|
||||||
$this->getClient()->isAvailable() &&
|
$this->getClient()->isAvailable() &&
|
||||||
version_compare($version, '1.7.0') >= 0;
|
version_compare($version, '1.7.0') >= 0;
|
||||||
@ -121,4 +115,24 @@ class TikaServerTextExtractor extends FileTextExtractor
|
|||||||
{
|
{
|
||||||
return $this->getClient()->tika($path);
|
return $this->getClient()->tika($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that the version number has a major, minor and patch number
|
||||||
|
* Reason being that version_compare('1.7', '1.7.0') will return -1 instead of 0
|
||||||
|
*
|
||||||
|
* @param $version
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function normaliseVersion($version)
|
||||||
|
{
|
||||||
|
if (!$version) {
|
||||||
|
return '0.0.0';
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < 2; $i++) {
|
||||||
|
if (substr_count($version, '.') < 2) {
|
||||||
|
$version .= '.0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $version;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,4 +40,24 @@ class TikaTextExtractorTest extends SapphireTest
|
|||||||
$this->assertTrue($extractor->supportsMime('text/html'));
|
$this->assertTrue($extractor->supportsMime('text/html'));
|
||||||
$this->assertFalse($extractor->supportsMime('application/not-supported'));
|
$this->assertFalse($extractor->supportsMime('application/not-supported'));
|
||||||
}
|
}
|
||||||
|
public function testNormaliseVersion()
|
||||||
|
{
|
||||||
|
$extractor = new TikaServerTextExtractor();
|
||||||
|
$reflection = new ReflectionClass($extractor);
|
||||||
|
$method = $reflection->getMethod('normaliseVersion');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$arr = [
|
||||||
|
'1.7.1' => '1.7.1',
|
||||||
|
'1.7' => '1.7.0',
|
||||||
|
'1' => '1.0.0',
|
||||||
|
null => '0.0.0',
|
||||||
|
'v1.5' => 'v1.5.0',
|
||||||
|
'carrot' => 'carrot.0.0'
|
||||||
|
];
|
||||||
|
foreach ($arr as $input => $expected) {
|
||||||
|
$actual = $method->invoke($extractor, $input);
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user