Merge branch '3.6' into 3

This commit is contained in:
Daniel Hensby 2018-02-13 14:30:59 +00:00
commit 09726333b7
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 79 additions and 20 deletions

29
LICENSE Normal file
View File

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2006-2018, SilverStripe Limited - www.silverstripe.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -34,26 +34,6 @@ If you would like to make changes to the SilverStripe core codebase, we have an
* [Bugtracker: Installer](https://github.com/silverstripe/silverstripe-installer/issues)
* [Forums](http://silverstripe.org/forums)
* [Developer Mailinglist](https://groups.google.com/forum/#!forum/silverstripe-dev)
## License ##
Copyright (c) 2006-2014, SilverStripe Limited - www.silverstripe.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of SilverStripe nor the names of its contributors may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
## Attribution ##

View File

@ -551,6 +551,11 @@ class Injector {
$constructorParams = $spec['constructor'];
}
// If we're dealing with a DataObject, pass through Singleton flag as second argument
if ($type != 'prototype' && empty($constructorParams) && is_subclass_of($class, 'DataObject')) {
$constructorParams = array(null, true);
}
$factory = isset($spec['factory']) ? $this->get($spec['factory']) : $this->getObjectCreator();
$object = $factory->create($class, $constructorParams);

View File

@ -33,6 +33,51 @@ class DataObjectTest extends SapphireTest {
'ManyManyListTest_Category',
);
/**
* @dataProvider provideSingletons
*/
public function testSingleton($inst, $defaultValue, $altDefaultValue)
{
$inst = $inst();
// Test that populateDefaults() isn't called on singletons
// which can lead to SQL errors during build, and endless loops
if ($defaultValue) {
$this->assertEquals($defaultValue, $inst->MyFieldWithDefault);
} else {
$this->assertEmpty($inst->MyFieldWithDefault);
}
if ($altDefaultValue) {
$this->assertEquals($altDefaultValue, $inst->MyFieldWithAltDefault);
} else {
$this->assertEmpty($inst->MyFieldWithAltDefault);
}
}
public function provideSingletons()
{
// because PHPUnit evalutes test providers *before* setUp methods
// any extensions added in the setUp methods won't be available
// we must return closures to generate the arguments at run time
return array(
array(function () {
return DataObjectTest_Fixture::create();
}, 'Default Value', 'Default Value'),
array(function () {
return new DataObjectTest_Fixture();
}, 'Default Value', 'Default Value'),
array(function () {
return singleton('DataObjectTest_Fixture');
}, null, null),
array(function () {
return DataObjectTest_Fixture::singleton();
}, null, null),
array(function () {
return new DataObjectTest_Fixture(null, true);
}, null, null),
);
}
public function testDb() {
$obj = new DataObjectTest_TeamComment();
$dbFields = $obj->db();