Download plugins/CustomJsTracker/tests/Integration/PluginTrackerFilesTest.php from Leon4gr45/matomo: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/spaces/Leon4gr45/matomo/resolve/main/plugins/CustomJsTracker/tests/Integration/PluginTrackerFilesTest.php
- Command line
-
hf download hf://spaces/Leon4gr45/matomo/plugins/CustomJsTracker/tests/Integration/PluginTrackerFilesTest.php
-
curl -L -o PluginTrackerFilesTest.php https://huggingface.co/spaces/Leon4gr45/matomo/resolve/main/plugins/CustomJsTracker/tests/Integration/PluginTrackerFilesTest.php
2.43 kB
| /** | |
| * Matomo - free/libre analytics platform | |
| * | |
| * @link https://matomo.org | |
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | |
| */ | |
| namespace Piwik\Plugins\CustomJsTracker\tests\Integration; | |
| use PHPUnit\Framework\MockObject\MockObject; | |
| use Piwik\Piwik; | |
| use Piwik\Plugins\CustomJsTracker\TrackingCode\PluginTrackerFiles; | |
| use Piwik\Tests\Framework\TestCase\IntegrationTestCase; | |
| /** | |
| * @group CustomJsTracker | |
| * @group PluginTrackerFilesTest | |
| * @group PluginTrackerFiles | |
| * @group Plugins | |
| */ | |
| class PluginTrackerFilesTest extends IntegrationTestCase | |
| { | |
| public function testFindIfAPluginDefinesAMinifiedAndARegularTrackerItShouldPreferTheMinifiedVersion() | |
| { | |
| $trackerFiles = $this->getMockedTrackerFiles(); | |
| $foundFiles = $trackerFiles->find(); | |
| $this->assertCount(1, $foundFiles); | |
| $this->assertTrue(isset($foundFiles['CustomJsTracker'])); | |
| $this->assertEquals('tracker.min.js', $foundFiles['CustomJsTracker']->getName()); | |
| } | |
| public function testFindShouldIgnoreMinifiedVersionIfRequested() | |
| { | |
| $trackerFiles = $this->getMockedTrackerFiles(); | |
| $trackerFiles->ignoreMinified(); | |
| $foundFiles = $trackerFiles->find(); | |
| $this->assertCount(1, $foundFiles); | |
| $this->assertTrue(isset($foundFiles['CustomJsTracker'])); | |
| $this->assertEquals('tracker.js', $foundFiles['CustomJsTracker']->getName()); | |
| } | |
| public function testFindEventsCanIgnoreFiles() | |
| { | |
| $trackerFiles = $this->getMockedTrackerFiles(); | |
| $foundFiles = $trackerFiles->find(); | |
| $this->assertCount(1, $foundFiles); | |
| Piwik::addAction('CustomJsTracker.shouldAddTrackerFile', function (&$shouldAdd, $pluginName) { | |
| if ($pluginName === 'CustomJsTracker') { | |
| $shouldAdd = false; | |
| } | |
| }); | |
| $foundFiles = $trackerFiles->find(); | |
| $this->assertCount(0, $foundFiles); | |
| } | |
| /** | |
| * @return PluginTrackerFiles|MockObject | |
| */ | |
| private function getMockedTrackerFiles(): MockObject | |
| { | |
| $mock = self::getMockBuilder(PluginTrackerFiles::class)->onlyMethods(['getDirectoriesToLook']); | |
| $trackerFiles = $mock->getMock(); | |
| $trackerFiles->method('getDirectoriesToLook')->willReturn([ | |
| 'CustomJsTracker' => PIWIK_DOCUMENT_ROOT . '/plugins/CustomJsTracker/tests/resources/', | |
| ]); | |
| return $trackerFiles; | |
| } | |
| } | |