|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SES\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SES\RedirectFormFinder; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @covers \SES\RedirectFormFinder |
|
9
|
|
|
* |
|
10
|
|
|
* @group semantic-signup |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU GPL v2+ |
|
13
|
|
|
* @since 1.0 |
|
14
|
|
|
* |
|
15
|
|
|
* @author mwjames |
|
16
|
|
|
*/ |
|
17
|
|
|
class RedirectFormFinderTest extends \PHPUnit_Framework_TestCase { |
|
18
|
|
|
|
|
19
|
|
|
public function testCanConstruct() { |
|
20
|
|
|
|
|
21
|
|
|
$formPrinterHandler = $this->getMockBuilder( '\SES\FormPrinterHandler' ) |
|
22
|
|
|
->disableOriginalConstructor() |
|
23
|
|
|
->getMock(); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertInstanceOf( |
|
26
|
|
|
'\SES\RedirectFormFinder', |
|
27
|
|
|
new RedirectFormFinder( $formPrinterHandler ) |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testRedirectToUrlForInvalidForm() { |
|
32
|
|
|
|
|
33
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
|
34
|
|
|
->disableOriginalConstructor() |
|
35
|
|
|
->getMock(); |
|
36
|
|
|
|
|
37
|
|
|
$outputPage->expects( $this->never() ) |
|
38
|
|
|
->method( 'redirect' ); |
|
39
|
|
|
|
|
40
|
|
|
$formPrinterHandler = $this->getMockBuilder( '\SES\FormPrinterHandler' ) |
|
41
|
|
|
->disableOriginalConstructor() |
|
42
|
|
|
->getMock(); |
|
43
|
|
|
|
|
44
|
|
|
$formPrinterHandler->expects( $this->once() ) |
|
45
|
|
|
->method( 'canUseForm' ) |
|
46
|
|
|
->will( $this->returnValue( false ) ); |
|
47
|
|
|
|
|
48
|
|
|
$instance = new RedirectFormFinder( $formPrinterHandler ); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertTrue( |
|
51
|
|
|
$instance->redirectToUrl( $outputPage ) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testRedirectToUrlForValidForm() { |
|
56
|
|
|
|
|
57
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
|
58
|
|
|
->disableOriginalConstructor() |
|
59
|
|
|
->getMock(); |
|
60
|
|
|
|
|
61
|
|
|
$outputPage->expects( $this->once() ) |
|
62
|
|
|
->method( 'redirect' ); |
|
63
|
|
|
|
|
64
|
|
|
$formHandler = $this->getMockBuilder( '\SES\FormPrinterHandler' ) |
|
65
|
|
|
->disableOriginalConstructor() |
|
66
|
|
|
->getMock(); |
|
67
|
|
|
|
|
68
|
|
|
$formHandler->expects( $this->once() ) |
|
69
|
|
|
->method( 'canUseForm' ) |
|
70
|
|
|
->will( $this->returnValue( true ) ); |
|
71
|
|
|
|
|
72
|
|
|
$instance = new RedirectFormFinder( $formHandler ); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertFalse( |
|
75
|
|
|
$instance->redirectToUrl( $outputPage ) |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|