Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Standardise extension hooks #1485

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/php/Controller/AssetAdminTest/FileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@

class FileExtension extends DataExtension implements TestOnly
{
public function canView($member = null)
protected function canView($member = null)
{
if ($this->owner->Name === 'disallowCanView.txt') {
return false;
}
}

public function canEdit($member = null)
protected function canEdit($member = null)
{
if ($this->owner->Name === 'disallowCanEdit.txt') {
return false;
}
}

public function canDelete($member = null)
protected function canDelete($member = null)
{
if ($this->owner->Name === 'disallowCanDelete.txt') {
return false;
}
}


public function canCreate($member = null, $context = [])
protected function canCreate($member = null, $context = [])
{
if (isset($context['Parent']) && $context['Parent']->Name === 'disallowCanAddChildren') {
return false;
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Controller/AssetAdminTest/FolderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@

class FolderExtension extends DataExtension implements TestOnly
{
public function canView($member = null, $context = array())
protected function canView($member = null, $context = array())
{
if ($this->owner->Name === 'disallowCanView') {
return false;
}
}

public function canEdit($member = null, $context = array())
protected function canEdit($member = null, $context = array())
{
if ($this->owner->Name === 'disallowCanEdit') {
return false;
}
}

public function canDelete($member = null, $context = array())
protected function canDelete($member = null, $context = array())
{
if ($this->owner->Name === 'disallowCanDelete') {
return false;
}
}

public function canCreate($member = null, $context = array())
protected function canCreate($member = null, $context = array())
{
if (isset($context['Name']) && $context['Name'] === 'disallowCanCreate') {
return false;
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/FileFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testEditFileFormWithPermissions()
// Add extension to simulate different permissions
File::add_extension(FileExtension::class);

$this->logInWithPermission('ADMIN');
$this->logInWithPermission('CMS_ACCESS_CampaignAdmin');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having admin access results in an early return true in versioned canPublish() so our extension wasn't being called which resulted in incorrectly failing unit tests.

That's only just not become a thing because the path for public methods on extensions is different - it was being called "directly" (earlier than the versioned method) instead of being used as an extension hook.


/** @var File $file */
$file = $this->objFromFixture(File::class, 'file1');
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Forms/FileFormBuilderTest/FileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ class FileExtension extends DataExtension implements TestOnly
public static $canUnpublish = true;
public static $canEdit = true;

public function canDelete($member)
protected function canDelete($member)
{
return FileExtension::$canDelete;
}

public function canPublish($member = null)
protected function canPublish($member = null)
{
return FileExtension::$canPublish;
}

public function canUnpublish($member = null)
protected function canUnpublish($member = null)
{
return FileExtension::$canUnpublish;
}

public function canEdit($member = null)
protected function canEdit($member = null)
{
return FileExtension::$canEdit;
}
Expand Down
Loading