Skip to content

Commit db7e265

Browse files
committed
goTo класса BitrixableTestCase.
1 parent 69aca81 commit db7e265

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

readme.MD

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function useComponentInvoker() {
208208
}
209209
```
210210

211-
#### Тестирование работы адаптера шабалона (result_modifier)
211+
#### Тестирование работы адаптера шаблона (result_modifier)
212212

213213
Тестировать result_modifier шаблона компонента можно объектом класса ```Prokl\BitrixTestingTools\Invokers\ResultModifierInvoker```.
214214

@@ -267,3 +267,23 @@ public function handlersOfEventExist() {
267267
$this->getAssert()->asTrue($eventInvoker->countOfHandlers() > 1);
268268
}
269269
```
270+
271+
#### Прочее
272+
273+
- Метод `goTo` класса `BitrixableTestCase`. Эмулирует нахождение на каком-либо URL. Выставляет все, что связано с URL
274+
в старом ядре и D7.
275+
276+
Также подменяет автоматом все, что возможно из супер-глобалов типа $_SERVER, $_POST и т.д.
277+
278+
```php
279+
$_GET['test'] = 'OK';
280+
281+
$this->goTo('/test/');
282+
283+
$url = $APPLICATION->GetCurPage(); // $url = '/test/index.php'
284+
285+
$request = Application::getInstance()->getContext()->getRequest();
286+
$uriString = $request->getRequestUri(); // $uriString = '/test/'
287+
288+
$testGetParam = $request->getQuery('test'); // $testGetParam = 'OK'
289+
```

src/Base/BitrixableTestCase.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Prokl\BitrixTestingTools\Base;
44

5-
use Bitrix\Catalog\Model\Price;
5+
use Bitrix\Main\Application;
66
use Exception;
77
use Prokl\BitrixTestingTools\Migrations\ArrilotMigratorProcessor;
88
use Prokl\BitrixTestingTools\Migrator;
@@ -13,6 +13,8 @@
1313
use Prokl\BitrixTestingTools\Traits\SprintMigrationsTrait;
1414
use Prokl\BitrixTestingTools\Traits\UseMigrationsTrait;
1515
use Prokl\TestingTools\Base\BaseTestCase;
16+
use ReflectionClass;
17+
use ReflectionException;
1618
use Sheerockoff\BitrixCi\Bootstrap;
1719

1820
/**
@@ -100,6 +102,41 @@ protected function setupDatabaseData() : void
100102
putenv('MYSQL_PASSWORD=');
101103
}
102104

105+
/**
106+
* Эмуляция нахождения на какой-либо странице. Выставляется все, что связано с URL - как в D7,
107+
* так и в старом ядре.
108+
*
109+
* @param string $url URL.
110+
*
111+
* @return void
112+
*
113+
* @throws ReflectionException
114+
*
115+
* @since 15.06.2021
116+
*/
117+
protected function goTo(string $url) : void
118+
{
119+
$_SERVER['REQUEST_URI'] = $url;
120+
$GLOBALS['APPLICATION']->sDirPath = GetPagePath(false, true);
121+
122+
$application = Application::getInstance();
123+
124+
$reflection = new ReflectionClass($application);
125+
$reflection_property = $reflection->getProperty('isExtendedKernelInitialized');
126+
$reflection_property->setAccessible(true);
127+
$reflection_property->setValue($application, false);
128+
129+
$application->initializeExtendedKernel(
130+
[
131+
'server' => $_SERVER,
132+
'get' => $_GET,
133+
'post' => $_POST,
134+
'files' => $_FILES,
135+
'cookie' => $_COOKIE,
136+
]
137+
);
138+
}
139+
103140
/**
104141
* Битриксовые штучки-дрючки с буфером.
105142
*

0 commit comments

Comments
 (0)