From ca2e80ec08d71ade7456b8094470657d4fc7b41d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 16 Feb 2011 08:53:51 +1300 Subject: [PATCH 1/4] MINOR Updated 'from source' docs --- docs/en/installation/from-source.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/installation/from-source.md b/docs/en/installation/from-source.md index 76a2e0832..2d974e968 100644 --- a/docs/en/installation/from-source.md +++ b/docs/en/installation/from-source.md @@ -76,7 +76,7 @@ This will add `sapphire`, `cms` and the `blackcandy` theme to your project. As a fallback solution, you can simply download all necessary files without any dependency management through piston. This is handy if you have an existing project in version control, and want a one-off snapshot -of the modules that won't be updated frequently. +of the modules. The only way to update this codebase later is to overwrite the whole folder, with no easy way to track and re-apply any changes made to it since. cd my-silverstripe-project/ tools/new-project -m flat From 65f6104cd6aaad00b3fbb4a6a1c13e431afa3f9a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 11 Feb 2011 14:54:54 +1300 Subject: [PATCH 2/4] MINOR Replaced assertType() calls with assertInstanceOf(), deprecated in PHPUnit 3.6 (throws warnings as of 3.5.10) --- tests/DataObjectDecoratorTest.php | 8 ++++---- tests/DataObjectTest.php | 4 ++-- tests/ObjectTest.php | 8 ++++---- tests/RequestHandlingTest.php | 2 +- tests/SearchContextTest.php | 2 +- tests/SiteTreeActionsTest.php | 4 ++-- tests/SiteTreeTest.php | 4 ++-- tests/control/DirectorTest.php | 2 +- tests/dev/LogTest.php | 6 +++--- tests/filesystem/FileTest.php | 4 ++-- tests/forms/FormTest.php | 6 +++--- tests/model/MoneyTest.php | 8 ++++---- tests/model/SiteConfigTest.php | 2 +- tests/model/TranslatableTest.php | 8 ++++---- tests/model/VersionedTest.php | 4 ++-- tests/security/MemberTest.php | 2 +- tests/security/PasswordEncryptorTest.php | 2 +- tests/security/SecurityDefaultAdminTest.php | 2 +- tests/security/SecurityTokenTest.php | 6 +++--- 19 files changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/DataObjectDecoratorTest.php b/tests/DataObjectDecoratorTest.php index 8b00dc813..ee7a917d5 100644 --- a/tests/DataObjectDecoratorTest.php +++ b/tests/DataObjectDecoratorTest.php @@ -41,10 +41,10 @@ class DataObjectDecoratorTest extends SapphireTest { $object = DataObject::get_one('DataObjectDecoratorTest_RelatedObject', "\"ContactID\" = {$contactID}"); $this->assertNotNull($object, 'Related object not null'); - $this->assertType('DataObjectDecoratorTest_Member', $object->Contact(), 'Related contact is a member dataobject'); - $this->assertType('DataObjectDecoratorTest_Member', $object->getComponent('Contact'), 'getComponent does the same thing as Contact()'); + $this->assertInstanceOf('DataObjectDecoratorTest_Member', $object->Contact(), 'Related contact is a member dataobject'); + $this->assertInstanceOf('DataObjectDecoratorTest_Member', $object->getComponent('Contact'), 'getComponent does the same thing as Contact()'); - $this->assertType('DataObjectDecoratorTest_RelatedObject', $contact->RelatedObjects()->First()); + $this->assertInstanceOf('DataObjectDecoratorTest_RelatedObject', $contact->RelatedObjects()->First()); $this->assertEquals("Lorem ipsum dolor", $contact->RelatedObjects()->First()->FieldOne); $this->assertEquals("Random notes", $contact->RelatedObjects()->First()->FieldTwo); $contact->delete(); @@ -143,7 +143,7 @@ class DataObjectDecoratorTest extends SapphireTest { function testDbObjectOnDecoratedFields() { $member = $this->objFromFixture('DataObjectDecoratorTest_Member', 'member1'); $this->assertNotNull($member->dbObject('Website')); - $this->assertType('Varchar', $member->dbObject('Website')); + $this->assertInstanceOf('Varchar', $member->dbObject('Website')); } function testDecoratorCanBeAppliedToDataObject() { diff --git a/tests/DataObjectTest.php b/tests/DataObjectTest.php index a7da9cc03..518ba4d12 100755 --- a/tests/DataObjectTest.php +++ b/tests/DataObjectTest.php @@ -685,7 +685,7 @@ class DataObjectTest extends SapphireTest { $changedFields = $changedPage->getChangedFields(); // Don't write the record, it will reset changed fields - $this->assertType('RedirectorPage', $changedPage); + $this->assertInstanceOf('RedirectorPage', $changedPage); $this->assertEquals($changedPage->ClassName, 'RedirectorPage'); $this->assertEquals($changedPage->RedirectionType, 'Internal'); //$this->assertEquals($changedPage->RecordClassName, 'RedirectorPage'); @@ -694,7 +694,7 @@ class DataObjectTest extends SapphireTest { $this->assertEquals($changedFields['ClassName']['after'], 'RedirectorPage'); $changedPage->write(); - $this->assertType('RedirectorPage', $changedPage); + $this->assertInstanceOf('RedirectorPage', $changedPage); $this->assertEquals($changedPage->ClassName, 'RedirectorPage'); } diff --git a/tests/ObjectTest.php b/tests/ObjectTest.php index 6c2c1e271..b43db43f8 100755 --- a/tests/ObjectTest.php +++ b/tests/ObjectTest.php @@ -177,19 +177,19 @@ class ObjectTest extends SapphireTest { $inst = new ObjectTest_ExtensionTest(); $extensions = $inst->getExtensionInstances(); $this->assertEquals(count($extensions), 2); - $this->assertType( + $this->assertInstanceOf( 'ObjectTest_ExtendTest1', $extensions['ObjectTest_ExtendTest1'] ); - $this->assertType( + $this->assertInstanceOf( 'ObjectTest_ExtendTest2', $extensions['ObjectTest_ExtendTest2'] ); - $this->assertType( + $this->assertInstanceOf( 'ObjectTest_ExtendTest1', $inst->getExtensionInstance('ObjectTest_ExtendTest1') ); - $this->assertType( + $this->assertInstanceOf( 'ObjectTest_ExtendTest2', $inst->getExtensionInstance('ObjectTest_ExtendTest2') ); diff --git a/tests/RequestHandlingTest.php b/tests/RequestHandlingTest.php index 4bdf7a48d..6b4e381c7 100755 --- a/tests/RequestHandlingTest.php +++ b/tests/RequestHandlingTest.php @@ -22,7 +22,7 @@ class RequestHandlingTest extends FunctionalTest { function testConstructedWithNullRequest() { $r = new RequestHandler(); - $this->assertType('NullHTTPRequest', $r->getRequest()); + $this->assertInstanceOf('NullHTTPRequest', $r->getRequest()); } function testRequestHandlerChainingAllParams() { diff --git a/tests/SearchContextTest.php b/tests/SearchContextTest.php index 46d262a97..8cc717baf 100644 --- a/tests/SearchContextTest.php +++ b/tests/SearchContextTest.php @@ -108,7 +108,7 @@ class SearchContextTest extends SapphireTest { $project = $results->First(); - $this->assertType('SearchContextTest_Project', $project); + $this->assertInstanceOf('SearchContextTest_Project', $project); $this->assertEquals("Blog Website", $project->Name); $this->assertEquals(2, $project->Actions()->Count()); diff --git a/tests/SiteTreeActionsTest.php b/tests/SiteTreeActionsTest.php index 2c39b30e9..0ebdbfb65 100644 --- a/tests/SiteTreeActionsTest.php +++ b/tests/SiteTreeActionsTest.php @@ -64,7 +64,7 @@ class SiteTreeActionsTest extends FunctionalTest { // Get the live version of the page $page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID"); - $this->assertType("SiteTree", $page); + $this->assertInstanceOf("SiteTree", $page); // Check that someone without the right permission can't delete the page $editor = $this->objFromFixture('Member', 'cmsnodeleteeditor'); @@ -116,7 +116,7 @@ class SiteTreeActionsTest extends FunctionalTest { // Get the live version of the page $page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID"); - $this->assertType('SiteTree', $page); + $this->assertInstanceOf('SiteTree', $page); $actionsArr = $page->getCMSActions()->column('Name'); diff --git a/tests/SiteTreeTest.php b/tests/SiteTreeTest.php index b2e7dadbb..82507fde6 100755 --- a/tests/SiteTreeTest.php +++ b/tests/SiteTreeTest.php @@ -143,7 +143,7 @@ class SiteTreeTest extends SapphireTest { $child->Title = 'Page Title'; $child->setParent($parent); - $this->assertType("SiteTree", $child->Parent); + $this->assertInstanceOf("SiteTree", $child->Parent); $this->assertEquals("Section Title", $child->Parent->Title); } @@ -152,7 +152,7 @@ class SiteTreeTest extends SapphireTest { $child = new SiteTreeTest_PageNode(); $child->setParent($parent); - $this->assertType('SiteTreeTest_PageNode', $child->Parent); + $this->assertInstanceOf('SiteTreeTest_PageNode', $child->Parent); } /** diff --git a/tests/control/DirectorTest.php b/tests/control/DirectorTest.php index 74e2f885f..3fa5cd92a 100644 --- a/tests/control/DirectorTest.php +++ b/tests/control/DirectorTest.php @@ -165,7 +165,7 @@ class DirectorTest extends SapphireTest { $url = 'DirectorTestRequest_Controller/' . sprintf($testfunction, ucfirst($method)) . '?' . http_build_query($fixture); $getresponse = Director::test($url, $fixture, null, strtoupper($method), null, null, $fixture); - $this->assertType('SS_HTTPResponse', $getresponse, 'Director::test() returns SS_HTTPResponse'); + $this->assertInstanceOf('SS_HTTPResponse', $getresponse, 'Director::test() returns SS_HTTPResponse'); $this->assertEquals($fixture['somekey'], $getresponse->getBody(), 'Director::test() ' . $testfunction); } } diff --git a/tests/dev/LogTest.php b/tests/dev/LogTest.php index 262868240..c7ea88841 100644 --- a/tests/dev/LogTest.php +++ b/tests/dev/LogTest.php @@ -18,18 +18,18 @@ class SS_LogTest extends SapphireTest { function testExistingWriter() { $writers = SS_Log::get_writers(); - $this->assertType('array', $writers); + $this->assertInternalType('array', $writers); $this->assertEquals(2, count($writers)); } function testRemoveWriter() { SS_Log::remove_writer($this->testEmailWriter); $writers = SS_Log::get_writers(); - $this->assertType('array', $writers); + $this->assertInternalType('array', $writers); $this->assertEquals(1, count($writers)); SS_Log::remove_writer($this->testFileWriter); $writers = SS_Log::get_writers(); - $this->assertType('array', $writers); + $this->assertInternalType('array', $writers); $this->assertEquals(0, count($writers)); } diff --git a/tests/filesystem/FileTest.php b/tests/filesystem/FileTest.php index 457168c58..42897c80e 100644 --- a/tests/filesystem/FileTest.php +++ b/tests/filesystem/FileTest.php @@ -27,10 +27,10 @@ class FileTest extends SapphireTest { $this->assertEquals($testfilePath, $file->Filename, '"Filename" property remains unchanged'); // TODO This should be auto-detected, see File->updateFilesystem() - // $this->assertType('Folder', $file->Parent(), 'Parent folder is created in database'); + // $this->assertInstanceOf('Folder', $file->Parent(), 'Parent folder is created in database'); // $this->assertFileExists($file->Parent()->getFullPath(), 'Parent folder is created on filesystem'); // $this->assertEquals('FileTest', $file->Parent()->Name); - // $this->assertType('Folder', $file->Parent()->Parent(), 'Grandparent folder is created in database'); + // $this->assertInstanceOf('Folder', $file->Parent()->Parent(), 'Grandparent folder is created in database'); // $this->assertFileExists($file->Parent()->Parent()->getFullPath(), 'Grandparent folder is created on filesystem'); // $this->assertEquals('assets', $file->Parent()->Parent()->Name); } diff --git a/tests/forms/FormTest.php b/tests/forms/FormTest.php index c6517558b..8a71b6074 100755 --- a/tests/forms/FormTest.php +++ b/tests/forms/FormTest.php @@ -243,12 +243,12 @@ class FormTest extends FunctionalTest { SecurityToken::enable(); $form1 = $this->getStubForm(); - $this->assertType('SecurityToken', $form1->getSecurityToken()); + $this->assertInstanceOf('SecurityToken', $form1->getSecurityToken()); SecurityToken::disable(); $form2 = $this->getStubForm(); - $this->assertType('NullSecurityToken', $form2->getSecurityToken()); + $this->assertInstanceOf('NullSecurityToken', $form2->getSecurityToken()); SecurityToken::enable(); } @@ -257,7 +257,7 @@ class FormTest extends FunctionalTest { SecurityToken::enable(); $formWithToken = $this->getStubForm(); - $this->assertType( + $this->assertInstanceOf( 'HiddenField', $formWithToken->Fields()->fieldByName(SecurityToken::get_default_name()), 'Token field added by default' diff --git a/tests/model/MoneyTest.php b/tests/model/MoneyTest.php index 55fa413a3..74aa0fec0 100644 --- a/tests/model/MoneyTest.php +++ b/tests/model/MoneyTest.php @@ -21,14 +21,14 @@ class MoneyTest extends SapphireTest { function testMoneyFieldsReturnedAsObjects() { $obj = $this->objFromFixture('MoneyTest_DataObject', 'test1'); - $this->assertType('Money', $obj->MyMoney); + $this->assertInstanceOf('Money', $obj->MyMoney); } function testLoadFromFixture() { $obj = $this->objFromFixture('MoneyTest_DataObject', 'test1'); - $this->assertType('Money', $obj->MyMoney); + $this->assertInstanceOf('Money', $obj->MyMoney); $this->assertEquals($obj->MyMoney->getCurrency(), 'EUR'); $this->assertEquals($obj->MyMoney->getAmount(), 1.23); } @@ -42,7 +42,7 @@ class MoneyTest extends SapphireTest { $this->assertNotContains('MyMoney', array_keys($changed)); // With changes - $this->assertType('Money', $obj->MyMoney); + $this->assertInstanceOf('Money', $obj->MyMoney); $obj->MyMoney->setAmount(99); $changed = $obj->getChangedFields(); $this->assertContains('MyMoney', array_keys($changed)); @@ -280,7 +280,7 @@ class MoneyTest extends SapphireTest { function testLoadIntoDataObject() { $obj = new MoneyTest_DataObject(); - $this->assertType('Money', $obj->obj('MyMoney')); + $this->assertInstanceOf('Money', $obj->obj('MyMoney')); $m = new Money(); $m->setValue(array( diff --git a/tests/model/SiteConfigTest.php b/tests/model/SiteConfigTest.php index e85c71375..181ce2db9 100644 --- a/tests/model/SiteConfigTest.php +++ b/tests/model/SiteConfigTest.php @@ -39,7 +39,7 @@ class SiteConfigTest extends SapphireTest { $configEn = SiteConfig::current_site_config(); $configFr = SiteConfig::current_site_config('fr_FR'); - $this->assertType('SiteConfig', $configFr); + $this->assertInstanceOf('SiteConfig', $configFr); $this->assertEquals($configFr->Locale, 'fr_FR'); $this->assertEquals($configFr->Title, $configEn->Title, 'Copies title from existing config'); } diff --git a/tests/model/TranslatableTest.php b/tests/model/TranslatableTest.php index 157ee35fc..2ac167ef2 100755 --- a/tests/model/TranslatableTest.php +++ b/tests/model/TranslatableTest.php @@ -220,7 +220,7 @@ class TranslatableTest extends FunctionalTest { // first test with default language $fields = $pageOrigLang->getCMSFields(); - $this->assertType( + $this->assertInstanceOf( 'TextField', $fields->dataFieldByName('Title'), 'Translatable doesnt modify fields if called in default language (e.g. "non-translation mode")' @@ -233,13 +233,13 @@ class TranslatableTest extends FunctionalTest { // then in "translation mode" $pageTranslated = $pageOrigLang->createTranslation('fr_FR'); $fields = $pageTranslated->getCMSFields(); - $this->assertType( + $this->assertInstanceOf( 'TextField', $fields->dataFieldByName('Title'), 'Translatable leaves original formfield intact in "translation mode"' ); $readonlyField = $fields->dataFieldByName('Title')->performReadonlyTransformation(); - $this->assertType( + $this->assertInstanceOf( $readonlyField->class, $fields->dataFieldByName('Title_original'), 'Translatable adds the original value as a ReadonlyField in "translation mode"' @@ -793,7 +793,7 @@ class TranslatableTest extends FunctionalTest { "Users with canEdit() and TRANSLATE_ALL permission can't create a new translation if locale is not in Translatable::get_allowed_locales()" ); - $this->assertType( + $this->assertInstanceOf( 'Page', $testPage->createTranslation('ja_JP') ); diff --git a/tests/model/VersionedTest.php b/tests/model/VersionedTest.php index 87879bf37..7ac497747 100644 --- a/tests/model/VersionedTest.php +++ b/tests/model/VersionedTest.php @@ -94,11 +94,11 @@ class VersionedTest extends SapphireTest { function testVersionedFieldsAdded() { $obj = new VersionedTest_DataObject(); // Check that the Version column is added as a full-fledged column - $this->assertType('Int', $obj->dbObject('Version')); + $this->assertInstanceOf('Int', $obj->dbObject('Version')); $obj2 = new VersionedTest_Subclass(); // Check that the Version column is added as a full-fledged column - $this->assertType('Int', $obj2->dbObject('Version')); + $this->assertInstanceOf('Int', $obj2->dbObject('Version')); } function testPublishCreateNewVersion() { diff --git a/tests/security/MemberTest.php b/tests/security/MemberTest.php index 2c50ef49c..c4de0d64f 100644 --- a/tests/security/MemberTest.php +++ b/tests/security/MemberTest.php @@ -150,7 +150,7 @@ class MemberTest extends FunctionalTest { $this->assertTrue($record->checkPassword('test1'), "Password test1 not found in MemberRecord"); $record = $passwords->next(); - $this->assertType('DataObject', $record); + $this->assertInstanceOf('DataObject', $record); $this->assertTrue($record->checkPassword('1nitialPassword'), "Password 1nitialPassword not found in MemberRecord"); } diff --git a/tests/security/PasswordEncryptorTest.php b/tests/security/PasswordEncryptorTest.php index c514b3ab2..fc862da6c 100644 --- a/tests/security/PasswordEncryptorTest.php +++ b/tests/security/PasswordEncryptorTest.php @@ -3,7 +3,7 @@ class PasswordEncryptorTest extends SapphireTest { function testCreateForCode() { PasswordEncryptor::register('test', 'PasswordEncryptorTest_TestEncryptor'); $e = PasswordEncryptor::create_for_algorithm('test'); - $this->assertType( + $this->assertInstanceOf( 'PasswordEncryptorTest_TestEncryptor', $e ); diff --git a/tests/security/SecurityDefaultAdminTest.php b/tests/security/SecurityDefaultAdminTest.php index b5a695d10..60099f988 100644 --- a/tests/security/SecurityDefaultAdminTest.php +++ b/tests/security/SecurityDefaultAdminTest.php @@ -40,7 +40,7 @@ class SecurityDefaultAdminTest extends SapphireTest { $admin = Security::findAnAdministrator(); - $this->assertType('Member', $admin); + $this->assertInstanceOf('Member', $admin); $this->assertTrue(Permission::checkMember($admin, 'ADMIN')); $this->assertNull($admin->Email); $this->assertNull($admin->Password); diff --git a/tests/security/SecurityTokenTest.php b/tests/security/SecurityTokenTest.php index f07567cbe..d25faf572 100644 --- a/tests/security/SecurityTokenTest.php +++ b/tests/security/SecurityTokenTest.php @@ -41,7 +41,7 @@ class SecurityTokenTest extends SapphireTest { function testInst() { $inst1 = SecurityToken::inst(); - $this->assertType('SecurityToken', $inst1); + $this->assertInstanceOf('SecurityToken', $inst1); } function testInstReturnsSingleton() { @@ -111,7 +111,7 @@ class SecurityTokenTest extends SapphireTest { $t->updateFieldSet($fs); $f = $fs->dataFieldByName($t->getName()); - $this->assertType('HiddenField', $f); + $this->assertInstanceOf('HiddenField', $f); $this->assertEquals($f->Name(), $t->getName(), 'Name matches'); $this->assertEquals($f->Value(), $t->getValue(), 'Value matches'); } @@ -123,7 +123,7 @@ class SecurityTokenTest extends SapphireTest { $t->updateFieldSet($fs); // second $f = $fs->dataFieldByName($t->getName()); - $this->assertType('HiddenField', $f); + $this->assertInstanceOf('HiddenField', $f); $this->assertEquals(1, $fs->Count()); } From 23e342ce03a0e54206c52ffa9bd0d09ba7651883 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 11 Feb 2011 15:09:49 +1300 Subject: [PATCH 3/4] API CHANGE Removing support for PHPUnit 3.4 (3.5.0 has been released in Sept 2010). Removing PhpUnitWrapper_3_4, and adding better version detection. --- dev/TestRunner.php | 2 +- dev/phpunit/PhpUnitWrapper.php | 24 +++--------- dev/phpunit/PhpUnitWrapper_3_4.php | 63 ------------------------------ dev/phpunit/PhpUnitWrapper_3_5.php | 2 - 4 files changed, 7 insertions(+), 84 deletions(-) delete mode 100644 dev/phpunit/PhpUnitWrapper_3_4.php diff --git a/dev/TestRunner.php b/dev/TestRunner.php index a7d89942c..814c9cffb 100644 --- a/dev/TestRunner.php +++ b/dev/TestRunner.php @@ -89,7 +89,7 @@ class TestRunner extends Controller { if (!self::$default_reporter) self::set_reporter(Director::is_cli() ? 'CliDebugView' : 'DebugView'); if(!PhpUnitWrapper::has_php_unit()) { - die("Please install PHPUnit using pear"); + die("Please install PHPUnit 3.5.0 or newer using pear\n"); } } diff --git a/dev/phpunit/PhpUnitWrapper.php b/dev/phpunit/PhpUnitWrapper.php index 7c98107a1..6a53d47d4 100644 --- a/dev/phpunit/PhpUnitWrapper.php +++ b/dev/phpunit/PhpUnitWrapper.php @@ -22,7 +22,7 @@ function fileExistsInIncludePath($filename) { /** * PHPUnit Wrapper class. * Base class for PHPUnit wrapper classes to support different PHPUnit versions. - * The current implementation supports PHPUnit 3.4 and PHPUnit 3.5. + * The current implementation supports PHPUnit 3.5. */ class PhpUnitWrapper implements IPhpUnitWrapper { @@ -48,13 +48,6 @@ class PhpUnitWrapper implements IPhpUnitWrapper { * @var PHPUnit_Framework_TestListener */ private $reporter = null; - - /** - * Shows the version, implemented by the phpunit-wrapper class instance. - * This instance implements no phpunit, the version is null. - * @var String - */ - protected $version = null; private static $phpunit_wrapper = null; @@ -123,11 +116,10 @@ class PhpUnitWrapper implements IPhpUnitWrapper { } /** - * Getter for $version (@see $version). * @return String */ public function getVersion() { - return $this->version; + return (method_exists('PHPUnit_Runner_Version', 'id')) ? PHPUnit_Runner_Version::id() : null; } /** @@ -140,25 +132,21 @@ class PhpUnitWrapper implements IPhpUnitWrapper { if (self::$phpunit_wrapper == null) { if (fileExistsInIncludePath("/PHPUnit/Autoload.php")) { self::$phpunit_wrapper = new PhpUnitWrapper_3_5(); - } else - if (fileExistsInIncludePath("/PHPUnit/Framework.php")) { - self::$phpunit_wrapper = new PhpUnitWrapper_3_4(); } else { - self::$phpunit_wrapper = new PhpUnitWrapper(); + self::$phpunit_wrapper = new PhpUnitWrapper(); } self::$phpunit_wrapper->init(); - } + return self::$phpunit_wrapper; } /** - * Returns true if one of the two supported PHPUNIT versions is installed. - * * @return boolean true if PHPUnit has been installed on the environment. */ static function has_php_unit() { - return (Bool) self::inst()->getVersion(); + $version = self::inst()->getVersion(); + return ($version && version_compare($version, '3.5.0', '>=')); } /** diff --git a/dev/phpunit/PhpUnitWrapper_3_4.php b/dev/phpunit/PhpUnitWrapper_3_4.php deleted file mode 100644 index 476fd0fbd..000000000 --- a/dev/phpunit/PhpUnitWrapper_3_4.php +++ /dev/null @@ -1,63 +0,0 @@ -getCoverageStatus()) { - // blacklist selected folders from coverage report - foreach(TestRunner::$coverage_filter_dirs as $dir) { - PHPUnit_Util_Filter::addDirectoryToFilter(BASE_PATH . '/' . $dir); - } - $this->getFrameworkTestResults()->collectCodeCoverageInformation(true); - } - } - - /** - * Overwrites aferRunTests. Creates coverage report and clover report - * if required. - */ - protected function aferRunTests() { - - if($this->getCoverageStatus()) { - - if(!file_exists(ASSETS_PATH . '/coverage-report')) { - mkdir(ASSETS_PATH . '/coverage-report'); - } - - $ret = PHPUnit_Util_Report::render($this->getFrameworkTestResults(), ASSETS_PATH . '/coverage-report/'); - - $coverageApp = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',Director::baseFolder())) . '.html'; - $coverageTemplates = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',realpath(TEMP_FOLDER))) . '.html'; - - echo "

Coverage reports available here:

"; - } - } - -} \ No newline at end of file diff --git a/dev/phpunit/PhpUnitWrapper_3_5.php b/dev/phpunit/PhpUnitWrapper_3_5.php index 67637df47..3e518bc4f 100644 --- a/dev/phpunit/PhpUnitWrapper_3_5.php +++ b/dev/phpunit/PhpUnitWrapper_3_5.php @@ -6,8 +6,6 @@ class PhpUnitWrapper_3_5 extends PhpUnitWrapper { - protected $version = 'PhpUnit V3.5'; - protected $coverage = null; protected static $test_name = 'SapphireTest'; From 662c5259e5fe62a426c6601e0c37f5d73fe8a5ec Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 22 Feb 2011 00:19:23 +1300 Subject: [PATCH 4/4] BUGFIX Fixed Group->collateAncestorIDs() handling of orphans (fixes #6413) --- security/Group.php | 2 +- tests/security/GroupTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/security/Group.php b/security/Group.php index 0bd4a1d6e..df9e27dab 100644 --- a/security/Group.php +++ b/security/Group.php @@ -278,7 +278,7 @@ class Group extends DataObject { */ public function collateAncestorIDs() { $parent = $this; - while(isset($parent)) { + while(isset($parent) && $parent instanceof Group) { $items[] = $parent->ID; $parent = $parent->Parent; } diff --git a/tests/security/GroupTest.php b/tests/security/GroupTest.php index f16820e54..f4aabd539 100644 --- a/tests/security/GroupTest.php +++ b/tests/security/GroupTest.php @@ -84,6 +84,32 @@ class GroupTest extends FunctionalTest { $this->assertNull(DataObject::get('Group', "\"ID\"={$adminGroup->ID}"), 'Group is removed'); $this->assertNull(DataObject::get('Permission',"\"GroupID\"={$adminGroup->ID}"), 'Permissions removed along with the group'); } + + function testCollateAncestorIDs() { + $parentGroup = $this->objFromFixture('Group', 'parentgroup'); + $childGroup = $this->objFromFixture('Group', 'childgroup'); + $orphanGroup = new Group(); + $orphanGroup->ParentID = 99999; + $orphanGroup->write(); + + $this->assertEquals( + array($parentGroup->ID), + $parentGroup->collateAncestorIDs(), + 'Root node only contains itself' + ); + + $this->assertEquals( + array($childGroup->ID, $parentGroup->ID), + $childGroup->collateAncestorIDs(), + 'Contains parent nodes, with child node first' + ); + + $this->assertEquals( + array($orphanGroup->ID), + $orphanGroup->collateAncestorIDs(), + 'Orphaned nodes dont contain invalid parent IDs' + ); + } } class GroupTest_Member extends Member implements TestOnly {