Skip to content

Commit 3f7482c

Browse files
committed
update parser tests for 1.43 and 1.44
- add `make parser-mw143` target for testing 1.43 - add REL1_44 to matrixes for static analysis and code style - add comment that a shared MW Core cache is ok for static analysis and code style tests. - use `continue-one-error: true` for intentional non-blocking steps - add README.md for describing the tests
1 parent 80bfb0b commit 3f7482c

4 files changed

Lines changed: 146 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ jobs:
8888
run: php maintenance/update.php --quick
8989

9090
- name: Run PHPUnit (junit)
91-
run: php tests/phpunit/phpunit.php -c extensions/ExternalContent/ --log-junit tests/junit.xml || true
91+
continue-on-error: true
92+
run: php tests/phpunit/phpunit.php -c extensions/ExternalContent/ --log-junit tests/junit.xml
9293

9394
- name: Upload PHPUnit JUnit result
9495
uses: actions/upload-artifact@v4
@@ -102,10 +103,10 @@ jobs:
102103

103104
- name: Upload code coverage (master only) securely
104105
if: matrix.mw == 'master'
106+
continue-on-error: true
105107
uses: codecov/codecov-action@v4
106108
with:
107109
files: coverage.xml
108-
fail_ci_if_error: false
109110

110111
- name: Upload coverage artifact (master only)
111112
if: matrix.mw == 'master'
@@ -115,8 +116,13 @@ jobs:
115116
path: coverage.xml
116117

117118
- name: Run parser tests (explicit targets)
118-
if: matrix.mw == 'REL1_43' || matrix.mw == 'master'
119-
run: php tests/parser/parserTests.php --file=extensions/ExternalContent/tests/parser/parserTests.txt
119+
if: matrix.mw >= 'REL1_43' || matrix.mw == 'master'
120+
run: |
121+
if [[ "${{ matrix.mw }}" == "REL1_43" ]]; then
122+
php tests/parser/parserTests.php --file=extensions/ExternalContent/tests/parser/parserTests-mw143.txt
123+
else
124+
php tests/parser/parserTests.php --file=extensions/ExternalContent/tests/parser/parserTests.txt
125+
fi
120126
121127
static-analysis:
122128
name: "Static Analysis: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
@@ -126,6 +132,8 @@ jobs:
126132
include:
127133
- mw: 'REL1_43'
128134
php: '8.3'
135+
- mw: 'REL1_44'
136+
php: '8.4'
129137

130138
runs-on: ubuntu-latest
131139

@@ -149,6 +157,8 @@ jobs:
149157
mediawiki
150158
!mediawiki/extensions/
151159
!mediawiki/vendor/
160+
# Shared cache key across static-analysis and code-style jobs
161+
# Safe to share because both jobs use the same MW core code
152162
key: mw_static_analysis
153163
restore-keys: |
154164
mw_static_analysis
@@ -196,6 +206,8 @@ jobs:
196206
include:
197207
- mw: 'REL1_43'
198208
php: '8.3'
209+
- mw: 'REL1_44'
210+
php: '8.4'
199211

200212
runs-on: ubuntu-latest
201213

@@ -219,6 +231,8 @@ jobs:
219231
mediawiki
220232
!mediawiki/extensions/
221233
!mediawiki/vendor/
234+
# Shared cache key across static-analysis and code-style jobs
235+
# Safe to share because both jobs use the same MW core code
222236
key: mw_static_analysis
223237
restore-keys: |
224238
mw_static_analysis

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ psalm:
1818

1919
parser:
2020
php ../../tests/parser/parserTests.php --file=tests/parser/parserTests.txt
21+
22+
parser-mw143:
23+
php ../../tests/parser/parserTests.php --file=tests/parser/parserTests-mw143.txt

tests/parser/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Parser Tests
2+
3+
This directory contains parser tests for the ExternalContent extension.
4+
5+
## Version Compatibility
6+
7+
Due to changes in MediaWiki's Codex message box implementation between versions, the HTML output differs slightly:
8+
9+
- **MediaWiki 1.43**: `<div class="cdx-message cdx-message--block cdx-message--error">`
10+
- **MediaWiki 1.44+**: `<div class="cdx-message--error cdx-message cdx-message--block">`
11+
12+
The difference is only in CSS class ordering, which does not affect functionality or visual appearance.
13+
14+
## Test Files
15+
16+
- `parserTests.txt` - Tests for MediaWiki 1.44 and later (current format)
17+
- `parserTests-mw143.txt` - Tests for MediaWiki 1.43 (legacy format)
18+
19+
## Running Tests
20+
21+
### Using Make (recommended)
22+
23+
For MediaWiki 1.44+:
24+
```bash
25+
make parser
26+
```
27+
28+
For MediaWiki 1.43:
29+
```bash
30+
make parser-mw143
31+
```
32+
33+
### Direct PHP execution
34+
35+
For MediaWiki 1.44+:
36+
```bash
37+
php ../../tests/parser/parserTests.php --file=tests/parser/parserTests.txt
38+
```
39+
40+
For MediaWiki 1.43:
41+
```bash
42+
php ../../tests/parser/parserTests.php --file=tests/parser/parserTests-mw143.txt
43+
```
44+
45+
## CI/CD Configuration
46+
47+
Update your GitHub Actions or CI configuration to run the appropriate test file based on the MediaWiki version:
48+
49+
```yaml
50+
- name: Run parser tests
51+
run: |
52+
if [[ "${{ matrix.mw }}" == "REL1_43" ]]; then
53+
php tests/parser/parserTests.php --file=extensions/ExternalContent/tests/parser/parserTests-mw143.txt
54+
else
55+
php tests/parser/parserTests.php --file=extensions/ExternalContent/tests/parser/parserTests.txt
56+
fi
57+
```
58+
59+
## Alternative Approach
60+
61+
If you prefer to maintain only one test file, you can use less strict assertions in your PHPUnit integration tests. See `tests/Unit/Adapters/ParserFunctionEmbedPresenterTest.php` for an example that uses `logicalOr` to accept multiple possible outputs:
62+
63+
```php
64+
$this->assertThat(
65+
$parserFunctionReturnValue[0],
66+
$this->logicalOr(
67+
$this->stringContains( '<div class="errorbox">' ),
68+
$this->stringContains( 'mw-message-box-error' ),
69+
$this->stringContains( 'cdx-message--error' )
70+
)
71+
);
72+
```

tests/parser/parserTests-mw143.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
!! Version 2
2+
3+
!! test
4+
Embed function should not render when it is disabled
5+
!! config
6+
wgExternalContentEnableEmbedFunction=false
7+
!! wikitext
8+
{{#embed:raw.githubusercontent.com/ProfessionalWiki/ExternalContent/master/README.md}}
9+
!! html
10+
<p>{{#embed:raw.githubusercontent.com/ProfessionalWiki/ExternalContent/master/README.md}}
11+
</p>
12+
!! end
13+
14+
!! test
15+
Bitbucket function should not render when it is disabled
16+
!! config
17+
wgExternalContentEnableBitbucketFunction=false
18+
!! wikitext
19+
{{#bitbucket:raw.githubusercontent.com/ProfessionalWiki/ExternalContent/master/README.md}}
20+
!! html
21+
<p>{{#bitbucket:raw.githubusercontent.com/ProfessionalWiki/ExternalContent/master/README.md}}
22+
</p>
23+
!! end
24+
25+
!! test
26+
Embed function should display not found for non-existing files
27+
!! config
28+
wgLanguageCode="en"
29+
!! wikitext
30+
{{#embed:https://localhost/this-does-not-exist.md}}
31+
!! html
32+
<div class="cdx-message cdx-message--block cdx-message--error"><span class="cdx-message__icon"></span><div class="cdx-message__content">Could not retrieve file</div></div>
33+
!! end
34+
35+
!! test
36+
Bitbucket function should show invalid URL error
37+
!! config
38+
wgLanguageCode="en"
39+
!! wikitext
40+
{{#bitbucket:https://localhost/not-a-valid-bitbucket-url.md}}
41+
!! html
42+
<div class="cdx-message cdx-message--block cdx-message--error"><span class="cdx-message__icon"></span><div class="cdx-message__content">Not a valid Bitbucket URL</div></div>
43+
!! end
44+
45+
!! test
46+
Files with extensions not in the whitelist should be rejected
47+
!! config
48+
wgExternalContentFileExtensionWhitelist=["md"]
49+
!! wikitext
50+
{{#embed:https://localhost/whatever.hax}}
51+
!! html
52+
<div class="cdx-message cdx-message--block cdx-message--error"><span class="cdx-message__icon"></span><div class="cdx-message__content">Embedding files with this extension is not allowed</div></div>
53+
!! end

0 commit comments

Comments
 (0)