File tree Expand file tree Collapse file tree 2 files changed +119
-0
lines changed Expand file tree Collapse file tree 2 files changed +119
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Prokl \BitrixTestingTools \Traits ;
4+
5+ use Prokl \TestingTools \Tools \PHPUnitUtils ;
6+ use ReflectionException ;
7+
8+ /**
9+ * Trait BBCComponentTrait
10+ * Утилиты для тестирования Базовых битриксовых компонентов (https://github.com/bitrix-expert/bbc).
11+ * @package Local\Tests\Traits
12+ */
13+ trait BBCComponentTrait
14+ {
15+ /**
16+ * Задать arParams компонента.
17+ *
18+ * @param array $arParams
19+ *
20+ * @return void
21+ * @throws ReflectionException
22+ */
23+ private function arParams (array $ arParams = []) : void
24+ {
25+ PHPUnitUtils::setProtectedProperty (
26+ $ this ->obTestObject ,
27+ 'arParams ' ,
28+ $ arParams
29+ );
30+ }
31+
32+ /**
33+ * Выполнить executeMain.
34+ *
35+ * @param mixed $mock
36+ *
37+ * @return mixed
38+ * @throws ReflectionException
39+ */
40+ private function runExecuteMain ($ mock = null )
41+ {
42+ $ mock = $ mock ?: $ this ->obTestObject ;
43+
44+ PHPUnitUtils::callMethod (
45+ $ mock ,
46+ 'executeMain ' ,
47+ []
48+ );
49+
50+ return PHPUnitUtils::getProtectedProperty (
51+ $ mock ,
52+ 'arResult '
53+ );
54+ }
55+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Prokl \BitrixTestingTools \Utils ;
4+
5+ use CIBlock ;
6+
7+ /**
8+ * Class Prokl\BitrixTestingTools\Utils
9+ * @package Local\Tests
10+ */
11+ class PHPUnitBitrixUtils
12+ {
13+ /**
14+ * Случайный ID инфоблока.
15+ *
16+ * @return integer
17+ */
18+ public static function getRandomIdIblock () : int
19+ {
20+ $ ib_list = CIBlock::GetList (
21+ [],
22+ [
23+ "ACTIVE " => 'Y ' ,
24+ ]
25+ );
26+
27+ while ($ ib = $ ib_list ->GetNext ()) {
28+ $ arIds [] = $ ib ['ID ' ];
29+ }
30+
31+ if (empty ($ arIds )) {
32+ return 0 ;
33+ }
34+
35+ return $ arIds [rand (1 , count ($ arIds ) - 1 )];
36+ }
37+
38+ /**
39+ * Случайный ID инфоблока с непустым полем DESCRIPTION.
40+ *
41+ * @return integer
42+ */
43+ public static function getRandomIblockIdWithTextInfo () : int
44+ {
45+ $ ibQuery = CIBlock::GetList (
46+ [],
47+ [
48+ "ACTIVE " => 'Y ' ,
49+ ]
50+ );
51+
52+ while ($ obIblock = $ ibQuery ->GetNext ()) {
53+ if (!empty ($ obIblock ['DESCRIPTION ' ])) {
54+ $ arIds [] = $ obIblock ['ID ' ];
55+ }
56+ }
57+
58+ if (empty ($ arIds )) {
59+ return 0 ;
60+ }
61+
62+ return $ arIds [rand (1 , count ($ arIds ) - 1 )];
63+ }
64+ }
You can’t perform that action at this time.
0 commit comments