Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
TipTree
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 7
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getStepNames
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTipTypes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTree
n/a
0 / 0
n/a
0 / 0
0
 getTaskTypeId
n/a
0 / 0
n/a
0 / 0
0
 getEditMessageTipConfigData
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 getPublishMessageTipConfigData
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 maybeAddLearnMoreLinkTipNode
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 getLearnMoreLink
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\HelpPanel\Tips;
4
5abstract class TipTree {
6
7    public const TIP_DATA_TYPE_PLAIN_MESSAGE = 'message';
8    public const TIP_DATA_TYPE_TEXT_VARIANT = 'text-variant';
9    public const TIP_DATA_TYPE_IMAGE = 'image';
10    public const TIP_DATA_TYPE_OOUI_ICON = 'icon';
11    public const TIP_DATA_TYPE_TITLE = 'title';
12    public const TIP_TYPE_MAIN_MULTIPLE_MAX_NODES = 3;
13
14    // The tip step names to use for constructing guidance tips in the help
15    // panel's suggested edit screen. Hard-coded for now.
16    private const TIP_STEP_NAMES = [
17        'value',
18        'calm',
19        'rules1',
20        'rules2',
21        'step1',
22        'step2',
23        'step3',
24        'publish'
25    ];
26
27    // The types of tips that can be shown for a task type. Hard-coded for now.
28    private const TIP_TYPES = [
29        'header',
30        'main',
31        'main-multiple',
32        'example',
33        'graphic',
34        'text'
35    ];
36    /**
37     * @var string|null
38     */
39    protected $learnMoreLink;
40    /**
41     * @var array
42     */
43    protected $extraData;
44
45    /**
46     * @param array $extraData
47     */
48    public function __construct( array $extraData ) {
49        $this->learnMoreLink = $extraData[$this->getTaskTypeId()]['learnMoreLink'] ?? null;
50        $this->extraData = $extraData;
51    }
52
53    /**
54     * @return string[]
55     */
56    public function getStepNames() {
57        return self::TIP_STEP_NAMES;
58    }
59
60    /**
61     * @return string[]
62     */
63    public function getTipTypes() {
64        return self::TIP_TYPES;
65    }
66
67    /**
68     * Get tip steps that will be used to build a node tree for a task type.
69     * @return array
70     */
71    abstract public function getTree(): array;
72
73    /**
74     * Get the task type ID that corresponds to this tip tree class.
75     * @return string
76     */
77    abstract protected function getTaskTypeId(): string;
78
79    /**
80     * @return array|string[]
81     */
82    protected function getEditMessageTipConfigData(): array {
83        return [
84            'type' => self::TIP_DATA_TYPE_PLAIN_MESSAGE,
85            'data' => 'vector-view-edit',
86            'variant' => [
87                'minerva' => [
88                    'data' => 'mobile-frontend-editor-edit',
89                ]
90            ]
91        ];
92    }
93
94    /**
95     * @return array|string[]
96     */
97    protected function getPublishMessageTipConfigData(): array {
98        return [
99            'type' => self::TIP_DATA_TYPE_PLAIN_MESSAGE,
100            'data' => 'publishchanges-start'
101        ];
102    }
103
104    /**
105     * @param array $steps
106     * @param string $stepName Step to which learn more link is added
107     * @param string $tipType Tip type to which learn more link is added
108     * @return array
109     */
110    protected function maybeAddLearnMoreLinkTipNode(
111        array $steps,
112        string $stepName = 'publish',
113        string $tipType = 'text'
114    ): array {
115        if ( $this->getLearnMoreLink() ) {
116            $steps[$stepName][$tipType] = [
117                [
118                    'type' => self::TIP_DATA_TYPE_TITLE,
119                    'data' => [ 'title' => $this->getLearnMoreLink() ],
120                ]
121            ];
122        }
123        return $steps;
124    }
125
126    /**
127     * @return string|null
128     */
129    protected function getLearnMoreLink() {
130        return $this->learnMoreLink;
131    }
132}