diff --git a/CHANGELOG.md b/CHANGELOG.md index cc667c8..8f73900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,9 @@ ``` - The second parameter (`$value`) of `Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore::setEnv()` is now of type `string`. +- Admin mode will be disabled by default when bootstrapping pimcore. +- The `WithoutAdminMode` trait was removed. + +### Bugfixes: + +- Reset admin mode to previous state after each test class when using `WithAdminMode` trait. diff --git a/README.md b/README.md index 6240ef0..72ec91c 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,9 @@ We provide traits to switch common behavior on/off in whole test case classes. #### Admin Mode -- `WithAdminMode` -- `WithoutAdminMode` +The admin mode is disabled by default when calling `BootstrapPimcore::bootstrap()`. + +To enable it again, you can use the `WithAdminMode` trait. #### Cache diff --git a/src/Pimcore/AdminMode.php b/src/Pimcore/AdminMode.php index 7bf42f1..c143e5e 100644 --- a/src/Pimcore/AdminMode.php +++ b/src/Pimcore/AdminMode.php @@ -4,7 +4,7 @@ namespace Neusta\Pimcore\TestingFramework\Pimcore; -use Pimcore\Model\DataObject\AbstractObject; +use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Localizedfield; use Pimcore\Model\Document; @@ -14,8 +14,8 @@ public static function enable(): void { \Pimcore::setAdminMode(); Document::setHideUnpublished(false); - AbstractObject::setHideUnpublished(false); - AbstractObject::setGetInheritedValues(false); + DataObject::setHideUnpublished(false); + DataObject::setGetInheritedValues(false); Localizedfield::setGetFallbackValues(false); } @@ -23,8 +23,13 @@ public static function disable(): void { \Pimcore::unsetAdminMode(); Document::setHideUnpublished(true); - AbstractObject::setHideUnpublished(true); - AbstractObject::setGetInheritedValues(true); + DataObject::setHideUnpublished(true); + DataObject::setGetInheritedValues(true); Localizedfield::setGetFallbackValues(true); } + + public static function isEnabled(): bool + { + return \Pimcore::inAdmin(); + } } diff --git a/src/Pimcore/BootstrapPimcore.php b/src/Pimcore/BootstrapPimcore.php index 53a2a50..9c972bb 100644 --- a/src/Pimcore/BootstrapPimcore.php +++ b/src/Pimcore/BootstrapPimcore.php @@ -20,6 +20,7 @@ public static function bootstrap(string ...$envVars): void Bootstrap::setProjectRoot(); Bootstrap::bootstrap(); + AdminMode::disable(); } public static function setEnv(string $name, string $value): void diff --git a/src/Pimcore/WithAdminMode.php b/src/Pimcore/WithAdminMode.php index 0a42916..5c4845c 100644 --- a/src/Pimcore/WithAdminMode.php +++ b/src/Pimcore/WithAdminMode.php @@ -6,6 +6,9 @@ trait WithAdminMode { + /** @internal */ + private static bool $adminModeWasEnabled; + /** * @internal * @@ -13,6 +16,19 @@ trait WithAdminMode */ public static function _enableAdminMode(): void { + self::$adminModeWasEnabled = AdminMode::isEnabled(); AdminMode::enable(); } + + /** + * @internal + * + * @afterClass + */ + public static function _resetAdminMode(): void + { + if (false === self::$adminModeWasEnabled) { + AdminMode::disable(); + } + } } diff --git a/src/Pimcore/WithoutAdminMode.php b/src/Pimcore/WithoutAdminMode.php deleted file mode 100644 index 227d42b..0000000 --- a/src/Pimcore/WithoutAdminMode.php +++ /dev/null @@ -1,18 +0,0 @@ -