1 | <?php |
||
19 | trait CommonContextTrait |
||
20 | { |
||
21 | /** |
||
22 | * @var MinkContext |
||
23 | */ |
||
24 | protected $minkContext; |
||
25 | |||
26 | /** |
||
27 | * @var CoreContext |
||
28 | */ |
||
29 | protected $coreContext; |
||
30 | |||
31 | /** |
||
32 | * @var UserContext |
||
33 | */ |
||
34 | protected $userContext; |
||
35 | |||
36 | /** |
||
37 | * @var SummaryFormContext |
||
38 | */ |
||
39 | protected $summaryFormContext; |
||
40 | |||
41 | /** |
||
42 | * @BeforeScenario |
||
43 | * |
||
44 | * @param BeforeScenarioScope $scope |
||
45 | */ |
||
46 | final public function gatherContexts(BeforeScenarioScope $scope) |
||
47 | { |
||
48 | $this->minkContext = $scope->getEnvironment()->getContext(MinkContext::class); |
||
49 | $this->coreContext = $scope->getEnvironment()->getContext(CoreContext::class); |
||
50 | $this->userContext = $scope->getEnvironment()->getContext(UserContext::class); |
||
51 | $this->summaryFormContext = $scope->getEnvironment()->getContext(SummaryFormContext::class); |
||
52 | } |
||
53 | |||
54 | public function buildUrl($name, array $params=array(), array $options=array()) |
||
55 | { |
||
56 | $defaults = ['lang'=>'en']; |
||
57 | $params = array_merge($defaults,$params); |
||
58 | /* @var Url $urlHelper */ |
||
59 | $urlHelper = $this |
||
60 | ->getService('ViewHelperManager') |
||
61 | ->get('url') |
||
62 | ; |
||
63 | $url = $urlHelper($name,$params,$options); |
||
64 | |||
65 | return $this->coreContext->generateUrl($url); |
||
66 | } |
||
67 | |||
68 | public function visit($url) |
||
69 | { |
||
70 | $this->coreContext->iVisit($url); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param $id |
||
75 | * @return mixed|object |
||
76 | */ |
||
77 | public function getService($id) |
||
78 | { |
||
79 | return $this->coreContext->getServiceManager()->get($id); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param $id |
||
84 | * |
||
85 | * @return RepositoryInterface |
||
86 | */ |
||
87 | public function getRepository($id) |
||
88 | { |
||
89 | return $this->coreContext->getRepositories()->get($id); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return UserContext |
||
94 | */ |
||
95 | public function getUserContext() |
||
96 | { |
||
97 | return $this->userContext; |
||
98 | } |
||
99 | } |
||
100 |