Completed
Pull Request — master (#28)
by Peter
02:16
created

SemanticTasksMailerTest::testGenerateDiffBodyTxt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 0
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
		$revision = null;
99
		try {
100
			$returnValue = SemanticTasksMailer::mailAssigneesUpdatedTask( $assignees, $article, $current_user, $text,
101
				$summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision );
102
		} catch ( MWException $e ) {
0 ignored issues
show
Bug introduced by
The class MWException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
103
104
		} catch ( ComplexityException $e ) {
0 ignored issues
show
Bug introduced by
The class MediaWiki\Diff\ComplexityException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
105
106
		}
107
108
		$this->assertTrue($returnValue);
109
	}
110
111
	/** @todo: fix covers annotation and remove this. */
112
	public function testValidCovers() {
113
		$this->assertTrue( true );
114
	}
115
}
116