|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\DonatingContext\Tests\Unit\UseCases\AddComment; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddComment\AddCommentRequest; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddComment\AddCommentValidator; |
|
9
|
|
|
|
|
10
|
|
|
class AddCommentValidatorTest extends \PHPUnit_Framework_TestCase { |
|
11
|
|
|
|
|
12
|
|
|
private function newValidAddCommentRequest(): AddCommentRequest { |
|
13
|
|
|
$request = new AddCommentRequest(); |
|
14
|
|
|
$request->setAuthorDisplayName( 'Gandalf the Grey' ); |
|
15
|
|
|
$request->setCommentText( 'In the common tongue it reads "One Wiki to Rule Them All. One Wiki to Find Them. ' . |
|
16
|
|
|
'One Wiki to Bring Them All and In The Darkness Bind Them." ' ); |
|
17
|
|
|
$request->setIsPublic( true ); |
|
18
|
|
|
$request->setDonationId( 1 ); |
|
19
|
|
|
return $request; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testValidCommentRequest_isSuccessful() { |
|
23
|
|
|
$validator = new AddCommentValidator(); |
|
24
|
|
|
$this->assertTrue( $validator->validate( $this->newValidAddCommentRequest() )->isSuccessful() ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testLongComment_isNotSuccessful() { |
|
28
|
|
|
$validator = new AddCommentValidator(); |
|
29
|
|
|
$request = $this->newValidAddCommentRequest(); |
|
30
|
|
|
$request->setCommentText( str_repeat( 'All work and no play makes jack a dull boy.', 1000 ) ); |
|
31
|
|
|
$this->assertFalse( $validator->validate( $request )->isSuccessful() ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testLongName_isNotSuccessful() { |
|
35
|
|
|
$validator = new AddCommentValidator(); |
|
36
|
|
|
$request = $this->newValidAddCommentRequest(); |
|
37
|
|
|
$request->setAuthorDisplayName( str_repeat( 'Dr. ', 50 ) . $request->getAuthorDisplayName() ); |
|
38
|
|
|
$this->assertFalse( $validator->validate( $request )->isSuccessful() ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|