Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
EditCardWidget
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 getImageContent
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getTextContent
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\HomepageModules\SuggestedEditsComponents;
4
5use GrowthExperiments\NewcomerTasks\Task\Task;
6use OOUI\Tag;
7use OOUI\Widget;
8
9class EditCardWidget extends Widget {
10
11    /** @var Task */
12    private $task;
13
14    /** @var string */
15    private $dir;
16
17    /**
18     * @param array $config Configuration options
19     *   - Task $config['task'] Task to show
20     *   - string $config['dir'] Text direction ('ltr' or 'rtl')
21     *   - any option understood by Widget
22     */
23    public function __construct( array $config = [] ) {
24        $this->task = $config['task'];
25        $this->dir = $config['dir'];
26        parent::__construct( array_merge(
27            $config,
28            [ 'classes' => [ 'suggested-edits-task-card-wrapper' ] ]
29        ) );
30
31        $this->appendContent(
32            // We should be able to construct the same URL used on the client-side
33            // here. But we may not want to, in order to allow for event logging code to
34            // load on the client, so leaving this as is for now.
35            ( new Tag( 'a' ) )->setAttributes( [ 'href' => '#' ] )
36            ->addClasses( [ 'se-card-content' ] )
37            ->appendContent(
38                $this->getImageContent(),
39                $this->getTextContent()
40            )
41        );
42    }
43
44    /** @return Tag */
45    private function getImageContent(): Tag {
46        return ( new Tag( 'div' ) )->addClasses( [ 'se-card-image', 'no-image', 'skeleton',
47            'mw-ge-tasktype-' . $this->task->getTaskType()->getId() ] );
48    }
49
50    /** @return Tag */
51    private function getTextContent(): Tag {
52        return ( new Tag( 'div' ) )
53            ->addClasses( [ 'se-card-text' ] )
54            ->setAttributes( [ 'dir' => $this->dir ] )
55            ->appendContent(
56                ( new Tag( 'h3' ) )
57                    ->addClasses( [ 'se-card-title' ] )
58                ->appendContent( $this->task->getTitle()->getText() ),
59                ( new Tag( 'div' ) )
60                ->addClasses( [ 'se-card-extract skeleton' ] )
61            )->appendContent(
62                ( new Tag( 'div' ) )->addClasses( [ 'se-card-pageviews skeleton' ] )
63            );
64    }
65
66}