2012-01-31 11:44:16 +01:00
|
|
|
<?php
|
2015-08-30 07:02:55 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\ORM\Tests;
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2017-05-17 07:40:13 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
|
|
|
use SilverStripe\ORM\FieldType\DBString;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\ORM\Tests\DBStringTest\MyStringField;
|
2012-01-31 11:44:16 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class DBStringTest extends SapphireTest
|
|
|
|
{
|
2013-05-30 10:26:58 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\ORM\FieldType\DBField::forTemplate()
|
|
|
|
*/
|
|
|
|
public function testForTemplate()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
"this is<br />\na test!",
|
|
|
|
DBField::create_field(MyStringField::class, "this is\na test!")->forTemplate()
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testDefault()
|
|
|
|
{
|
2017-05-17 07:40:13 +02:00
|
|
|
/** @var DBString $dbField */
|
|
|
|
$dbField = Injector::inst()->create(
|
2016-12-16 05:34:21 +01:00
|
|
|
DBStringTest\MyStringField::class."(['default' => 'Here is my default text'])",
|
|
|
|
'Myfield'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
"Here is my default text",
|
|
|
|
$dbField->getDefaultValue()
|
|
|
|
);
|
|
|
|
}
|
2016-09-14 08:02:20 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\ORM\FieldType\DBString::LowerCase()
|
|
|
|
*/
|
|
|
|
public function testLowerCase()
|
|
|
|
{
|
2017-05-17 07:40:13 +02:00
|
|
|
/** @var MyStringField $field */
|
|
|
|
$field = DBField::create_field(MyStringField::class, 'This is a TEST!');
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
'this is a test!',
|
2017-05-17 07:40:13 +02:00
|
|
|
$field->LowerCase()
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
2012-01-31 11:44:16 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\ORM\FieldType\DBString::UpperCase()
|
|
|
|
*/
|
|
|
|
public function testUpperCase()
|
|
|
|
{
|
2017-05-17 07:40:13 +02:00
|
|
|
/** @var MyStringField $field */
|
|
|
|
$field = DBField::create_field(MyStringField::class, 'This is a TEST!');
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
'THIS IS A TEST!',
|
2017-05-17 07:40:13 +02:00
|
|
|
$field->UpperCase()
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
2012-01-31 11:44:16 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testExists()
|
|
|
|
{
|
|
|
|
// True exists
|
|
|
|
$this->assertTrue(DBField::create_field(MyStringField::class, true)->exists());
|
|
|
|
$this->assertTrue(DBField::create_field(MyStringField::class, '0')->exists());
|
|
|
|
$this->assertTrue(DBField::create_field(MyStringField::class, '1')->exists());
|
|
|
|
$this->assertTrue(DBField::create_field(MyStringField::class, 1)->exists());
|
|
|
|
$this->assertTrue(DBField::create_field(MyStringField::class, 1.1)->exists());
|
2015-04-01 03:31:55 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
// false exists
|
|
|
|
$this->assertFalse(DBField::create_field(MyStringField::class, false)->exists());
|
|
|
|
$this->assertFalse(DBField::create_field(MyStringField::class, '')->exists());
|
|
|
|
$this->assertFalse(DBField::create_field(MyStringField::class, null)->exists());
|
|
|
|
$this->assertFalse(DBField::create_field(MyStringField::class, 0)->exists());
|
|
|
|
$this->assertFalse(DBField::create_field(MyStringField::class, 0.0)->exists());
|
|
|
|
}
|
2012-01-31 11:44:16 +01:00
|
|
|
}
|