diff --git a/src/Core/Injector/Injector.php b/src/Core/Injector/Injector.php index 8c4c940d3..0b77d82d0 100644 --- a/src/Core/Injector/Injector.php +++ b/src/Core/Injector/Injector.php @@ -426,13 +426,13 @@ class Injector implements ContainerInterface // to ensure we get cached $spec['id'] = $id; -// We've removed this check because new functionality means that the 'class' field doesn't need to refer -// specifically to a class anymore - it could be a compound statement, ala SilverStripe's old Object::create -// functionality +// We've removed this check because new functionality means that the 'class' field doesn't need to refer +// specifically to a class anymore - it could be a compound statement, ala SilverStripe's old Object::create +// functionality // -// if (!class_exists($class)) { -// throw new Exception("Failed to load '$class' from $file"); -// } +// if (!class_exists($class)) { +// throw new Exception("Failed to load '$class' from $file"); +// } // store the specs for now - we lazy load on demand later on. $this->specs[$id] = $spec; diff --git a/src/Dev/BulkLoader.php b/src/Dev/BulkLoader.php index 989fc996d..3857fc173 100644 --- a/src/Dev/BulkLoader.php +++ b/src/Dev/BulkLoader.php @@ -136,11 +136,11 @@ abstract class BulkLoader extends ViewableData } /* - * Load the given file via {@link self::processAll()} and {@link self::processRecord()}. - * Optionally truncates (clear) the table before it imports. - * - * @return BulkLoader_Result See {@link self::processAll()} - */ + * Load the given file via {@link self::processAll()} and {@link self::processRecord()}. + * Optionally truncates (clear) the table before it imports. + * + * @return BulkLoader_Result See {@link self::processAll()} + */ public function load($filepath) { Environment::increaseTimeLimitTo(3600); diff --git a/src/Dev/DevelopmentAdmin.php b/src/Dev/DevelopmentAdmin.php index db0757df0..99741822b 100644 --- a/src/Dev/DevelopmentAdmin.php +++ b/src/Dev/DevelopmentAdmin.php @@ -140,8 +140,8 @@ class DevelopmentAdmin extends Controller /* - * Internal methods - */ + * Internal methods + */ /** * @return array of url => description @@ -175,8 +175,8 @@ class DevelopmentAdmin extends Controller /* - * Unregistered (hidden) actions - */ + * Unregistered (hidden) actions + */ /** * Build the default data, calling requireDefaultRecords on all diff --git a/src/Forms/FieldList.php b/src/Forms/FieldList.php index 6acfbbf61..c926986ed 100644 --- a/src/Forms/FieldList.php +++ b/src/Forms/FieldList.php @@ -688,7 +688,7 @@ class FieldList extends ArrayList $fieldMap[$field->getName()] = $field; } - // Iterate through the ordered list of names, building a new array to be put into $this->items. + // Iterate through the ordered list of names, building a new array to be put into $this->items. // While we're doing this, empty out $fieldMap so that we can keep track of leftovers. // Unrecognised field names are okay; just ignore them $fields = array(); diff --git a/src/ORM/Connect/DBSchemaManager.php b/src/ORM/Connect/DBSchemaManager.php index 4ec52cbd9..e501d7f87 100644 --- a/src/ORM/Connect/DBSchemaManager.php +++ b/src/ORM/Connect/DBSchemaManager.php @@ -890,13 +890,13 @@ MESSAGE /* - * This is a lookup table for data types. - * For instance, Postgres uses 'INT', while MySQL uses 'UNSIGNED' - * So this is a DB-specific list of equivilents. - * - * @param string $type - * @return string - */ + * This is a lookup table for data types. + * For instance, Postgres uses 'INT', while MySQL uses 'UNSIGNED' + * So this is a DB-specific list of equivilents. + * + * @param string $type + * @return string + */ abstract public function dbDataType($type); /** @@ -1151,10 +1151,10 @@ MESSAGE abstract public function varchar($values); /* - * Returns data type for 'year' column - * - * @param array $values Contains a tokenised list of info about this data type - * @return string - */ + * Returns data type for 'year' column + * + * @param array $values Contains a tokenised list of info about this data type + * @return string + */ abstract public function year($values); } diff --git a/src/ORM/Connect/Database.php b/src/ORM/Connect/Database.php index ab6d56572..45d8b6c86 100644 --- a/src/ORM/Connect/Database.php +++ b/src/ORM/Connect/Database.php @@ -617,14 +617,14 @@ abstract class Database } /* - * Determines if the current database connection supports a given list of extensions - * - * @param array $extensions List of extensions to check for support of. The key of this array - * will be an extension name, and the value the configuration for that extension. This - * could be one of partitions, tablespaces, or clustering - * @return boolean Flag indicating support for all of the above - * @todo Write test cases - */ + * Determines if the current database connection supports a given list of extensions + * + * @param array $extensions List of extensions to check for support of. The key of this array + * will be an extension name, and the value the configuration for that extension. This + * could be one of partitions, tablespaces, or clustering + * @return boolean Flag indicating support for all of the above + * @todo Write test cases + */ public function supportsExtensions($extensions) { return false; diff --git a/src/ORM/Connect/MySQLSchemaManager.php b/src/ORM/Connect/MySQLSchemaManager.php index 30e827337..81f661ae2 100644 --- a/src/ORM/Connect/MySQLSchemaManager.php +++ b/src/ORM/Connect/MySQLSchemaManager.php @@ -614,11 +614,11 @@ class MySQLSchemaManager extends DBSchemaManager } /* - * Return the MySQL-proprietary 'Year' datatype - * - * @param array $values Contains a tokenised list of info about this data type - * @return string - */ + * Return the MySQL-proprietary 'Year' datatype + * + * @param array $values Contains a tokenised list of info about this data type + * @return string + */ public function year($values) { return 'year(4)'; diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index c9a61bb87..465ad03c4 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -3337,12 +3337,15 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity */ public function summaryFields() { - $fields = $this->config()->get('summary_fields'); + $rawFields = $this->config()->get('summary_fields'); - // if fields were passed in numeric array, - // convert to an associative array - if ($fields && array_key_exists(0, $fields)) { - $fields = array_combine(array_values($fields), array_values($fields)); + // Merge associative / numeric keys + $fields = []; + foreach ($rawFields as $key => $value) { + if (is_int($key)) { + $key = $value; + } + $fields[$key] = $value; } if (!$fields) { @@ -3418,8 +3421,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity } /* - * @ignore - */ + * @ignore + */ private static $subclass_access = true; /** diff --git a/tests/behat/src/CmsFormsContext.php b/tests/behat/src/CmsFormsContext.php index 3391be6b5..c345cb891 100644 --- a/tests/behat/src/CmsFormsContext.php +++ b/tests/behat/src/CmsFormsContext.php @@ -241,11 +241,11 @@ JS; } /* - * @example Given the CMS settings has the following data - * | Title | My site title | - * | Theme | My site theme | - * @Given /^the CMS settings have the following data$/ - */ + * @example Given the CMS settings has the following data + * | Title | My site title | + * | Theme | My site theme | + * @Given /^the CMS settings have the following data$/ + */ public function theCmsSettingsHasData(TableNode $fieldsTable) { $fields = $fieldsTable->getRowsHash(); diff --git a/tests/php/Control/ControllerTest.php b/tests/php/Control/ControllerTest.php index daead0a31..c9228911c 100644 --- a/tests/php/Control/ControllerTest.php +++ b/tests/php/Control/ControllerTest.php @@ -390,8 +390,8 @@ class ControllerTest extends FunctionalTest 'Numeric actions do not slip through.' ); //$this->assertFalse( - // $controller->hasAction('lowercase_permission'), - // 'Lowercase permission does not slip through.' + // $controller->hasAction('lowercase_permission'), + // 'Lowercase permission does not slip through.' //); $this->assertFalse( $controller->hasAction('undefined'), diff --git a/tests/php/Dev/CsvBulkLoaderTest.php b/tests/php/Dev/CsvBulkLoaderTest.php index e6cd461c1..beb0f54e7 100644 --- a/tests/php/Dev/CsvBulkLoaderTest.php +++ b/tests/php/Dev/CsvBulkLoaderTest.php @@ -230,7 +230,7 @@ class CsvBulkLoaderTest extends SapphireTest // null values are valid imported // $this->assertEquals($player->Biography, 'He\'s a good guy', - // 'Test retaining of previous information on duplicate when overwriting with blank field'); + // 'Test retaining of previous information on duplicate when overwriting with blank field'); } public function testLoadWithCustomImportMethods() diff --git a/tests/php/Forms/ListboxFieldTest.php b/tests/php/Forms/ListboxFieldTest.php index 66bccc81f..a674999a0 100644 --- a/tests/php/Forms/ListboxFieldTest.php +++ b/tests/php/Forms/ListboxFieldTest.php @@ -226,11 +226,11 @@ class ListboxFieldTest extends SapphireTest * @todo re-enable these tests when field validation is removed from {@link ListboxField::setValue()} and moved * to the {@link ListboxField::validate()} function */ - // $field->setValue(4); - // $this->assertFalse( - // $field->validate($validator), - // 'Field does not validate values outside of source map' - // ); + // $field->setValue(4); + // $this->assertFalse( + // $field->validate($validator), + // 'Field does not validate values outside of source map' + // ); $field->setValue( false, new ArrayData( diff --git a/tests/php/ORM/DataObjectTest.php b/tests/php/ORM/DataObjectTest.php index 77637977f..d25edc1f7 100644 --- a/tests/php/ORM/DataObjectTest.php +++ b/tests/php/ORM/DataObjectTest.php @@ -2,25 +2,23 @@ namespace SilverStripe\ORM\Tests; +use InvalidArgumentException; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; use SilverStripe\i18n\i18n; +use SilverStripe\ORM\Connect\MySQLDatabase; +use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObjectSchema; +use SilverStripe\ORM\DB; use SilverStripe\ORM\FieldType\DBBoolean; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBField; -use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\DB; -use SilverStripe\ORM\Connect\MySQLDatabase; use SilverStripe\ORM\FieldType\DBPolymorphicForeignKey; use SilverStripe\ORM\FieldType\DBVarchar; use SilverStripe\ORM\ManyManyList; use SilverStripe\ORM\Tests\DataObjectTest\Player; -use SilverStripe\ORM\ValidationException; use SilverStripe\View\ViewableData; use stdClass; -use ReflectionException; -use InvalidArgumentException; class DataObjectTest extends SapphireTest { @@ -87,11 +85,11 @@ class DataObjectTest extends SapphireTest // Test with table required $this->assertEquals( - DataObjectTest\TeamComment::class.'.Varchar', + DataObjectTest\TeamComment::class . '.Varchar', $schema->fieldSpec(DataObjectTest\TeamComment::class, 'Name', DataObjectSchema::INCLUDE_CLASS) ); $this->assertEquals( - DataObjectTest\TeamComment::class.'.Text', + DataObjectTest\TeamComment::class . '.Text', $schema->fieldSpec(DataObjectTest\TeamComment::class, 'Comment', DataObjectSchema::INCLUDE_CLASS) ); $dbFields = $schema->fieldSpecs(DataObjectTest\ExtendedTeamComment::class); @@ -127,8 +125,8 @@ class DataObjectTest extends SapphireTest // Values can be an array... $player = new DataObjectTest\Player( array( - 'FirstName' => 'James', - 'Surname' => 'Smith' + 'FirstName' => 'James', + 'Surname' => 'Smith' ) ); @@ -278,7 +276,7 @@ class DataObjectTest extends SapphireTest $comment1 = DataObject::get_one( DataObjectTest\TeamComment::class, array( - '"DataObjectTest_TeamComment"."Name"' => 'Joe' + '"DataObjectTest_TeamComment"."Name"' => 'Joe' ), false ); @@ -287,7 +285,7 @@ class DataObjectTest extends SapphireTest $comment2 = DataObject::get_one( DataObjectTest\TeamComment::class, array( - '"DataObjectTest_TeamComment"."Name"' => 'Joe' + '"DataObjectTest_TeamComment"."Name"' => 'Joe' ), false ); @@ -297,7 +295,7 @@ class DataObjectTest extends SapphireTest $comment1 = DataObject::get_one( DataObjectTest\TeamComment::class, array( - '"DataObjectTest_TeamComment"."Name"' => 'Bob' + '"DataObjectTest_TeamComment"."Name"' => 'Bob' ), true ); @@ -306,7 +304,7 @@ class DataObjectTest extends SapphireTest $comment2 = DataObject::get_one( DataObjectTest\TeamComment::class, array( - '"DataObjectTest_TeamComment"."Name"' => 'Bob' + '"DataObjectTest_TeamComment"."Name"' => 'Bob' ), true ); @@ -338,7 +336,7 @@ class DataObjectTest extends SapphireTest $subteam1 = DataObject::get_one( strtolower(DataObjectTest\SubTeam::class), array( - '"DataObjectTest_Team"."Title"' => 'Subteam 1' + '"DataObjectTest_Team"."Title"' => 'Subteam 1' ), true ); @@ -705,8 +703,8 @@ class DataObjectTest extends SapphireTest $obj->getChangedFields(true, DataObject::CHANGE_VALUE), array( 'FirstName' => array( - 'before'=>'Captain', - 'after'=>'Captain-changed', + 'before' => 'Captain', + 'after' => 'Captain-changed', 'level' => DataObject::CHANGE_VALUE ) ), @@ -1190,15 +1188,13 @@ class DataObjectTest extends SapphireTest $summaryFields = $team->summaryFields(); $this->assertEquals( - 'Custom Title', - $summaryFields['Title'], - 'Custom title is preserved' - ); - - $this->assertEquals( - 'Captain\'s shirt number', - $summaryFields['Captain.ShirtNumber'], - 'Custom title on relation is preserved' + [ + 'Title' => 'Custom Title', + 'Title.UpperCase' => 'Title', + 'Captain.ShirtNumber' => 'Captain\'s shirt number', + 'Captain.FavouriteTeam.Title' => 'Captain\'s favourite team', + ], + $summaryFields ); } @@ -1211,10 +1207,10 @@ class DataObjectTest extends SapphireTest $team1->update( array( - 'DatabaseField' => 'Something', - 'Captain.FirstName' => 'Jim', - 'Captain.Email' => 'jim@example.com', - 'Captain.FavouriteTeam.Title' => 'New and improved team 1', + 'DatabaseField' => 'Something', + 'Captain.FirstName' => 'Jim', + 'Captain.Email' => 'jim@example.com', + 'Captain.FavouriteTeam.Title' => 'New and improved team 1', ) ); @@ -1242,8 +1238,8 @@ class DataObjectTest extends SapphireTest $team1->update( array( - 'Captain.FirstName' => 'Jim', - 'Captain.FavouriteTeam.Title' => 'New and improved team 1', + 'Captain.FirstName' => 'Jim', + 'Captain.FavouriteTeam.Title' => 'New and improved team 1', ) ); /* Test that the captain ID has been updated */ @@ -1459,8 +1455,8 @@ class DataObjectTest extends SapphireTest $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Controller is not a valid subclass of DataObject'); /** - * @skipUpgrade -*/ + * @skipUpgrade + */ $dataObject->newClassInstance('Controller'); } @@ -1577,7 +1573,7 @@ class DataObjectTest extends SapphireTest $teamExtraFields = $team->manyManyExtraFields(); $this->assertEquals( array( - 'Players' => array('Position' => 'Varchar(100)') + 'Players' => array('Position' => 'Varchar(100)') ), $teamExtraFields ); @@ -1587,8 +1583,8 @@ class DataObjectTest extends SapphireTest $teamExtraFields = $subTeam->manyManyExtraFields(); $this->assertEquals( array( - 'Players' => array('Position' => 'Varchar(100)'), - 'FormerPlayers' => array('Position' => 'Varchar(100)') + 'Players' => array('Position' => 'Varchar(100)'), + 'FormerPlayers' => array('Position' => 'Varchar(100)') ), $teamExtraFields ); @@ -1598,7 +1594,7 @@ class DataObjectTest extends SapphireTest $this->assertEquals( $teamExtraFields, array( - 'Position' => 'Varchar(100)' + 'Position' => 'Varchar(100)' ) ); @@ -1607,7 +1603,7 @@ class DataObjectTest extends SapphireTest $this->assertEquals( $playerExtraFields, array( - 'Position' => 'Varchar(100)' + 'Position' => 'Varchar(100)' ) ); @@ -1797,9 +1793,9 @@ class DataObjectTest extends SapphireTest $company = new DataObjectTest\Company(); $this->assertEquals( - array ( - 'CurrentStaff' => DataObjectTest\Staff::class, - 'PreviousStaff' => DataObjectTest\Staff::class + array( + 'CurrentStaff' => DataObjectTest\Staff::class, + 'PreviousStaff' => DataObjectTest\Staff::class ), $company->hasMany(), 'has_many strips field name data by default.' @@ -1812,16 +1808,16 @@ class DataObjectTest extends SapphireTest ); $this->assertEquals( - array ( - 'CurrentStaff' => DataObjectTest\Staff::class.'.CurrentCompany', - 'PreviousStaff' => DataObjectTest\Staff::class.'.PreviousCompany' + array( + 'CurrentStaff' => DataObjectTest\Staff::class . '.CurrentCompany', + 'PreviousStaff' => DataObjectTest\Staff::class . '.PreviousCompany' ), $company->hasMany(false), 'has_many returns field name data when $classOnly is false.' ); $this->assertEquals( - DataObjectTest\Staff::class.'.CurrentCompany', + DataObjectTest\Staff::class . '.CurrentCompany', DataObject::getSchema()->hasManyComponent(DataObjectTest\Company::class, 'CurrentStaff', false), 'has_many returns field name data on single records when $classOnly is false.' ); @@ -1897,7 +1893,7 @@ class DataObjectTest extends SapphireTest public function testBelongsTo() { $company = new DataObjectTest\Company(); - $ceo = new DataObjectTest\CEO(); + $ceo = new DataObjectTest\CEO(); $company->Name = 'New Company'; $company->write(); @@ -1948,7 +1944,7 @@ class DataObjectTest extends SapphireTest public function testBelongsToPolymorphic() { $company = new DataObjectTest\Company(); - $ceo = new DataObjectTest\CEO(); + $ceo = new DataObjectTest\CEO(); $company->write(); $ceo->write(); diff --git a/tests/php/ORM/DataObjectTest/Team.php b/tests/php/ORM/DataObjectTest/Team.php index b44317d11..999250843 100644 --- a/tests/php/ORM/DataObjectTest/Team.php +++ b/tests/php/ORM/DataObjectTest/Team.php @@ -59,7 +59,7 @@ class Team extends DataObject implements TestOnly ); private static $summary_fields = array( - 'Title' => 'Custom Title', + 'Title', // Overridden by Team_Extension 'Title.UpperCase' => 'Title', 'Captain.ShirtNumber' => 'Captain\'s shirt number', 'Captain.FavouriteTeam.Title' => 'Captain\'s favourite team' diff --git a/tests/php/ORM/DataObjectTest/Team_Extension.php b/tests/php/ORM/DataObjectTest/Team_Extension.php index 4ad6926a0..bd6b93df2 100644 --- a/tests/php/ORM/DataObjectTest/Team_Extension.php +++ b/tests/php/ORM/DataObjectTest/Team_Extension.php @@ -7,6 +7,10 @@ use SilverStripe\ORM\DataExtension; class Team_Extension extends DataExtension implements TestOnly { + private static $summary_fields = [ + 'Title' => 'Custom Title', // override non-associative 'Title' + ]; + private static $db = array( 'ExtendedDatabaseField' => 'Varchar' ); diff --git a/tests/php/View/SSViewerTest.php b/tests/php/View/SSViewerTest.php index 2260df02d..2f3351002 100644 --- a/tests/php/View/SSViewerTest.php +++ b/tests/php/View/SSViewerTest.php @@ -1775,8 +1775,8 @@ EOC; $this->assertContains($code, $result); // TODO Fix inline links in PHP mode // $this->assertContains( - // '',