silverstripe-framework/tests/php/ORM/DBStringTest.php

72 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2016-10-14 03:30:05 +02:00
namespace SilverStripe\ORM\Tests;
use SilverStripe\Core\Object;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBString;
use SilverStripe\Dev\SapphireTest;
2016-10-14 03:30:05 +02:00
use SilverStripe\ORM\Tests\DBStringTest\MyStringField;
class DBStringTest extends SapphireTest {
/**
2016-10-14 03:30:05 +02:00
* @covers \SilverStripe\ORM\FieldType\DBField::forTemplate()
*/
public function testForTemplate() {
$this->assertEquals(
"this is<br />\na test!",
2016-10-14 03:30:05 +02:00
DBField::create_field(MyStringField::class, "this is\na test!")->forTemplate()
);
}
2014-08-15 08:53:05 +02:00
public function testDefault() {
/** @var DBString $dbField */
$dbField = Object::create_from_string(
2016-11-13 08:35:43 +01:00
DBStringTest\MyStringField::class."(['default' => 'Here is my default text'])",
'Myfield'
);
$this->assertEquals(
"Here is my default text",
$dbField->getDefaultValue()
);
}
/**
2016-10-14 03:30:05 +02:00
* @covers \SilverStripe\ORM\FieldType\DBString::LowerCase()
*/
public function testLowerCase() {
$this->assertEquals(
'this is a test!',
2016-10-14 03:30:05 +02:00
DBField::create_field(MyStringField::class, 'This is a TEST!')->LowerCase()
);
}
/**
2016-10-14 03:30:05 +02:00
* @covers \SilverStripe\ORM\FieldType\DBString::UpperCase()
*/
public function testUpperCase() {
$this->assertEquals(
'THIS IS A TEST!',
2016-10-14 03:30:05 +02:00
DBField::create_field(MyStringField::class, 'This is a TEST!')->UpperCase()
);
}
public function testExists() {
// True exists
2016-10-14 03:30:05 +02:00
$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());
// false exists
2016-10-14 03:30:05 +02:00
$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());
}
}