|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* MageSpec |
|
4
|
|
|
* |
|
5
|
|
|
* NOTICE OF LICENSE |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the MIT License, that is bundled with this |
|
8
|
|
|
* package in the file LICENSE. |
|
9
|
|
|
* It is also available through the world-wide-web at this URL: |
|
10
|
|
|
* |
|
11
|
|
|
* http://opensource.org/licenses/MIT |
|
12
|
|
|
* |
|
13
|
|
|
* If you did not receive a copy of the license and are unable to obtain it |
|
14
|
|
|
* through the world-wide-web, please send an email |
|
15
|
|
|
* to <[email protected]> so we can send you a copy immediately. |
|
16
|
|
|
* |
|
17
|
|
|
* @category MageTest |
|
18
|
|
|
* @package PhpSpec_MagentoExtension |
|
19
|
|
|
* @subpackage Matcher |
|
20
|
|
|
* |
|
21
|
|
|
* @copyright Copyright (c) 2012-2013 MageTest team and contributors. |
|
22
|
|
|
*/ |
|
23
|
|
|
namespace MageTest\PhpSpec\MagentoExtension\Matcher; |
|
24
|
|
|
|
|
25
|
|
|
use PhpSpec\Matcher\BasicMatcher; |
|
26
|
|
|
use PhpSpec\Exception\Example\FailureException; |
|
27
|
|
|
use PhpSpec\Formatter\Presenter\Presenter as PresenterInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* BeInArea |
|
31
|
|
|
* |
|
32
|
|
|
* @category MageTest |
|
33
|
|
|
* @package PhpSpec_MagentoExtension |
|
34
|
|
|
* @subpackage Matcher |
|
35
|
|
|
* |
|
36
|
|
|
* @author MageTest team (https://github.com/MageTest/MageSpec/contributors) |
|
37
|
|
|
*/ |
|
38
|
|
|
class BeInArea extends BasicMatcher |
|
39
|
|
|
{ |
|
40
|
|
|
private $presenter; |
|
41
|
|
|
|
|
42
|
|
|
public function __construct(PresenterInterface $presenter) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->presenter = $presenter; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function supports($alias, $subject, array $arguments) |
|
48
|
|
|
{ |
|
49
|
|
|
return $alias === 'beInArea' && |
|
50
|
|
|
$subject instanceof \Mage_Core_Controller_Front_Action && |
|
51
|
|
|
isset($arguments[0]) && |
|
52
|
|
|
in_array($arguments[0], array('admin', 'frontend')); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function matches($subject, array $arguments) |
|
56
|
|
|
{ |
|
57
|
|
|
return $subject->get('mage')->app()->getArea() === $arguments[0]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function getFailureException($name, $subject, array $arguments) |
|
61
|
|
|
{ |
|
62
|
|
|
$area = $subject->get('mage')->app()->getArea(); |
|
63
|
|
|
return new FailureException(sprintf( |
|
64
|
|
|
'Expected %s to be in area %s, got %s.', |
|
65
|
|
|
$this->presenter->presentValue($subject), |
|
66
|
|
|
$this->presenter->presentString($arguments[0]), |
|
67
|
|
|
$this->presenter->presentString($area) |
|
68
|
|
|
)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function getNegativeFailureException($name, $subject, array $arguments) |
|
72
|
|
|
{ |
|
73
|
|
|
return new FailureException(sprintf( |
|
74
|
|
|
'Expected %s not to be in area %s.', |
|
75
|
|
|
$this->presenter->presentValue($subject), |
|
76
|
|
|
$this->presenter->presentValue($arguments[0]) |
|
77
|
|
|
)); |
|
78
|
|
|
} |
|
79
|
|
|
} |