mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
e8375111b1
Fixes #1409
82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
|
|
|
|
use SilverStripe\Core\Object;
|
|
use SilverStripe\ORM\FieldType\DBField;
|
|
use SilverStripe\ORM\FieldType\DBString;
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
|
|
|
|
/**
|
|
* @package framework
|
|
* @subpackage tests
|
|
*/
|
|
|
|
class DBStringTest extends SapphireTest {
|
|
|
|
/**
|
|
* @covers SilverStripe\Model\FieldType\DBField::forTemplate()
|
|
*/
|
|
public function testForTemplate() {
|
|
$this->assertEquals(
|
|
"this is<br />\na test!",
|
|
DBField::create_field('StringFieldTest_MyStringField', "this is\na test!")->forTemplate()
|
|
);
|
|
}
|
|
|
|
public function testDefault() {
|
|
/** @var DBString $dbField */
|
|
$dbField = Object::create_from_string(
|
|
"StringFieldTest_MyStringField(['default' => 'Here is my default text'])",
|
|
'Myfield'
|
|
);
|
|
$this->assertEquals(
|
|
"Here is my default text",
|
|
$dbField->getDefaultValue()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers SilverStripe\Model\FieldType\DBString::LowerCase()
|
|
*/
|
|
public function testLowerCase() {
|
|
$this->assertEquals(
|
|
'this is a test!',
|
|
DBField::create_field('StringFieldTest_MyStringField', 'This is a TEST!')->LowerCase()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers SilverStripe\Model\FieldType\DBString::UpperCase()
|
|
*/
|
|
public function testUpperCase() {
|
|
$this->assertEquals(
|
|
'THIS IS A TEST!',
|
|
DBField::create_field('StringFieldTest_MyStringField', 'This is a TEST!')->UpperCase()
|
|
);
|
|
}
|
|
|
|
public function testExists() {
|
|
// True exists
|
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', true)->exists());
|
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', '0')->exists());
|
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', '1')->exists());
|
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', 1)->exists());
|
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', 1.1)->exists());
|
|
|
|
// false exists
|
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', false)->exists());
|
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', '')->exists());
|
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', null)->exists());
|
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', 0)->exists());
|
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', 0.0)->exists());
|
|
}
|
|
|
|
}
|
|
|
|
class StringFieldTest_MyStringField extends DBString implements TestOnly {
|
|
public function requireField() {}
|
|
}
|