TikaTextExtractorTest::testExtraction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 19
rs 9.9
1
<?php
2
3
namespace SilverStripe\TextExtraction\Tests;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
8
9
/**
10
 * Tests the {@see TikaTextExtractor} class
11
 *
12
 * @group tika-tests
13
 */
14
class TikaTextExtractorTest extends SapphireTest
15
{
16
    protected $usesDatabase = true;
17
18
    public function testExtraction()
19
    {
20
        $extractor = TikaTextExtractor::create();
21
        if (!$extractor->isAvailable()) {
22
            $this->markTestSkipped('tika cli not available');
23
        }
24
25
        // Check file
26
        $file = new File();
27
        $file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
28
        $file->write();
29
30
        $content = $extractor->getContent($file);
31
        $this->assertContains('This is a test file with a link', $content);
32
33
        // Check mime validation
34
        $this->assertTrue($extractor->supportsMime('application/pdf'));
35
        $this->assertTrue($extractor->supportsMime('text/html'));
36
        $this->assertFalse($extractor->supportsMime('application/not-supported'));
37
    }
38
}
39