2012-01-31 11:44:16 +01:00
|
|
|
<?php
|
2015-08-30 07:02:55 +02:00
|
|
|
|
|
|
|
use SilverStripe\Model\FieldType\DBField;
|
|
|
|
use SilverStripe\Model\FieldType\DBString;
|
|
|
|
|
2012-01-31 11:44:16 +01:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2012-01-31 11:44:16 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
|
2015-08-30 07:02:55 +02:00
|
|
|
class DBStringTest extends SapphireTest {
|
2013-05-30 10:26:58 +02:00
|
|
|
|
|
|
|
/**
|
2016-03-26 05:58:28 +01:00
|
|
|
* @covers SilverStripe\Model\FieldType\DBField::forTemplate()
|
2013-05-30 10:26:58 +02:00
|
|
|
*/
|
|
|
|
public function testForTemplate() {
|
|
|
|
$this->assertEquals(
|
|
|
|
"this is<br />\na test!",
|
|
|
|
DBField::create_field('StringFieldTest_MyStringField', "this is\na test!")->forTemplate()
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-01-31 11:44:16 +01:00
|
|
|
/**
|
2016-03-26 05:58:28 +01:00
|
|
|
* @covers SilverStripe\Model\FieldType\DBString::LowerCase()
|
2012-01-31 11:44:16 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testLowerCase() {
|
2012-01-31 11:44:16 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
'this is a test!',
|
2012-03-27 06:57:42 +02:00
|
|
|
DBField::create_field('StringFieldTest_MyStringField', 'This is a TEST!')->LowerCase()
|
2012-01-31 11:44:16 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-26 05:58:28 +01:00
|
|
|
* @covers SilverStripe\Model\FieldType\DBString::UpperCase()
|
2012-01-31 11:44:16 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testUpperCase() {
|
2012-01-31 11:44:16 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
'THIS IS A TEST!',
|
2012-03-27 06:57:42 +02:00
|
|
|
DBField::create_field('StringFieldTest_MyStringField', 'This is a TEST!')->UpperCase()
|
2012-01-31 11:44:16 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-01 03:31:55 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2012-01-31 11:44:16 +01:00
|
|
|
}
|
|
|
|
|
2015-08-30 07:02:55 +02:00
|
|
|
class StringFieldTest_MyStringField extends DBString implements TestOnly {
|
2012-09-19 12:07:39 +02:00
|
|
|
public function requireField() {}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|