From 09902f9b000abbf0b567377bcb1b7e7dc14528a6 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 16:36:15 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/ChangeSet.php | 6 +- src/ChangeSetItem.php | 12 +-- src/GraphQL/Plugins/UnpublishOnDelete.php | 2 +- src/GraphQL/Plugins/VersionedDataObject.php | 2 +- src/GraphQL/Plugins/VersionedRead.php | 2 +- src/GraphQL/Resolvers/VersionedResolver.php | 2 +- src/ReadingMode.php | 8 +- src/RecursivePublishable.php | 2 +- src/RestoreAction.php | 4 +- src/Versioned.php | 78 +++++++++---------- src/VersionedGridFieldItemRequest.php | 16 ++-- tests/php/GraphQL/Fake/FakeDataObjectStub.php | 2 +- tests/php/VersionedNumberCacheTest.php | 18 ++--- tests/php/VersionedTest/TestObject.php | 6 +- 14 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/ChangeSet.php b/src/ChangeSet.php index 1e5a3eb0..d0551346 100644 --- a/src/ChangeSet.php +++ b/src/ChangeSet.php @@ -623,11 +623,11 @@ public function getPublishedLabel() public function getStateLabel() { switch ($this->State) { - case self::STATE_OPEN: + case ChangeSet::STATE_OPEN: return _t(__CLASS__.'.STATE_OPEN', 'Active'); - case self::STATE_PUBLISHED: + case ChangeSet::STATE_PUBLISHED: return _t(__CLASS__.'.STATE_PUBLISHED', 'Published'); - case self::STATE_REVERTED: + case ChangeSet::STATE_REVERTED: return _t(__CLASS__.'.STATE_REVERTED', 'Reverted'); default: return null; diff --git a/src/ChangeSetItem.php b/src/ChangeSetItem.php index 2c19efc1..be147260 100644 --- a/src/ChangeSetItem.php +++ b/src/ChangeSetItem.php @@ -129,7 +129,7 @@ public function getChangeType() // Unversioned classes have no change type if (!$this->isVersioned()) { - return self::CHANGE_NONE; + return ChangeSetItem::CHANGE_NONE; } // Get change versions @@ -153,13 +153,13 @@ public function getChangeType() // Version comparisons if ($draftVersion == $liveVersion) { - $type = self::CHANGE_NONE; + $type = ChangeSetItem::CHANGE_NONE; } elseif (!$liveVersion) { - $type = self::CHANGE_CREATED; + $type = ChangeSetItem::CHANGE_CREATED; } elseif (!$draftVersion) { - $type = self::CHANGE_DELETED; + $type = ChangeSetItem::CHANGE_DELETED; } else { - $type = self::CHANGE_MODIFIED; + $type = ChangeSetItem::CHANGE_MODIFIED; } $this->extend('updateChangeType', $type, $draftVersion, $liveVersion); return $type; @@ -402,7 +402,7 @@ public function canPublish($member = null) { // No action for unversiond objects so no action to deny // Implicitly added items allow publish - if (!$this->isVersioned() || $this->Added === self::IMPLICITLY) { + if (!$this->isVersioned() || $this->Added === ChangeSetItem::IMPLICITLY) { return true; } diff --git a/src/GraphQL/Plugins/UnpublishOnDelete.php b/src/GraphQL/Plugins/UnpublishOnDelete.php index b708e006..ed47ddf0 100644 --- a/src/GraphQL/Plugins/UnpublishOnDelete.php +++ b/src/GraphQL/Plugins/UnpublishOnDelete.php @@ -31,7 +31,7 @@ class UnpublishOnDelete implements ModelMutationPlugin */ public function getIdentifier(): string { - return self::IDENTIFIER; + return UnpublishOnDelete::IDENTIFIER; } public function apply(ModelMutation $mutation, Schema $schema, array $config = []): void diff --git a/src/GraphQL/Plugins/VersionedDataObject.php b/src/GraphQL/Plugins/VersionedDataObject.php index 4af0e0f7..8a947e46 100644 --- a/src/GraphQL/Plugins/VersionedDataObject.php +++ b/src/GraphQL/Plugins/VersionedDataObject.php @@ -39,7 +39,7 @@ class VersionedDataObject implements ModelTypePlugin, SchemaUpdater */ public function getIdentifier(): string { - return self::IDENTIFIER; + return VersionedDataObject::IDENTIFIER; } /** diff --git a/src/GraphQL/Plugins/VersionedRead.php b/src/GraphQL/Plugins/VersionedRead.php index c1ac8858..1bce5498 100644 --- a/src/GraphQL/Plugins/VersionedRead.php +++ b/src/GraphQL/Plugins/VersionedRead.php @@ -25,7 +25,7 @@ class VersionedRead implements ModelQueryPlugin */ public function getIdentifier(): string { - return self::IDENTIFIER; + return VersionedRead::IDENTIFIER; } /** diff --git a/src/GraphQL/Resolvers/VersionedResolver.php b/src/GraphQL/Resolvers/VersionedResolver.php index 869f06d6..a5c08ecb 100644 --- a/src/GraphQL/Resolvers/VersionedResolver.php +++ b/src/GraphQL/Resolvers/VersionedResolver.php @@ -83,7 +83,7 @@ public static function resolveVersionList(array $resolverContext): Closure } // Get all versions - return self::getVersionsList($object); + return VersionedResolver::getVersionsList($object); }; } diff --git a/src/ReadingMode.php b/src/ReadingMode.php index 5a0f5c5b..e6bb3721 100644 --- a/src/ReadingMode.php +++ b/src/ReadingMode.php @@ -28,14 +28,14 @@ public static function toDataQueryParams($mode) switch ($parts[0]) { case 'Archive': $archiveStage = isset($parts[2]) ? $parts[2] : Versioned::DRAFT; - self::validateStage($archiveStage); + ReadingMode::validateStage($archiveStage); return [ 'Versioned.mode' => 'archive', 'Versioned.date' => $parts[1], 'Versioned.stage' => $archiveStage, ]; case 'Stage': - self::validateStage($parts[1]); + ReadingMode::validateStage($parts[1]); return [ 'Versioned.mode' => 'stage', 'Versioned.stage' => $parts[1], @@ -133,13 +133,13 @@ public static function toQueryString($mode) switch ($parts[0]) { case 'Archive': $archiveStage = isset($parts[2]) ? $parts[2] : Versioned::DRAFT; - self::validateStage($archiveStage); + ReadingMode::validateStage($archiveStage); return [ 'archiveDate' => $parts[1], 'stage' => $archiveStage, ]; case 'Stage': - self::validateStage($parts[1]); + ReadingMode::validateStage($parts[1]); return [ 'stage' => $parts[1], ]; diff --git a/src/RecursivePublishable.php b/src/RecursivePublishable.php index 25df24f4..f44adb35 100644 --- a/src/RecursivePublishable.php +++ b/src/RecursivePublishable.php @@ -264,7 +264,7 @@ protected function lookupReverseOwners() array_shift($classes); // skip DataObject foreach ($classes as $class) { // Ensure this class is RecursivePublishable - if (!DataObject::has_extension($class, self::class)) { + if (!DataObject::has_extension($class, RecursivePublishable::class)) { continue; } diff --git a/src/RestoreAction.php b/src/RestoreAction.php index 86fe3fcd..a9739edc 100644 --- a/src/RestoreAction.php +++ b/src/RestoreAction.php @@ -57,7 +57,7 @@ public static function restore($item) ); } - $changedLocation = self::shouldRestoreToRoot($item); + $changedLocation = RestoreAction::shouldRestoreToRoot($item); $archivedItem = Versioned::get_latest_version($classname, $id); @@ -69,7 +69,7 @@ public static function restore($item) ->byID($archivedItem->ID); } - $message = self::getRestoreMessage($item, $restoredItem, $changedLocation); + $message = RestoreAction::getRestoreMessage($item, $restoredItem, $changedLocation); return $message; } diff --git a/src/Versioned.php b/src/Versioned.php index e1f18060..2f756266 100644 --- a/src/Versioned.php +++ b/src/Versioned.php @@ -122,7 +122,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider, Resetta * * @var null */ - protected static $default_reading_mode = self::DEFAULT_MODE; + protected static $default_reading_mode = Versioned::DEFAULT_MODE; /** * Field used to hold the migrating version @@ -147,9 +147,9 @@ class Versioned extends DataExtension implements TemplateGlobalProvider, Resetta * @var array */ private static $non_virtual_fields = [ - self::MIGRATING_VERSION, - self::NEXT_WRITE_WITHOUT_VERSIONED, - self::DELETE_WRITES_VERSION_DISABLED, + Versioned::MIGRATING_VERSION, + Versioned::NEXT_WRITE_WITHOUT_VERSIONED, + Versioned::DELETE_WRITES_VERSION_DISABLED, ]; /** @@ -302,7 +302,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider, Resetta */ public static function reset() { - self::$reading_mode = ''; + Versioned::$reading_mode = ''; Controller::curr()->getRequest()->getSession()->clear('readingMode'); } @@ -329,7 +329,7 @@ public function augmentDataQueryCreation(SQLSelect &$query, DataQuery &$dataQuer * * @var string $mode One of "StagedVersioned" or "Versioned". */ - public function __construct($mode = self::STAGEDVERSIONED) + public function __construct($mode = Versioned::STAGEDVERSIONED) { if (!in_array($mode, [static::STAGEDVERSIONED, static::VERSIONED])) { throw new InvalidArgumentException("Invalid mode: {$mode}"); @@ -1300,8 +1300,8 @@ public function augmentWrite(&$manipulation) } else { // All writes are to draft, only live affect both $stages = !$this->hasStages() || static::get_stage() === static::LIVE - ? [self::DRAFT, self::LIVE] - : [self::DRAFT]; + ? [Versioned::DRAFT, Versioned::LIVE] + : [Versioned::DRAFT]; $this->augmentWriteVersioned($manipulation, $class, $table, $id, $stages, false); } @@ -1360,7 +1360,7 @@ public function onAfterWrite() */ public function getNextWriteWithoutVersion() { - return $this->owner->getField(self::NEXT_WRITE_WITHOUT_VERSIONED); + return $this->owner->getField(Versioned::NEXT_WRITE_WITHOUT_VERSIONED); } /** @@ -1371,7 +1371,7 @@ public function getNextWriteWithoutVersion() */ public function setNextWriteWithoutVersion($flag) { - return $this->owner->setField(self::NEXT_WRITE_WITHOUT_VERSIONED, $flag); + return $this->owner->setField(Versioned::NEXT_WRITE_WITHOUT_VERSIONED, $flag); } /** @@ -1381,7 +1381,7 @@ public function setNextWriteWithoutVersion($flag) */ public function getDeleteWritesVersion() { - return !$this->owner->getField(self::DELETE_WRITES_VERSION_DISABLED); + return !$this->owner->getField(Versioned::DELETE_WRITES_VERSION_DISABLED); } /** @@ -1392,7 +1392,7 @@ public function getDeleteWritesVersion() */ public function setDeleteWritesVersion($flag) { - return $this->owner->setField(self::DELETE_WRITES_VERSION_DISABLED, !$flag); + return $this->owner->setField(Versioned::DELETE_WRITES_VERSION_DISABLED, !$flag); } /** @@ -1646,7 +1646,7 @@ public function canViewVersioned($member = null) $owner = $this->owner; // Bypass if site is unsecured - if (!self::get_draft_site_secured()) { + if (!Versioned::get_draft_site_secured()) { return true; } @@ -1706,7 +1706,7 @@ public function canViewVersioned($member = null) * @param Member $member * @return bool */ - public function canViewStage($stage = self::LIVE, $member = null) + public function canViewStage($stage = Versioned::LIVE, $member = null) { return static::withVersionedMode(function () use ($stage, $member) { Versioned::set_stage($stage); @@ -1807,7 +1807,7 @@ public function publishSingle() // get the last published version $original = null; if ($this->isPublished()) { - $original = self::get_by_stage($owner->baseClass(), self::LIVE) + $original = Versioned::get_by_stage($owner->baseClass(), Versioned::LIVE) ->byID($owner->ID); } @@ -1961,7 +1961,7 @@ public function copyVersionToStage($fromStage, $toStage) */ public function getMigratingVersion() { - return $this->owner->getField(self::MIGRATING_VERSION); + return $this->owner->getField(Versioned::MIGRATING_VERSION); } /** @@ -1972,7 +1972,7 @@ public function getMigratingVersion() */ public function setMigratingVersion($version) { - return $this->owner->setField(self::MIGRATING_VERSION, $version); + return $this->owner->setField(Versioned::MIGRATING_VERSION, $version); } /** @@ -2231,7 +2231,7 @@ public static function choose_site_stage(HTTPRequest $request) */ public static function set_reading_mode($mode) { - self::$reading_mode = $mode; + Versioned::$reading_mode = $mode; } /** @@ -2241,7 +2241,7 @@ public static function set_reading_mode($mode) */ public static function get_reading_mode() { - return self::$reading_mode; + return Versioned::$reading_mode; } /** @@ -2307,7 +2307,7 @@ public static function set_stage($stage) */ public static function set_default_reading_mode($mode) { - self::$default_reading_mode = $mode; + Versioned::$default_reading_mode = $mode; } /** @@ -2317,7 +2317,7 @@ public static function set_default_reading_mode($mode) */ public static function get_default_reading_mode() { - return self::$default_reading_mode ?: self::DEFAULT_MODE; + return Versioned::$default_reading_mode ?: Versioned::DEFAULT_MODE; } /** @@ -2332,7 +2332,7 @@ public static function get_draft_site_secured() return (bool)static::$is_draft_site_secured; } // Config default - return (bool)Config::inst()->get(self::class, 'draft_site_secured'); + return (bool)Config::inst()->get(Versioned::class, 'draft_site_secured'); } /** @@ -2351,7 +2351,7 @@ public static function set_draft_site_secured($secured) * @param string $date New reading archived date. * @param string $stage Set stage */ - public static function reading_archived_date($date, $stage = self::DRAFT) + public static function reading_archived_date($date, $stage = Versioned::DRAFT) { ReadingMode::validateStage($stage); Versioned::set_reading_mode('Archive.' . $date . '.' . $stage); @@ -2413,9 +2413,9 @@ private static function determineVersionNumberByStage($class, $stage, $id, $cach // cached call if ($cache) { - if (isset(self::$cache_versionnumber[$baseClass][$stage][$id])) { - return self::$cache_versionnumber[$baseClass][$stage][$id] ?: null; - } elseif (isset(self::$cache_versionnumber[$baseClass][$stage]['_complete'])) { + if (isset(Versioned::$cache_versionnumber[$baseClass][$stage][$id])) { + return Versioned::$cache_versionnumber[$baseClass][$stage][$id] ?: null; + } elseif (isset(Versioned::$cache_versionnumber[$baseClass][$stage]['_complete'])) { // if the cache was marked as "complete" then we know the record is missing, just return null // this is used for treeview optimisation to avoid unnecessary re-requests for draft pages return null; @@ -2430,16 +2430,16 @@ private static function determineVersionNumberByStage($class, $stage, $id, $cach // cache value (if required) if ($cache) { - if (!isset(self::$cache_versionnumber[$baseClass])) { - self::$cache_versionnumber[$baseClass] = []; + if (!isset(Versioned::$cache_versionnumber[$baseClass])) { + Versioned::$cache_versionnumber[$baseClass] = []; } - if (!isset(self::$cache_versionnumber[$baseClass][$stage])) { - self::$cache_versionnumber[$baseClass][$stage] = []; + if (!isset(Versioned::$cache_versionnumber[$baseClass][$stage])) { + Versioned::$cache_versionnumber[$baseClass][$stage] = []; } // Internally store nulls as 0 - self::$cache_versionnumber[$baseClass][$stage][$id] = $version ?: 0; + Versioned::$cache_versionnumber[$baseClass][$stage][$id] = $version ?: 0; } return $version ?: null; @@ -2456,8 +2456,8 @@ public function onPrepopulateTreeDataCache($recordList = null, array $options = { $idList = is_array($recordList) ? $recordList : ($recordList instanceof DataList ? $recordList->column('ID') : null); - self::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::DRAFT, $idList); - self::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::LIVE, $idList); + Versioned::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::DRAFT, $idList); + Versioned::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::LIVE, $idList); } /** @@ -2498,13 +2498,13 @@ public static function prepopulate_versionnumber_cache($class, $stage, $idList = // If we are caching IDs for _all_ records then we can mark this cache as "complete" and in the case of a cache-miss // no subsequent call is necessary } else { - self::$cache_versionnumber[$baseClass][$stage] = [ '_complete' => true ]; + Versioned::$cache_versionnumber[$baseClass][$stage] = [ '_complete' => true ]; } $versions = DB::prepared_query("SELECT \"ID\", \"Version\" FROM \"$stageTable\" $filter", $parameters)->map(); foreach ($versions as $id => $version) { - self::$cache_versionnumber[$baseClass][$stage][$id] = $version; + Versioned::$cache_versionnumber[$baseClass][$stage][$id] = $version; } $className = $class instanceof DataObject ? $class->ClassName : $class; @@ -2560,7 +2560,7 @@ public function deleteFromStage($stage) // Fix the version number cache (in case you go delete from stage and then check ExistsOnLive) $baseClass = $owner->baseClass(); - self::$cache_versionnumber[$baseClass][$stage][$owner->ID] = null; + Versioned::$cache_versionnumber[$baseClass][$stage][$owner->ID] = null; } /** @@ -2638,7 +2638,7 @@ public function rollbackRecursive($version = null) public function rollbackSingle($version) { // Validate $version and safely cast - if (isset($version) && !is_numeric($version) && $version !== self::LIVE) { + if (isset($version) && !is_numeric($version) && $version !== Versioned::LIVE) { throw new InvalidArgumentException("Invalid rollback source version $version"); } if (isset($version) && is_numeric($version)) { @@ -2647,7 +2647,7 @@ public function rollbackSingle($version) // Copy version between stage $owner = $this->owner; $owner->invokeWithExtensions('onBeforeRollbackSingle', $version); - $owner->copyVersionToStage($version, self::DRAFT); + $owner->copyVersionToStage($version, Versioned::DRAFT); $owner->invokeWithExtensions('onAfterRollbackSingle', $version); } @@ -2916,7 +2916,7 @@ public function onBeforeDuplicate($source, $doWrite) public function flushCache() { - self::$cache_versionnumber = []; + Versioned::$cache_versionnumber = []; $this->versionModifiedCache = []; } diff --git a/src/VersionedGridFieldItemRequest.php b/src/VersionedGridFieldItemRequest.php index 99aa354d..0ec3ecf8 100644 --- a/src/VersionedGridFieldItemRequest.php +++ b/src/VersionedGridFieldItemRequest.php @@ -307,7 +307,7 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions) $rootTabSet = TabSet::create('ActionMenus'); $moreOptions = Tab::create( 'MoreOptions', - _t(self::class . '.MoreOptions', 'More options', 'Expands a view for more buttons') + _t(VersionedGridFieldItemRequest::class . '.MoreOptions', 'More options', 'Expands a view for more buttons') ); $moreOptions->addExtraClass('popover-actions-simulate'); @@ -329,7 +329,7 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions) $actionSave = ($majorActions) ? $majorActions->fieldByName('action_doSave') : null; if ($canEdit && $isOnDraft && $actionSave !== null) { $actionSave - ->setTitle(_t(self::class . '.BUTTONSAVED', 'Saved')) + ->setTitle(_t(VersionedGridFieldItemRequest::class . '.BUTTONSAVED', 'Saved')) ->removeExtraClass('btn-primary font-icon-save font-icon-rocket') ->addExtraClass('btn-outline-primary font-icon-tick') ->setAttribute('data-btn-alternate-add', 'btn-primary font-icon-save') @@ -340,19 +340,19 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions) // "publish" action if ($canPublish && $isOnDraft) { // "publish", as with "save", it supports an alternate state to show when action is needed. - $actionPublish = FormAction::create('doPublish', _t(self::class . '.BUTTONPUBLISHED', 'Published')) + $actionPublish = FormAction::create('doPublish', _t(VersionedGridFieldItemRequest::class . '.BUTTONPUBLISHED', 'Published')) ->addExtraClass($noChangesClasses) ->setAttribute('data-btn-alternate-add', 'btn-primary font-icon-rocket') ->setAttribute('data-btn-alternate-remove', $noChangesClasses) ->setUseButtonTag(true) - ->setAttribute('data-text-alternate', _t(self::class . '.BUTTONSAVEPUBLISH', 'Publish')); + ->setAttribute('data-text-alternate', _t(VersionedGridFieldItemRequest::class . '.BUTTONSAVEPUBLISH', 'Publish')); $actions->insertAfter('action_doSave', $actionPublish); // Set up the initial state of the button to reflect the state of the underlying record object. if ($stagesDiffer) { $actionPublish->addExtraClass('btn-primary font-icon-rocket'); - $actionPublish->setTitle(_t(self::class . '.BUTTONSAVEPUBLISH', 'Publish')); + $actionPublish->setTitle(_t(VersionedGridFieldItemRequest::class . '.BUTTONSAVEPUBLISH', 'Publish')); $actionPublish->removeExtraClass($noChangesClasses); } } @@ -361,10 +361,10 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions) if ($isPublished && $isOnDraft && $canUnpublish) { $actionUnpublish = FormAction::create( 'doUnpublish', - _t(self::class . '.BUTTONUNPUBLISH', 'Unpublish') + _t(VersionedGridFieldItemRequest::class . '.BUTTONUNPUBLISH', 'Unpublish') ) ->setDescription( - _t(self::class . '.BUTTONUNPUBLISHDESC', 'Remove this record from the published site') + _t(VersionedGridFieldItemRequest::class . '.BUTTONUNPUBLISHDESC', 'Remove this record from the published site') ) ->addExtraClass('btn-secondary'); @@ -386,7 +386,7 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions) $actionArchive = FormAction::create('doArchive', $title) ->addExtraClass('delete btn btn-secondary') - ->setDescription(_t(self::class . '.BUTTONARCHIVEDESC', 'Unpublish and send to archive')); + ->setDescription(_t(VersionedGridFieldItemRequest::class . '.BUTTONARCHIVEDESC', 'Unpublish and send to archive')); $moreOptions->push($actionArchive); } diff --git a/tests/php/GraphQL/Fake/FakeDataObjectStub.php b/tests/php/GraphQL/Fake/FakeDataObjectStub.php index 9da64613..f3b71d29 100644 --- a/tests/php/GraphQL/Fake/FakeDataObjectStub.php +++ b/tests/php/GraphQL/Fake/FakeDataObjectStub.php @@ -31,6 +31,6 @@ public function canEdit($member = null) public function rollbackRecursive($rollbackVersion) { - self::$rollbackCalled = true; + FakeDataObjectStub::$rollbackCalled = true; } } diff --git a/tests/php/VersionedNumberCacheTest.php b/tests/php/VersionedNumberCacheTest.php index cf4bde41..70eb406a 100644 --- a/tests/php/VersionedNumberCacheTest.php +++ b/tests/php/VersionedNumberCacheTest.php @@ -36,7 +36,7 @@ public static function setUpBeforeClass(): void // Initialise our dummy object $obj = TestObject::create(['Title' => 'Initial version']); $obj->write(); - self::$publishedID = $obj->ID; + VersionedNumberCacheTest::$publishedID = $obj->ID; // Create our live version $obj->Title = 'This will be our live version'; @@ -52,9 +52,9 @@ public static function setUpBeforeClass(): void // This object won't ne publish $draftOnly = TestObject::create(['Title' => 'Draft Only object']); $draftOnly->write(); - self::$draftOnlyID = $draftOnly->ID; + VersionedNumberCacheTest::$draftOnlyID = $draftOnly->ID; - self::$expectedVersions = [ + VersionedNumberCacheTest::$expectedVersions = [ 'liveVersion' => $liveVersion, 'draftVersion' => $draftVersion, 'null' => null @@ -85,13 +85,13 @@ public function cacheDataProvider() */ public function testVersionNumberCache($stage, $ID, $cache, $expected) { - $actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache); - $this->assertEquals(self::$expectedVersions[$expected], $actual); + $actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, VersionedNumberCacheTest::${$ID}, $cache); + $this->assertEquals(VersionedNumberCacheTest::$expectedVersions[$expected], $actual); if ($cache) { // When cahing is eanbled, try re-accessing version number to make sure the cache returns the same value - $actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache); - $this->assertEquals(self::$expectedVersions[$expected], $actual); + $actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, VersionedNumberCacheTest::${$ID}, $cache); + $this->assertEquals(VersionedNumberCacheTest::$expectedVersions[$expected], $actual); } } @@ -101,7 +101,7 @@ public function testVersionNumberCache($stage, $ID, $cache, $expected) public function testPrepopulatedVersionNumberCache($stage, $ID, $cache, $expected) { TestObject::singleton()->onPrepopulateTreeDataCache(); - $actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache); - $this->assertEquals(self::$expectedVersions[$expected], $actual); + $actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, VersionedNumberCacheTest::${$ID}, $cache); + $this->assertEquals(VersionedNumberCacheTest::$expectedVersions[$expected], $actual); } } diff --git a/tests/php/VersionedTest/TestObject.php b/tests/php/VersionedTest/TestObject.php index 14ab57c5..f644d490 100644 --- a/tests/php/VersionedTest/TestObject.php +++ b/tests/php/VersionedTest/TestObject.php @@ -74,8 +74,8 @@ public function canView($member = null) public function onAfterPublish($original) { - if (self::$setNameWithoutVersionAfterPublish !== null) { - $this->Name = self::$setNameWithoutVersionAfterPublish; + if (TestObject::$setNameWithoutVersionAfterPublish !== null) { + $this->Name = TestObject::$setNameWithoutVersionAfterPublish; $this->writeWithoutVersion(); } } @@ -83,6 +83,6 @@ public function onAfterPublish($original) public function onAfterDelete() { parent::onAfterDelete(); - self::$nameValueOfObjectJustDeleted = $this->Name; + TestObject::$nameValueOfObjectJustDeleted = $this->Name; } }