2017-05-05 04:51:52 +02:00
|
|
|
<?php
|
|
|
|
|
2019-04-23 08:22:18 +02:00
|
|
|
use Sunnysideup\DMS\Cms\DMSUploadField;
|
|
|
|
use Sunnysideup\DMS\Cms\DMSUploadField_ItemHandler;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2017-05-05 04:51:52 +02:00
|
|
|
class DMSUploadFieldTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var DMSUploadField
|
|
|
|
*/
|
|
|
|
protected $field;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->field = new DMSUploadField('StubUploadField');
|
|
|
|
}
|
|
|
|
|
2017-07-27 03:26:43 +02:00
|
|
|
/**
|
|
|
|
* SS 3.x injector will return an overloaded parent of a child class if the child is not injected.
|
|
|
|
* This is a sanity check.
|
|
|
|
*/
|
|
|
|
public function testDmsUploadFieldIsInjectable()
|
|
|
|
{
|
2019-04-23 08:22:18 +02:00
|
|
|
$this->assertInstanceOf(DMSUploadField::class, DMSUploadField::create('Stub'));
|
2017-07-27 03:26:43 +02:00
|
|
|
}
|
|
|
|
|
2017-05-05 04:51:52 +02:00
|
|
|
/**
|
|
|
|
* The validator is coded to always return true. Replace this test if this behaviour changes in future.
|
|
|
|
*/
|
|
|
|
public function testValidatorAlwaysReturnsTrue()
|
|
|
|
{
|
|
|
|
$this->assertTrue($this->field->validate('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetItemHandler()
|
|
|
|
{
|
2019-04-23 08:22:18 +02:00
|
|
|
$this->assertInstanceOf(DMSUploadField_ItemHandler::class, $this->field->getItemHandler(123));
|
2017-05-05 04:51:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that the folder name can be get/set and that the value set is casted to a string
|
|
|
|
*/
|
|
|
|
public function testCanGetAndSetFolderName()
|
|
|
|
{
|
|
|
|
$this->field->setFolderName('qwerty');
|
|
|
|
$this->assertSame('qwerty', $this->field->getFolderName());
|
|
|
|
$this->field->setFolderName(123);
|
|
|
|
$this->assertSame('123', $this->field->getFolderName());
|
|
|
|
}
|
|
|
|
}
|