Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ImportIdentityFormSnippet
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHtml
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace FileImporter\Html;
4
5use MediaWiki\Html\Html;
6
7/**
8 * Collection of input elements that are used to persist the request from page load to page load.
9 *
10 * @license GPL-2.0-or-later
11 * @author Addshore
12 */
13class ImportIdentityFormSnippet {
14
15    private array $identityParts;
16
17    private const IDENTITY_KEYS = [
18        'clientUrl',
19        'intendedFileName',
20        'intendedRevisionSummary',
21        'intendedWikitext',
22        'actionStats',
23        'validationWarnings',
24        'importDetailsHash',
25        'automateSourceWikiCleanup',
26        'automateSourceWikiDelete'
27    ];
28
29    /**
30     * @param array $identityParts Keys:
31     *     - clientUrl, as initial input by the user
32     *     - intendedFileName, either generated from the client URL or passed by the user
33     *     - importDetailsHash, generated from the first import request, to ensure we know what
34     *                          we are importing
35     */
36    public function __construct( array $identityParts ) {
37        $this->identityParts = $identityParts;
38    }
39
40    /**
41     * @return string
42     */
43    public function getHtml() {
44        $html = '';
45
46        foreach ( self::IDENTITY_KEYS as $identityKey ) {
47            if ( array_key_exists( $identityKey, $this->identityParts ) ) {
48                $html .= Html::element(
49                    'input',
50                    [
51                        'type' => 'hidden',
52                        'name' => $identityKey,
53                        'value' => $this->identityParts[$identityKey],
54                    ]
55                );
56            }
57        }
58
59        return $html;
60    }
61
62}