SemanticMediaWiki /
SemanticTasks
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
Loading history...
|
|||
| 103 | |||
| 104 | } catch ( ComplexityException $e ) { |
||
| 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 |