mirror of
https://github.com/silverstripe/silverstripe-textextraction
synced 2024-10-22 11:06:00 +02:00
API Add namespaces to tests and update SapphireTest implementation
This commit is contained in:
parent
66c9db8c0d
commit
fe5148e678
@ -1,23 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\TextExtraction\Extension\FileTextCache,
|
namespace SilverStripe\TextExtraction\Tests;
|
||||||
SilverStripe\TextExtraction\Extension\FileTextCache_Database,
|
|
||||||
SilverStripe\Dev\SapphireTest,
|
use SilverStripe\Assets\File;
|
||||||
SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\TextExtraction\Cache\FileTextCache\Database;
|
||||||
|
|
||||||
class FileTextCacheDatabaseTest extends SapphireTest
|
class FileTextCacheDatabaseTest extends SapphireTest
|
||||||
{
|
{
|
||||||
public function testTruncatesByMaxLength()
|
public function testTruncatesByMaxLength()
|
||||||
{
|
{
|
||||||
Config::nest();
|
Config::modify()->set(Database::class, 'max_content_length', 5);
|
||||||
|
|
||||||
Config::inst()->update('FileTextCache_Database', 'max_content_length', 5);
|
$cache = new Database();
|
||||||
$cache = new FileTextCache_Database();
|
$file = $this->getMockBuilder(File::class)->setMethods(['write'])->getMock();
|
||||||
$file = $this->getMock('File', array('write'));
|
|
||||||
$content = '0123456789';
|
$content = '0123456789';
|
||||||
$cache->save($file, $content);
|
$cache->save($file, $content);
|
||||||
$this->assertEquals($cache->load($file), '01234');
|
|
||||||
|
|
||||||
Config::unnest();
|
$this->assertEquals($cache->load($file), '01234');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,44 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\TextExtraction\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\TextExtraction\Extension\FileTextExtractable;
|
||||||
|
|
||||||
class FileTextExtractableTest extends SapphireTest
|
class FileTextExtractableTest extends SapphireTest
|
||||||
{
|
{
|
||||||
protected $requiredExtensions = array(
|
protected $usesDatabase = true;
|
||||||
'File' => array('FileTextExtractable')
|
|
||||||
);
|
|
||||||
|
|
||||||
public function setUp()
|
protected static $required_extensions = [
|
||||||
|
File::class => [
|
||||||
|
FileTextExtractable::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// Ensure that html is a valid extension
|
// Ensure that html is a valid extension
|
||||||
Config::inst()
|
Config::modify()->merge(File::class, 'allowed_extensions', ['html']);
|
||||||
->nest()
|
|
||||||
->update('File', 'allowed_extensions', array('html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
Config::unnest();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExtractFileAsText()
|
public function testExtractFileAsText()
|
||||||
{
|
{
|
||||||
// Create a copy of the file, as it may be clobbered by the test
|
// Create a copy of the file, as it may be clobbered by the test
|
||||||
// ($file->extractFileAsText() calls $file->write)
|
// ($file->extractFileAsText() calls $file->write)
|
||||||
copy(BASE_PATH.'/textextraction/tests/fixtures/test1.html', BASE_PATH.'/textextraction/tests/fixtures/test1-copy.html');
|
copy(
|
||||||
|
dirname(__FILE__) . '/fixtures/test1.html',
|
||||||
|
dirname(__FILE__) . '/fixtures/test1-copy.html'
|
||||||
|
);
|
||||||
|
|
||||||
// Use HTML, since the extractor is always available
|
// Use HTML, since the extractor is always available
|
||||||
$file = new File(array(
|
$file = new File([
|
||||||
'Name' => 'test1-copy.html',
|
'Name' => 'test1-copy.html',
|
||||||
'Filename' => 'textextraction/tests/fixtures/test1-copy.html'
|
'Filename' => dirname(__FILE__) . '/fixtures/test1-copy.html'
|
||||||
));
|
]);
|
||||||
$file->write();
|
$file->write();
|
||||||
|
|
||||||
$content = $file->extractFileAsText();
|
$content = $file->extractFileAsText();
|
||||||
@ -39,8 +46,8 @@ class FileTextExtractableTest extends SapphireTest
|
|||||||
$this->assertContains('Test Text', $content);
|
$this->assertContains('Test Text', $content);
|
||||||
$this->assertEquals($content, $file->FileContentCache);
|
$this->assertEquals($content, $file->FileContentCache);
|
||||||
|
|
||||||
if (file_exists(BASE_PATH.'/textextraction/tests/fixtures/test1-copy.html')) {
|
if (file_exists(dirname(__FILE__) . '/fixtures/test1-copy.html')) {
|
||||||
unlink(BASE_PATH.'/textextraction/tests/fixtures/test1-copy.html');
|
unlink(dirname(__FILE__) . '/fixtures/test1-copy.html');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\TextExtraction\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\TextExtraction\Extractor\HTMLTextExtractor;
|
||||||
|
|
||||||
class HTMLTextExtractorTest extends SapphireTest
|
class HTMLTextExtractorTest extends SapphireTest
|
||||||
{
|
{
|
||||||
public function testExtraction()
|
public function testExtraction()
|
||||||
{
|
{
|
||||||
$extractor = new HTMLTextExtractor();
|
$extractor = new HTMLTextExtractor();
|
||||||
|
|
||||||
$content = $extractor->getContent(Director::baseFolder() . '/textextraction/tests/fixtures/test1.html');
|
$content = $extractor->getContent(dirname(__FILE__) . '/fixtures/test1.html');
|
||||||
|
|
||||||
$this->assertContains('Test Headline', $content);
|
$this->assertContains('Test Headline', $content);
|
||||||
$this->assertNotContains('Test Comment', $content, 'Strips HTML comments');
|
$this->assertNotContains('Test Comment', $content, 'Strips HTML comments');
|
||||||
$this->assertNotContains('Test Style', $content, 'Strips non-content style tags');
|
$this->assertNotContains('Test Style', $content, 'Strips non-content style tags');
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\TextExtraction\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\TextExtraction\Extractor\FileTextExtractor\Exception;
|
||||||
|
use SilverStripe\TextExtraction\Extractor\PDFTextExtractor;
|
||||||
|
|
||||||
class PDFTextExtractorTest extends SapphireTest
|
class PDFTextExtractorTest extends SapphireTest
|
||||||
{
|
{
|
||||||
public function testExtraction()
|
public function testExtraction()
|
||||||
{
|
{
|
||||||
$extractor = new PDFTextExtractor();
|
$extractor = new PDFTextExtractor();
|
||||||
if (!$extractor->isAvailable()) {
|
if (!$extractor->isAvailable()) {
|
||||||
$this->setExpectedException(
|
$this->expectException(Exception::class);
|
||||||
'FileTextExtractor_Exception',
|
$this->expectExceptionMessage('getRawOutput called on unavailable extractor');
|
||||||
'getRawOutput called on unavailable extractor'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $extractor->getContent(Director::baseFolder() . '/textextraction/tests/fixtures/test1.pdf');
|
$content = $extractor->getContent(dirname(__FILE__) . '/fixtures/test1.pdf');
|
||||||
$this->assertContains('This is a test file with a link', $content);
|
$this->assertContains('This is a test file with a link', $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\TextExtraction\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\TextExtraction\Extractor\TikaServerTextExtractor;
|
||||||
|
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@see TikaTextExtractor} class
|
* Tests the {@see TikaTextExtractor} class
|
||||||
*/
|
*/
|
||||||
@ -13,7 +19,7 @@ class TikaTextExtractorTest extends SapphireTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check file
|
// Check file
|
||||||
$file = Director::baseFolder() . '/textextraction/tests/fixtures/test1.pdf';
|
$file = dirname(__FILE__) . '/fixtures/test1.pdf';
|
||||||
$content = $extractor->getContent($file);
|
$content = $extractor->getContent($file);
|
||||||
$this->assertContains('This is a test file with a link', $content);
|
$this->assertContains('This is a test file with a link', $content);
|
||||||
|
|
||||||
@ -31,7 +37,7 @@ class TikaTextExtractorTest extends SapphireTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check file
|
// Check file
|
||||||
$file = Director::baseFolder() . '/textextraction/tests/fixtures/test1.pdf';
|
$file = dirname(__FILE__) . '/fixtures/test1.pdf';
|
||||||
$content = $extractor->getContent($file);
|
$content = $extractor->getContent($file);
|
||||||
$this->assertContains('This is a test file with a link', $content);
|
$this->assertContains('This is a test file with a link', $content);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user