|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) Andreas Heigl<[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
6
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
7
|
|
|
* in the Software without restriction, including without limitation the rights |
|
8
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
10
|
|
|
* furnished to do so, subject to the following conditions: |
|
11
|
|
|
* |
|
12
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
13
|
|
|
* all copies or substantial portions of the Software. |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
21
|
|
|
* THE SOFTWARE. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Andreas Heigl<[email protected]> |
|
24
|
|
|
* @copyright Andreas Heigl |
|
25
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT-License |
|
26
|
|
|
* @since 20.02.2017 |
|
27
|
|
|
* @link http://github.com/heiglandreas/org.heigl.Mailproxy |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
namespace Org_Heigl\MailproxyTest\Controller; |
|
31
|
|
|
|
|
32
|
|
|
use Org_Heigl\Mailproxy\Controller\ProxyController; |
|
33
|
|
|
use Mockery as M; |
|
34
|
|
|
use PHPUnit\Framework\TestCase; |
|
35
|
|
|
use Zend\Http\Response; |
|
36
|
|
|
use Zend\Mvc\MvcEvent; |
|
37
|
|
|
use Zend\Router\Http\RouteMatch; |
|
38
|
|
|
use Zend\Stdlib\ResponseInterface; |
|
39
|
|
|
use Zend\View\Model\ViewModel; |
|
40
|
|
|
|
|
41
|
|
|
class ProxyControllerTest extends TestCase |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* @dataProvider ResolutionProvider |
|
45
|
|
|
* @covers \Org_Heigl\Mailproxy\Controller\ProxyController |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testResolution($input, $redirect, $parameters = null) |
|
48
|
|
|
{ |
|
49
|
|
|
$controller = new ProxyController(); |
|
50
|
|
|
|
|
51
|
|
|
$params = [ |
|
52
|
|
|
'id' => $input, |
|
53
|
|
|
'controller' => '', |
|
54
|
|
|
'action' => '', |
|
55
|
|
|
]; |
|
56
|
|
|
if (is_array($parameters)) { |
|
57
|
|
|
$params = array_merge($params, $parameters); |
|
58
|
|
|
} |
|
59
|
|
|
$routeMatch = M::mock(RouteMatch::class); |
|
60
|
|
|
$routeMatch->shouldReceive('getParams')->andReturn($params); |
|
61
|
|
|
|
|
62
|
|
|
$response = new Response(); |
|
63
|
|
|
|
|
64
|
|
|
$event = M::mock(MvcEvent::class); |
|
65
|
|
|
$event->shouldReceive('getRouteMatch')->andReturn($routeMatch); |
|
66
|
|
|
$event->shouldReceive('getResponse')->andReturn($response); |
|
67
|
|
|
|
|
68
|
|
|
$controller->setEvent($event); |
|
69
|
|
|
|
|
70
|
|
|
$model = $controller->indexAction(); |
|
71
|
|
|
$this->assertInstanceOf(ViewModel::class, $model); |
|
72
|
|
|
$this->assertTrue($model->terminate()); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals(['Location' => $redirect], $response->getHeaders()->toArray()); |
|
75
|
|
|
$this->assertEquals('302', $response->getStatusCode()); |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function resolutionProvider() |
|
81
|
|
|
{ |
|
82
|
|
|
return [ |
|
83
|
|
|
['moc.elpmaxe@ofni', 'mailto:[email protected]'], |
|
84
|
|
|
['moc.elpmaxe@ofni', 'mailto:[email protected]?subject=test', ['subject' => 'test']], |
|
85
|
|
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|