Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
NavigationWidgetFactory
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
20
 getPreviousNextButtonHtml
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 getEditButton
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\HomepageModules\SuggestedEditsComponents;
4
5use GrowthExperiments\NewcomerTasks\Task\Task;
6use GrowthExperiments\NewcomerTasks\Task\TaskSet;
7use OOUI\ButtonWidget;
8use OOUI\HtmlSnippet;
9use OOUI\Tag;
10
11class NavigationWidgetFactory {
12
13    /** @var TaskSet|\StatusValue */
14    private $taskSet;
15
16    /** @var \MessageLocalizer */
17    private $messageLocalizer;
18
19    /** @var Task */
20    private $task;
21
22    /** @var \StatusValue */
23    private $error;
24
25    /**
26     * NavigationWidgetFactory constructor.
27     * Generate navigation elements for SuggestedEdits module
28     *
29     * @param \MessageLocalizer $messageLocalizer
30     * @param TaskSet|\StatusValue $taskSet
31     */
32    public function __construct(
33        \MessageLocalizer $messageLocalizer, $taskSet
34    ) {
35        $this->messageLocalizer = $messageLocalizer;
36        $this->taskSet = $taskSet;
37        $this->task = $taskSet instanceof TaskSet && $taskSet->count() ? $taskSet[0] : null;
38        $this->error = $taskSet instanceof \StatusValue ? $taskSet : null;
39    }
40
41    /**
42     * Return HTML for previous or next buttons
43     *
44     * @param string $direction Should be one of "Previous" or "Next" (case sensitive)
45     * @return Tag
46     * @throws \OOUI\Exception
47     */
48    public function getPreviousNextButtonHtml( string $direction ): Tag {
49        // The following classes are used here:
50        // * suggested-edits-previous
51        // * suggested-edits-next
52
53        // The following message keys are used here:
54        // * growthexperiments-homepage-suggestededits-previous-card
55        // * growthexperiments-homepage-suggestededits-previous-next
56        return ( new Tag( 'div' ) )->addClasses( [ 'suggested-edits-' . strtolower( $direction ) ] )
57            ->appendContent( new HtmlSnippet( ( new PreviousNext( [
58                'direction' => $direction,
59                'message' => $this->messageLocalizer->msg(
60                    'growthexperiments-homepage-suggestededits-' . strtolower( $direction ) . '-card'
61                )->text(),
62                'hidden' => !$this->task || $this->error
63            ] ) )->toString() ) );
64    }
65
66    /**
67     * Return edit button
68     *
69     * @return ButtonWidget
70     */
71    public function getEditButton(): ButtonWidget {
72        return new ButtonWidget( [
73            'icon' => 'edit',
74            'label' => $this->messageLocalizer->msg(
75                'growthexperiments-homepage-suggestededits-edit-card'
76            )->text(),
77            'flags' => [ 'primary', 'progressive' ],
78            'classes' => [ 'suggested-edits-footer-navigation-edit-button' ]
79        ] );
80    }
81}