Skip to content

Commit 09423a6

Browse files
Adds tests
1 parent 64f56eb commit 09423a6

3 files changed

Lines changed: 109 additions & 0 deletions

File tree

tests/Integration/APITest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,26 @@ public function test_deleteContainerVariable_shouldFailWhenContainerNotExists()
493493
$this->api->deleteContainerVariable($this->idSite, 9999, $this->idContainerDraftVersion, $idVariable = 999);
494494
}
495495

496+
public function test_deleteContainerVariable_shouldFailWhenMissingCustomTemplateCapability()
497+
{
498+
$this->setAdminUser();
499+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array($this->idSite));
500+
$idVariable = $this->api->addContainerVariable(
501+
$this->idSite,
502+
$this->idContainer,
503+
$this->idContainerDraftVersion,
504+
CustomJsFunctionVariable::ID,
505+
'myCustomVariable'
506+
);
507+
508+
$this->expectException(\Piwik\NoAccessException::class);
509+
$this->expectExceptionMessage('checkUserHasCapability tagmanager_use_custom_templates Fake exception');
510+
511+
$this->setWriteUser();
512+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array());
513+
$this->api->deleteContainerVariable($this->idSite, $this->idContainer, $this->idContainerDraftVersion, $idVariable);
514+
}
515+
496516
public function test_deleteContainerTrigger_shouldFailWhenNotHavingViewPermissions()
497517
{
498518
$this->expectException(\Piwik\NoAccessException::class);
@@ -543,6 +563,30 @@ public function test_deleteContainerTag_shouldFailWhenContainerNotExists()
543563
$this->api->deleteContainerTag($this->idSite, 9999, $this->idContainerDraftVersion, $idTag = 999);
544564
}
545565

566+
public function test_deleteContainerTag_shouldFailWhenMissingCustomTemplateCapability()
567+
{
568+
$this->setAdminUser();
569+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array($this->idSite));
570+
$idTrigger = $this->api->addContainerTrigger($this->idSite, $this->idContainer, $this->idContainerDraftVersion, WindowLoadedTrigger::ID, 'myTagDeleteTrigger');
571+
$fireTrigger = array($idTrigger);
572+
$idTag = $this->api->addContainerTag(
573+
$this->idSite,
574+
$this->idContainer,
575+
$this->idContainerDraftVersion,
576+
CustomHtmlTag::ID,
577+
'myCustomTag',
578+
array('customHtml' => 'foo'),
579+
$fireTrigger
580+
);
581+
582+
$this->expectException(\Piwik\NoAccessException::class);
583+
$this->expectExceptionMessage('checkUserHasCapability tagmanager_use_custom_templates Fake exception');
584+
585+
$this->setWriteUser();
586+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array());
587+
$this->api->deleteContainerTag($this->idSite, $this->idContainer, $this->idContainerDraftVersion, $idTag);
588+
}
589+
546590
public function test_pauseContainerTag_shouldFailWhenNotHavingWritePermissions()
547591
{
548592
$this->expectException(\Piwik\NoAccessException::class);
@@ -591,6 +635,30 @@ public function test_pauseContainerTag_success()
591635
$this->assertEquals('myName', $tag['name']);
592636
}
593637

638+
public function test_pauseContainerTag_shouldFailWhenMissingCustomTemplateCapability()
639+
{
640+
$this->setAdminUser();
641+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array($this->idSite));
642+
$idTrigger = $this->api->addContainerTrigger($this->idSite, $this->idContainer, $this->idContainerDraftVersion, WindowLoadedTrigger::ID, 'myTagPauseTrigger');
643+
$fireTrigger = array($idTrigger);
644+
$idTag = $this->api->addContainerTag(
645+
$this->idSite,
646+
$this->idContainer,
647+
$this->idContainerDraftVersion,
648+
CustomHtmlTag::ID,
649+
'myCustomTag',
650+
array('customHtml' => 'foo'),
651+
$fireTrigger
652+
);
653+
654+
$this->expectException(\Piwik\NoAccessException::class);
655+
$this->expectExceptionMessage('checkUserHasCapability tagmanager_use_custom_templates Fake exception');
656+
657+
$this->setWriteUser();
658+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array());
659+
$this->api->pauseContainerTag($this->idSite, $this->idContainer, $this->idContainerDraftVersion, $idTag);
660+
}
661+
594662
public function test_resumeContainerTag_shouldFailWhenNotHavingWritePermissions()
595663
{
596664
$this->expectException(\Piwik\NoAccessException::class);
@@ -640,6 +708,31 @@ public function test_resumeContainerTag_success()
640708
$this->assertEquals('myName', $tag['name']);
641709
}
642710

711+
public function test_resumeContainerTag_shouldFailWhenMissingCustomTemplateCapability()
712+
{
713+
$this->setAdminUser();
714+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array($this->idSite));
715+
$idTrigger = $this->api->addContainerTrigger($this->idSite, $this->idContainer, $this->idContainerDraftVersion, WindowLoadedTrigger::ID, 'myTagResumeTrigger');
716+
$fireTrigger = array($idTrigger);
717+
$idTag = $this->api->addContainerTag(
718+
$this->idSite,
719+
$this->idContainer,
720+
$this->idContainerDraftVersion,
721+
CustomHtmlTag::ID,
722+
'myCustomTag',
723+
array('customHtml' => 'foo'),
724+
$fireTrigger
725+
);
726+
$this->api->pauseContainerTag($this->idSite, $this->idContainer, $this->idContainerDraftVersion, $idTag);
727+
728+
$this->expectException(\Piwik\NoAccessException::class);
729+
$this->expectExceptionMessage('checkUserHasCapability tagmanager_use_custom_templates Fake exception');
730+
731+
$this->setWriteUser();
732+
FakeAccess::$idSitesCapabilities = array(UseCustomTemplates::ID => array());
733+
$this->api->resumeContainerTag($this->idSite, $this->idContainer, $this->idContainerDraftVersion, $idTag);
734+
}
735+
643736
public function test_addContainerTagsWithoutStatusShouldReturnActiveWhenNotSet()
644737
{
645738
$idContainer = $this->api->createDefaultContainerForSite($this->idSite);

tests/UI/ContainerTag_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,21 @@ describe("ContainerTag", function () {
175175

176176
it('should be able to view a customHTML tag but without edit button', async function () {
177177
permissions.setWriteUser();
178+
permissions.setCapabilities({"tagmanager_use_custom_templates": []});
178179
await page.goto(container1Base + '#?idTag=1');
179180
await page.waitForNetworkIdle();
180181
await page.waitForTimeout(750);
181182
await capture.page(page, 'custom_html_tag_write_user_not_editable');
182183
});
183184

185+
it('should hide pause and delete actions for custom template tags without capability', async function () {
186+
permissions.setWriteUser();
187+
permissions.setCapabilities({"tagmanager_use_custom_templates": []});
188+
await page.goto(container1Base);
189+
await page.waitForTimeout(250);
190+
await capture.page(page, 'custom_template_tag_actions_hidden');
191+
});
192+
184193
it('should be able to view a customHTML tag but without edit button after edit', async function () {
185194
await setTagName('tagNameNew after write user edit');
186195
await capture.page(page, 'custom_html_tag_write_user_not_editable_after_edit');

tests/UI/ContainerVariable_spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ describe("ContainerVariable", function () {
156156
await capture.page(page, 'custom_js_variable_write_user_not_editable');
157157
});
158158

159+
it('should be able to view a variable list with delete action not visible for custom JS', async function () {
160+
permissions.setWriteUser();
161+
await page.goto(container1Base);
162+
await page.waitForNetworkIdle();
163+
await capture.page(page, 'custom_js_variable_list_delete_ction_hidden_when_no_access');
164+
});
165+
159166
it('should be able to view a customJS variable but without edit button after edit', async function () {
160167
await setVariableName('CustomJSVariable after write user edit');
161168
await capture.page(page, 'custom_js_variable_write_user_not_editable_after_edit');

0 commit comments

Comments
 (0)