1
|
|
|
<?php |
2
|
|
|
namespace ST\Tests; |
3
|
|
|
|
4
|
|
|
use MediaWiki\Diff\ComplexityException; |
5
|
|
|
use MWException; |
6
|
|
|
use ST\Assignees; |
7
|
|
|
use ST\SemanticTasksMailer; |
8
|
|
|
use ST\UserMailer; |
9
|
|
|
use TextContent; |
10
|
|
|
use Title; |
11
|
|
|
use User; |
12
|
|
|
use WikiPage; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers SemanticTasksMailer |
16
|
|
|
* @group semantic-tasks |
17
|
|
|
* |
18
|
|
|
* @license GNU GPL v2+ |
19
|
|
|
* @since 3.0 |
20
|
|
|
*/ |
21
|
|
|
class SemanticTasksMailerTest extends \MediaWikiTestCase { |
22
|
|
|
|
23
|
|
|
/** @todo: expand tests */ |
24
|
|
|
/** |
25
|
|
|
* @covers SemanticTasksMailer::mailNotification |
26
|
|
|
* @throws ComplexityException |
27
|
|
|
* @throws MWException |
28
|
|
|
*/ |
29
|
|
|
public function testMailNotification() { |
30
|
|
|
$userMailerMock = $this->createMock( UserMailer::class ); |
31
|
|
|
|
32
|
|
|
$assignees = [ 'someone' ]; |
33
|
|
|
$text = ''; |
34
|
|
|
$title = new Title(); |
35
|
|
|
$user = new \User(); |
36
|
|
|
$status = 0; //ST_NEWTASK |
37
|
|
|
|
38
|
|
|
$userMailerMock->expects( $this->once() ) |
39
|
|
|
->method( 'send' ) |
40
|
|
|
->with( $assignees, $this->anything(), $this->anything(), $this->anything(), $this->anything() ) |
41
|
|
|
->willReturn( \Status::newGood() ); |
42
|
|
|
|
43
|
|
|
SemanticTasksMailer::setUserMailer( $userMailerMock ); |
44
|
|
|
SemanticTasksMailer::mailNotification( $assignees, $text, $title, $user, $status ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @covers SemanticTasksMailer::generateDiffBodyTxt |
49
|
|
|
* @throws ComplexityException |
50
|
|
|
* @throws MWException |
51
|
|
|
*/ |
52
|
|
|
public function testGenerateDiffBodyTxt() { |
53
|
|
|
$namespace = $this->getDefaultWikitextNS(); |
54
|
|
|
$title = Title::newFromText( 'Kitten', $namespace ); |
55
|
|
|
|
56
|
|
|
$context = new \RequestContext(); |
57
|
|
|
$context->setTitle( $title ); |
58
|
|
|
|
59
|
|
|
$page = WikiPage::factory( $title ); |
60
|
|
|
$strings = [ "it is a kitten", "two kittens", "three kittens", "four kittens" ]; |
61
|
|
|
$revisions = []; |
62
|
|
|
foreach ( $strings as $string ) { |
63
|
|
|
$content = \ContentHandler::makeContent( $string, $title ); |
64
|
|
|
$page->doEditContent( $content, 'edit page' ); |
65
|
|
|
$revisions[] = $page->getLatest(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$returnText = SemanticTasksMailer::generateDiffBodyTxt( $title, $context ); |
69
|
|
|
$this->assertNotEquals( '', $returnText, 'Diff should not be empty string.' ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @covers Assignees::saveAssignees |
74
|
|
|
*/ |
75
|
|
|
public function testSaveAssignees() { |
76
|
|
|
$title = new Title(); |
77
|
|
|
$article = new WikiPage( $title ); |
78
|
|
|
$assignees = new Assignees(); |
79
|
|
|
$assignees->saveAssignees( $article ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** @todo: add more tests or asserts */ |
83
|
|
|
/** |
84
|
|
|
* @covers SemanticTasksMailer::mailAssigneesUpdatedTask |
85
|
|
|
* @throws MWException |
86
|
|
|
*/ |
87
|
|
|
public function testMailAssigneesUpdatedTaskTrueOnMinorEdit() { |
88
|
|
|
$assignees = new Assignees(); |
89
|
|
|
$title = new Title(); |
90
|
|
|
$article = new WikiPage($title); |
91
|
|
|
$current_user = new User(); |
92
|
|
|
$text = new TextContent('test TextContent'); |
93
|
|
|
$summary = ''; // unused |
94
|
|
|
$minoredit = true; // or true; |
95
|
|
|
$watchthis = null; // unused |
96
|
|
|
$sectionanchor = null; // unused |
97
|
|
|
$flags = EDIT_NEW; // or other.. |
98
|
|
|
try { |
99
|
|
|
$returnValue = SemanticTasksMailer::mailAssigneesUpdatedTask( $assignees, $article, $current_user, $text, |
100
|
|
|
$summary, $minoredit, $watchthis, $sectionanchor, $flags ); |
101
|
|
|
} catch ( MWException $e ) { |
|
|
|
|
102
|
|
|
|
103
|
|
|
} catch ( ComplexityException $e ) { |
|
|
|
|
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$this->assertTrue($returnValue); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** @todo: fix covers annotation and remove this. */ |
111
|
|
|
public function testValidCovers() { |
112
|
|
|
$this->assertTrue( true ); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|