Skip to content

Commit 1802d15

Browse files
authored
Add UI tests [no_release] (#48)
* Add UI tests * fix UI test * Use real spec * split test cases * attempting to fix styling * fix font * Another attempt at fixing font * revert font changes * Fix screenshots * update .gitignore
1 parent cf1e332 commit 1802d15

13 files changed

Lines changed: 1280 additions & 36 deletions

.github/workflows/matomo-tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,25 @@ jobs:
5656
redis-service: true
5757
artifacts-pass: ${{ secrets.ARTIFACTS_PASS }}
5858
upload-artifacts: ${{ matrix.php == '7.4' && matrix.target == 'maximum_supported_matomo' }}
59+
artifacts-protected: true
60+
github-token: ${{ secrets.TESTS_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
61+
UI:
62+
runs-on: ubuntu-24.04
63+
steps:
64+
- uses: actions/checkout@v3
65+
with:
66+
lfs: true
67+
persist-credentials: false
68+
- name: running tests
69+
uses: matomo-org/github-action-tests@main
70+
with:
71+
plugin-name: 'ApiReference'
72+
matomo-test-branch: 'maximum_supported_matomo'
73+
test-type: 'UI'
74+
php-version: 'matomo5_max_php'
75+
node-version: '16'
76+
redis-service: true
77+
artifacts-pass: ${{ secrets.ARTIFACTS_PASS }}
78+
upload-artifacts: true
79+
artifacts-protected: true
80+
github-token: ${{ secrets.TESTS_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ vendor/**/phpunit.xml*
99
vendor/**/phpcs.xml*
1010
vendor/**/composer.json
1111
vendor/**/composer.lock
12+
/tests/UI/processed-ui-screenshots/
1213
/vue/dist/demo.html
1314
/vue/dist/*.common.js
1415
/vue/dist/*.map
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/**
4+
* Matomo - free/libre analytics platform
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Piwik\Plugins\ApiReference\tests\Fixtures;
13+
14+
use Piwik\Plugins\ApiReference\ApiReference;
15+
use Piwik\Plugins\ApiReference\Specs\PathResolver;
16+
use Piwik\Tests\Framework\Fixture;
17+
use Piwik\Updater;
18+
19+
class SwaggerPageFixture extends Fixture
20+
{
21+
public $dateTime = '2010-01-03 00:00:00';
22+
public $idSite = 1;
23+
private bool $hadOriginalSpecFixture = false;
24+
private ?string $originalSpecFixtureContents = null;
25+
26+
public function setUp(): void
27+
{
28+
$this->setUpWebsite();
29+
$this->markApiReferenceAsInstalled();
30+
$this->writeOpenApiSpecFixtures();
31+
}
32+
33+
public function tearDown(): void
34+
{
35+
$this->removeOpenApiSpecFixtures();
36+
}
37+
38+
private function setUpWebsite(): void
39+
{
40+
if (!self::siteCreated($this->idSite)) {
41+
$idSite = self::createWebsite($this->dateTime);
42+
$this->assertSame($this->idSite, $idSite);
43+
}
44+
}
45+
46+
private function writeOpenApiSpecFixtures(): void
47+
{
48+
$resolver = new PathResolver();
49+
$specDirectory = $resolver->getSpecDirectory();
50+
$specPath = $this->getBandwidthSpecPath();
51+
52+
if (!is_dir($specDirectory)) {
53+
mkdir($specDirectory, 0777, true);
54+
}
55+
56+
if (is_file($specPath)) {
57+
$this->hadOriginalSpecFixture = true;
58+
$originalContents = file_get_contents($specPath);
59+
$this->originalSpecFixtureContents = $originalContents === false ? null : $originalContents;
60+
}
61+
62+
copy($this->getBandwidthSpecFixturePath(), $specPath);
63+
}
64+
65+
private function markApiReferenceAsInstalled(): void
66+
{
67+
(new Updater())->markComponentSuccessfullyUpdated('ApiReference', '5.0.0');
68+
}
69+
70+
private function removeOpenApiSpecFixtures(): void
71+
{
72+
$specPath = $this->getBandwidthSpecPath();
73+
74+
if ($this->hadOriginalSpecFixture) {
75+
file_put_contents($specPath, $this->originalSpecFixtureContents ?? '');
76+
} elseif (is_file($specPath)) {
77+
unlink($specPath);
78+
}
79+
}
80+
81+
private function getBandwidthSpecPath(): string
82+
{
83+
return (new PathResolver())->getSpecFilePath('Bandwidth', ApiReference::DEFAULT_SPEC_VERSION);
84+
}
85+
86+
private function getBandwidthSpecFixturePath(): string
87+
{
88+
return __DIR__ . '/../Resources/SwaggerPage/Bandwidth_openapi_spec_v1.0.0.json';
89+
}
90+
}

0 commit comments

Comments
 (0)