-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Ensure getters and setters are respected (#10708)
- Loading branch information
1 parent
981e20e
commit e3a94b9
Showing
10 changed files
with
203 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace SilverStripe\ORM\Tests\DBFieldTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataObject; | ||
|
||
class TestDataObject extends DataObject implements TestOnly | ||
{ | ||
private static $table_name = 'DBFieldTest_TestDataObject'; | ||
|
||
private static $db = [ | ||
'Title' => TestDbField::class, | ||
'MyTestField' => TestDbField::class, | ||
]; | ||
|
||
public $setFieldCalledCount = 0; | ||
|
||
public function setField($fieldName, $val) | ||
{ | ||
$this->setFieldCalledCount++; | ||
return parent::setField($fieldName, $val); | ||
} | ||
|
||
public function setMyTestField($val) | ||
{ | ||
return $this->setField('MyTestField', strtolower($val)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace SilverStripe\ORM\Tests\DBFieldTest; | ||
|
||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DB; | ||
use SilverStripe\ORM\FieldType\DBField; | ||
|
||
class TestDbField extends DBField implements TestOnly | ||
{ | ||
public function requireField() | ||
{ | ||
// Basically the same as DBVarchar but we don't want to test with DBVarchar in case something | ||
// changes in that class eventually. | ||
$charset = Config::inst()->get(MySQLDatabase::class, 'charset'); | ||
$collation = Config::inst()->get(MySQLDatabase::class, 'collation'); | ||
|
||
$parts = [ | ||
'datatype' => 'varchar', | ||
'precision' => 255, | ||
'character set' => $charset, | ||
'collate' => $collation, | ||
'arrayValue' => $this->arrayValue | ||
]; | ||
|
||
$values = [ | ||
'type' => 'varchar', | ||
'parts' => $parts | ||
]; | ||
|
||
DB::require_field($this->tableName, $this->name, $values); | ||
} | ||
|
||
public $saveIntoCalledCount = 0; | ||
|
||
public function saveInto($dataObject) | ||
{ | ||
$this->saveIntoCalledCount++; | ||
return parent::saveInto($dataObject); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace SilverStripe\ORM\Tests\DataObjectTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataObject; | ||
|
||
class SettersAndGetters extends DataObject implements TestOnly | ||
{ | ||
private static $table_name = 'DataObjectTest_SettersAndGetters'; | ||
|
||
private static $db = [ | ||
'MyTestField' => 'Varchar(255)', | ||
]; | ||
|
||
public function setMyTestField($val) | ||
{ | ||
$this->setField('MyTestField', strtolower($val)); | ||
} | ||
|
||
public function getMyTestField() | ||
{ | ||
return strtoupper($this->getField('MyTestField')); | ||
} | ||
} |