Skip to content

Commit

Permalink
Disable admin mode by default (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreesen committed Jun 20, 2023
1 parent a924f74 commit 1c5d93e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/Pimcore/AdminMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,17 +14,22 @@ 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);
}

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();
}
}
1 change: 1 addition & 0 deletions src/Pimcore/BootstrapPimcore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/Pimcore/WithAdminMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@

trait WithAdminMode
{
/** @internal */
private static bool $adminModeWasEnabled;

/**
* @internal
*
* @beforeClass
*/
public static function _enableAdminMode(): void
{
self::$adminModeWasEnabled = AdminMode::isEnabled();
AdminMode::enable();
}

/**
* @internal
*
* @afterClass
*/
public static function _resetAdminMode(): void
{
if (false === self::$adminModeWasEnabled) {
AdminMode::disable();
}
}
}
18 changes: 0 additions & 18 deletions src/Pimcore/WithoutAdminMode.php

This file was deleted.

0 comments on commit 1c5d93e

Please sign in to comment.