Completed
Push — master ( 62a5ef...24c5f5 )
by Peter
14s queued 12s
created

SemanticTasksMailerTest::overrideMwServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 2
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
	/**
24
	 * Only needed for MW 1.31
25
	 */
26
	public function run( \PHPUnit_Framework_TestResult $result = null ) {
27
		// MW 1.31
28
		$this->setCliArg( 'use-normal-tables', true );
29
		parent::run( $result );
30
	}
31
32
	protected function overrideMwServices( $configOverrides = null, array $services = [] ) {
33
		/**
34
		 * `MediaWikiTestCase` isolates the result with  `MediaWikiTestResult` which
35
		 * ecapsultes the commandline args and since we need to use "real" tables
36
		 * as part of "use-normal-tables" we otherwise end-up with the `CloneDatabase`
37
		 * to create TEMPORARY  TABLE by default as in:
38
		 *
39
		 * CREATE TEMPORARY  TABLE `unittest_smw_di_blob` (LIKE `smw_di_blob`) and
40
		 * because of the TEMPORARY TABLE, MySQL (not MariaDB) will complain
41
		 * about things like:
42
		 *
43
		 * SELECT p.smw_title AS prop, o_id AS id0, o0.smw_title AS v0, o0.smw_namespace
44
		 * AS v1, o0.smw_iw AS v2, o0.smw_sortkey AS v3, o0.smw_subobject AS v4,
45
		 * o0.smw_sort AS v5 FROM `unittest_smw_di_wikipage` INNER JOIN
46
		 * `unittest_smw_object_ids` AS p ON p_id=p.smw_id INNER JOIN
47
		 * `unittest_smw_object_ids` AS o0 ON o_id=o0.smw_id WHERE (s_id='29') AND
48
		 * (p.smw_iw!=':smw') AND (p.smw_iw!=':smw-delete')
49
		 *
50
		 * Function: SMW\SQLStore\EntityStore\SemanticDataLookup::fetchSemanticDataFromTable
51
		 * Error: 1137 Can't reopen table: 'p' ()
52
		 *
53
		 * The reason is that `unittest_smw_object_ids` was created as TEMPORARY TABLE
54
		 * and p is referencing to a TEMPORARY TABLE as well which isn't allowed in
55
		 * MySQL.
56
		 *
57
		 * "You cannot refer to a TEMPORARY table more than once in the same query" [0]
58
		 *
59
		 * [0] https://dev.mysql.com/doc/refman/8.0/en/temporary-table-problems.html
60
		 */
61
		// MW 1.32+
62
		$this->setCliArg( 'use-normal-tables', true );
63
		parent::overrideMwServices( $configOverrides, $services );
64
	}
65
66
	/** @todo: expand tests */
67
	/**
68
	 * @covers SemanticTasksMailer::mailNotification
69
	 * @throws ComplexityException
70
	 * @throws MWException
71
	 */
72
	public function testMailNotification() {
73
		$userMailerMock = $this->createMock( UserMailer::class );
74
75
		$assignees = [ 'someone' ];
76
		$text = '';
77
		$title = new Title();
78
		$user = new \User();
79
		$status = 0; //ST_NEWTASK
80
81
		$userMailerMock->expects( $this->once() )
82
			->method( 'send' )
83
			->with( $assignees, $this->anything(), $this->anything(), $this->anything(), $this->anything() )
84
			->willReturn( \Status::newGood() );
85
86
		SemanticTasksMailer::setUserMailer( $userMailerMock );
87
		SemanticTasksMailer::mailNotification( $assignees, $text, $title, $user, $status );
88
	}
89
90
	/**
91
	 * @covers SemanticTasksMailer::generateDiffBodyTxt
92
	 * @throws ComplexityException
93
	 * @throws MWException
94
	 */
95
	public function testGenerateDiffBodyTxt() {
96
		$namespace = $this->getDefaultWikitextNS();
97
		$title = Title::newFromText( 'Kitten', $namespace );
98
99
		$context = new \RequestContext();
100
		$context->setTitle( $title );
101
102
		$page = WikiPage::factory( $title );
103
		$strings = [ "it is a kitten", "two kittens", "three kittens", "four kittens" ];
104
		$revisions = [];
105
		foreach ( $strings as $string ) {
106
			$content = \ContentHandler::makeContent( $string, $title );
107
			$page->doEditContent( $content, 'edit page' );
108
			$revisions[] = $page->getLatest();
109
		}
110
111
		$returnText = SemanticTasksMailer::generateDiffBodyTxt( $title, $context );
112
		$this->assertNotEquals( '', $returnText, 'Diff should not be empty string.' );
113
	}
114
115
	/**
116
	 * @covers Assignees::saveAssignees
117
	 */
118
	public function testSaveAssignees() {
119
		$title = new Title();
120
		$article = new WikiPage( $title );
121
		$assignees = new Assignees();
122
		$assignees->saveAssignees( $article );
123
	}
124
125
	/** @todo: add more tests or asserts */
126
	/**
127
	 * @covers SemanticTasksMailer::mailAssigneesUpdatedTask
128
	 * @throws MWException
129
	 */
130
	public function testMailAssigneesUpdatedTaskTrueOnMinorEdit() {
131
		$assignees = new Assignees();
132
		$title = new Title();
133
		$article = new WikiPage($title);
134
		$current_user = new User();
135
		$text = new TextContent('test TextContent');
136
		$summary = ''; // unused
137
		$minoredit = true; // or true;
138
		$watchthis = null; // unused
139
		$sectionanchor = null; // unused
140
		$flags = EDIT_NEW; // or other..
141
		try {
142
			$returnValue = SemanticTasksMailer::mailAssigneesUpdatedTask( $assignees, $article, $current_user, $text,
143
				$summary, $minoredit, $watchthis, $sectionanchor, $flags );
144
		} 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...
145
146
		} 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...
147
148
		}
149
150
		$this->assertTrue($returnValue);
151
	}
152
153
	/** @todo: fix covers annotation and remove this. */
154
	public function testValidCovers() {
155
		$this->assertTrue( true );
156
	}
157
}
158

 

OSZAR »