Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IVEDU-80 #64

Merged
merged 9 commits into from
Oct 4, 2024
10 changes: 10 additions & 0 deletions lang/ru/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@
$MESS['INTERVOLGA_EDU.COURSE2_LESSON4_SETVIEWTARGETNEWS_DESCRIPTION'] = 'В шаблоне компонента bitrix:news в шаблоне просмотра детальной страницы news.detail должен использоваться метод SetViewTarget';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON4_SHOWVIEWTARGETNEWS'] = 'Проверка ShowViewContent для даты новостей';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON4_SHOWVIEWTARGETNEWS_DESCRIPTION'] = 'ShowViewContent должен быть размещен в header.php перед <p> с классом title';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_HERMITAGEINCOMPONENT'] = 'Проверка корректной выборки данных в компоненте';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_HERMITAGEINCOMPONENT_DESCRIPTION'] = 'В файле компонента должны быть вызовы GetList для элементов и разделов вне циклов';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_TEMPLATELOGIC'] = ' Проверка подготовки Эрмитажа в компоненте';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_TEMPLATELOGIC_DESCRIPTION'] = 'В файле компонента должны быть вызовы CIBlock::GetPanelButtons для элементов и разделов';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_DATACOLLECTION'] = 'Проверка логики работы шаблона';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_DATACOLLECTION_DESCRIPTION'] = 'В файле шаблона данные должны выводиться двумя вложенными циклами foreach';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_DESCRIPTION'] = 'Проверка файла .description.php';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_DESCRIPTION_DESCRIPTION'] = 'В файле .description.php текст должен быть вынесен в lang-файл, подключение news_list.gif должно быть убрано';
$MESS['INTERVOLGA_EDU.COURSE2_LESSON5_1_HERMITAGE'] = 'Проверка файла подключения эрмитажа';
Expand Down Expand Up @@ -303,9 +309,13 @@
$MESS['INTERVOLGA_EDU.SOFT_FORNITURE_SECTION'] = 'Мягкая мебель';
$MESS['INTERVOLGA_EDU.POST_PROPERTY'] = 'Должность';
$MESS['INTERVOLGA_EDU.COMPANY_PROPERTY'] = 'Компания';
$MESS['INTERVOLGA_EDU.EXPERIENCE_PROPERTY'] = 'Требуемый стаж';
$MESS['INTERVOLGA_EDU.WORK_TIME_PROPERTY'] = 'График работы';
$MESS['INTERVOLGA_EDU.EDUCATION_PROPERTY'] = 'Образование';
$MESS['INTERVOLGA_EDU.CATALOGBINDING_PROPERTY'] = 'Привязка к каталогу';
$MESS['INTERVOLGA_EDU.AVAILABLE_PROPERTY'] = 'В наличии';
$MESS['INTERVOLGA_EDU.IBLOCK_REVIEWS'] = 'Отзывы';
$MESS['INTERVOLGA_EDU.IBLOCK_VACANCY'] = 'Вакансии';
$MESS['INTERVOLGA_EDU.IBLOCK_RESPONDENT'] = 'Респондент';
$MESS['INTERVOLGA_EDU.IBLOCK_PROMO'] = 'Акции';
$MESS['INTERVOLGA_EDU.IBLOCK_NEWS'] = 'Новости';
Expand Down
7 changes: 7 additions & 0 deletions lang/ru/lib/asserts/assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@
$MESS['INTERVOLGA_EDU.LANG_STRING_NOT_FOUND'] = 'Строка \'#STRING#\' не найдена в языковом файле #FILE#';
$MESS['INTERVOLGA_EDU.EN_LANG_CODE_NOT_FOUND'] = 'Код \'#CODE#\' не найден в /en/ языковом файле #FILE#';
$MESS['INTERVOLGA_EDU.LOC_MESSAGE_NOT_FOUND'] = 'Код \'#CODE#\' не найден в файле #FILE#';

$MESS['INTERVOLGA_EDU.HAS_EXTRA_PROPERTY'] = 'Имеются лишние свойства:<b> #EXTRA_PROPERTIES# </b>';
$MESS['INTERVOLGA_EDU.REPLACE_TO_PROPERTY'] = 'Возможно стоит <b>#PROPERTY#</b> заменить на <b>#REPLACE_TO#</b>';
$MESS['INTERVOLGA_EDU.CHANGE_TO_DESC'] = 'детальное описание элемента';
$MESS['INTERVOLGA_EDU.CHANGE_TO_NAME'] = 'название элемента';
$MESS['INTERVOLGA_EDU.COUNT_SECTIONS_IS_LESS'] = 'Требуемое количество разделов: <b>#REQUIRED#</b>, сейчас: <b>#NOW#</b>';
$MESS['INTERVOLGA_EDU.COUNT_ELEMENTS_IN_SECTION_IS_LESS'] = 'Разделы (#SECTIONS#) имеют меньше #MIN# элемента';
2 changes: 2 additions & 0 deletions lang/ru/lib/locator/component/customvacancieslist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS['INTERVOLGA_EDU.COMPONENT_CUSTOM_VACANCIES_LIST'] = 'вызов Кастомный комплексный компонент "Список Вакансий"';
3 changes: 3 additions & 0 deletions lang/ru/lib/tests/course2/lesson5_1/testdatacollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
$MESS['INTERVOLGA_EDU.COURSE_2.LESSON_1_2.REG_GET_LIST_CIBlockSection'] = 'CIBlockSection в цикле foreach/while';
$MESS['INTERVOLGA_EDU.COURSE_2.LESSON_1_2.REG_GET_LIST_CIBlockElement'] = 'CIBlockElement в цикле foreach/while';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS['INTERVOLGA_EDU.COURSE_2.LESSON_1_2.HERMITAGE_BUTTONS'] = 'привязка кнопок эрмитажа (GetPanelButtons) больше одного раза. Эрмитаж должен быть использован два раза: один для элементов, второй для разделов.';
2 changes: 2 additions & 0 deletions lang/ru/lib/tests/course2/lesson5_1/testtemplatelogic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS['INTERVOLGA_EDU.COURSE_2.LESSON_1_2.FOREACH_COUNT'] = 'цикл foreach вложенный в другой foreach';
98 changes: 98 additions & 0 deletions lib/asserts/assert.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Intervolga\Edu\Asserts;

use Bitrix\Iblock\ElementTable;
use Bitrix\Iblock\SectionTable;
use Bitrix\Main\Config\Option;
use Bitrix\Main\IO\Directory;
use Bitrix\Main\IO\File;
Expand Down Expand Up @@ -80,6 +82,7 @@ public static function notEq($value, $expect, string $message = '')
));
}
}

/**
* @param string $error
* @throws AssertException
Expand Down Expand Up @@ -992,6 +995,101 @@ public static function propertyTypeListHasValues(array $property, array $values,
}
}

public static function checkUnnecessaryProperties(int $idIBlock, $changeTo, $message = '')
{
$properties = \CIBlock::getProperties($idIBlock);
while ($property = $properties->fetch()['CODE']) {
foreach ($changeTo as $what => $code) {
$reg = new Regex('/' . $what . '/i', '');
if (preg_match($reg->getRegex(), $property)) {
static::registerError(static::getCustomOrLocMessage(
'INTERVOLGA_EDU.REPLACE_TO_PROPERTY', [
'#PROPERTY#' => $property,
'#REPLACE_TO#' => Loc::getMessage($code)
]
), $message);
break;
}
}
}
}

public static function checkCertainProperties(array $requiredProperties, int $idIBlock, string $message = '')
{
$codeProperties = [];
$properties = \CIBlock::getProperties($idIBlock);
while ($property = $properties->fetch()['CODE']) {
$codeProperties[] = $property;
}
$codeReuired = [];
foreach ($requiredProperties as $requiredProperty) {
$codeReuired[] = $requiredProperty::find()['CODE'];
}

if ($props = array_diff($codeProperties, $codeReuired)) {
static::registerError(static::getCustomOrLocMessage(
'INTERVOLGA_EDU.HAS_EXTRA_PROPERTY',
[
'#EXTRA_PROPERTIES#' => implode(', ', $props)
]
), $message);
}
}

public static function checkMinCountSection(int $idIBlock, int $min, string $message = '')
{
$cnt = SectionTable::getList([
'order' => [],
'filter' =>
[
'IBLOCK_ID' => $idIBlock,
],
'count_total' => true,
])->getCount();
if ($cnt<$min) {
static::registerError(static::getCustomOrLocMessage(
'INTERVOLGA_EDU.COUNT_SECTIONS_IS_LESS',
[
'#REQUIRED#' => $min,
'#NOW#' => $cnt
]
), $message);
}
}

public static function checkMinElementsInSection(int $idIBlock, int $min, string $message = '')
{
$getList = ElementTable::getList([
'order' => [],
'filter' =>
[
'IBLOCK_ID' => $idIBlock,
]
]);

$sectionOfCount = [];
while ($el = $getList->fetch()) {
$sectionOfCount[$el['IBLOCK_SECTION_ID']]++;
}

$lessIDs = [];
foreach ($sectionOfCount as $section => $count) {
if ($count<$min) {
$lessIDs[$section] = $count;
}
}
if ($lessIDs) {
static::registerError(static::getCustomOrLocMessage(
'INTERVOLGA_EDU.COUNT_ELEMENTS_IN_SECTION_IS_LESS',
[
'#SECTIONS#' => implode(', ', $lessIDs),
'#MIN#' => $min,
],
$message
));
}
}

public static function menuItemsCount(string $menuPath, $expect, string $message = '')
{
$menuFile = FileSystem::getFile($menuPath);
Expand Down
17 changes: 17 additions & 0 deletions lib/locator/component/customvacancieslist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace Intervolga\Edu\Locator\Component;

use Bitrix\Main\Localization\Loc;

class CustomVacanciesList extends ComponentLocator
{
public static function getCode(): array
{
return ['intervolga:vacancies.list'];
}

public static function getNameLoc(): string
{
return Loc::getMessage('INTERVOLGA_EDU.COMPONENT_CUSTOM_VACANCIES_LIST');
}
}
27 changes: 27 additions & 0 deletions lib/locator/iblock/property/educationproperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace Intervolga\Edu\Locator\Iblock\Property;

use Bitrix\Main\Localization\Loc;
use Intervolga\Edu\Locator\Iblock\VacancyIblock;

class EducationProperty extends PropertyLocator
{
public static function getIblock()
{
return VacancyIblock::class;
}

public static function getFilter(): array
{
return [
'=CODE' => [
'EDUCATION'
],
];
}

public static function getNameLoc(): string
{
return Loc::getMessage('INTERVOLGA_EDU.EDUCATION_PROPERTY');
}
}
29 changes: 29 additions & 0 deletions lib/locator/iblock/property/experienceproperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace Intervolga\Edu\Locator\Iblock\Property;

use Bitrix\Main\Localization\Loc;
use Intervolga\Edu\Locator\Iblock\VacancyIblock;

class ExperienceProperty extends PropertyLocator
{
public static function getIblock()
{
return VacancyIblock::class;
}

public static function getFilter(): array
{
return [
'=CODE' => [
'REQUIRED_EXP',
'EXP',
'EXPERIENCE',
],
];
}

public static function getNameLoc(): string
{
return Loc::getMessage('INTERVOLGA_EDU.EXPERIENCE_PROPERTY');
}
}
28 changes: 28 additions & 0 deletions lib/locator/iblock/property/worktimeproperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace Intervolga\Edu\Locator\Iblock\Property;

use Bitrix\Main\Localization\Loc;
use Intervolga\Edu\Locator\Iblock\VacancyIblock;

class WorkTimeProperty extends PropertyLocator
{
public static function getIblock()
{
return VacancyIblock::class;
}

public static function getFilter(): array
{
return [
'=CODE' => [
'WORK_TIME',
'WORKING_TIME'
],
];
}

public static function getNameLoc(): string
{
return Loc::getMessage('INTERVOLGA_EDU.WORK_TIME_PROPERTY');
}
}
23 changes: 23 additions & 0 deletions lib/locator/iblock/vacancyiblock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Intervolga\Edu\Locator\Iblock;

use Bitrix\Main\Localization\Loc;

class VacancyIblock extends IblockLocator
{
public static function getFilter(): array
{
return [
'=CODE' => [
'vacancy',
'vacancies',
'furniture_vacancies_s1'
],
];
}

public static function getNameLoc(): string
{
return Loc::getMessage('INTERVOLGA_EDU.IBLOCK_VACANCY');
}
}
7 changes: 6 additions & 1 deletion lib/tester.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ protected static function getTestClasses()
\Intervolga\Edu\Tests\Course2\Lesson4\TestSetViewTargetMaterials::class,
\Intervolga\Edu\Tests\Course2\Lesson4\TestShowViewContentMaterials::class,

\Intervolga\Edu\Tests\Course2\Lesson5_1\TestDataCollection::class,
\Intervolga\Edu\Tests\Course2\Lesson5_1\TestHermitage::class,
\Intervolga\Edu\Tests\Course2\Lesson5_1\TestHermitageInComponent::class,
\Intervolga\Edu\Tests\Course2\Lesson5_1\TestTemplateLogic::class,
\Intervolga\Edu\Tests\Course2\Lesson5_1\TestComponentDirectory::class,
\Intervolga\Edu\Tests\Course2\Lesson5_1\TestDescription::class,
\Intervolga\Edu\Tests\Course2\Lesson5_1\TestHermitage::class,


\Intervolga\Edu\Tests\Course2\Lesson5_2\TestComponentCache::class,
\Intervolga\Edu\Tests\Course2\Lesson5_2\TestVacancyIblock::class,

\Intervolga\Edu\Tests\Course2\Lesson6\TestWebFormsChecker::class,
\Intervolga\Edu\Tests\Course2\Lesson6\TestVacanciesParametersChecker::class,
Expand Down
33 changes: 33 additions & 0 deletions lib/tests/course2/lesson5_1/testdatacollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Intervolga\Edu\Tests\Course2\Lesson5_1;

use Bitrix\Main\Localization\Loc;
use Intervolga\Edu\Asserts\Assert;
use Intervolga\Edu\Asserts\AssertComponent;
use Intervolga\Edu\Locator\Component\CustomVacanciesList;
use Intervolga\Edu\Locator\IO\VacanciesListComponent;
use Intervolga\Edu\Tests\BaseTest;
use Intervolga\Edu\Util\FileSystem;
use Intervolga\Edu\Util\Regex;

class TestDataCollection extends BaseTest
{
const REG_GET_LIST_CIBlockSection = '/(foreach|while)+\s*([\w\s\d$=\-:()[\]\.;,><\'\"]*\{[\w\s\d{$=\-:()[\]\.;,><\'\"]*(\{[\w\s\d{$=\-:()[\]\.;,><\'\"]*\})*|[\w\s\d{$=\-:()[\]\.;,><\'\"])*CIBlockSection::getList\(/i';
const REG_GET_LIST_CIBlockElement = '/(foreach|while)+\s*([\w\s\d$=\-:()[\]\.;,><\'\"]*\{[\w\s\d{$=\-:()[\]\.;,><\'\"]*(\{[\w\s\d{$=\-:()[\]\.;,><\'\"]*\})*|[\w\s\d{$=\-:()[\]\.;,><\'\"])*CIBlockElement::getList\(/i';

protected static function run()
{
AssertComponent::componentLocator(CustomVacanciesList::class);
Assert::directoryLocator(VacanciesListComponent::class);
if ($directory = VacanciesListComponent::find()) {
$file = FileSystem::getInnerFile($directory, 'component.php');
Assert::fseExists($file);
if ($file->isExists()) {
Assert::fileContentNotMatches($file, new Regex(static::REG_GET_LIST_CIBlockSection,
Loc::getMessage('INTERVOLGA_EDU.COURSE_2.LESSON_1_2.REG_GET_LIST_CIBlockSection')));
Assert::fileContentNotMatches($file, new Regex(static::REG_GET_LIST_CIBlockElement,
Loc::getMessage('INTERVOLGA_EDU.COURSE_2.LESSON_1_2.REG_GET_LIST_CIBlockElement')));
}
}
}
}
30 changes: 30 additions & 0 deletions lib/tests/course2/lesson5_1/testhermitageincomponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace Intervolga\Edu\Tests\Course2\Lesson5_1;

use Bitrix\Main\Localization\Loc;
use Intervolga\Edu\Asserts\Assert;
use Intervolga\Edu\Asserts\AssertComponent;
use Intervolga\Edu\Locator\Component\CustomVacanciesList;
use Intervolga\Edu\Locator\IO\VacanciesListComponent;
use Intervolga\Edu\Tests\BaseTest;
use Intervolga\Edu\Util\FileSystem;
use Intervolga\Edu\Util\Regex;

class TestHermitageInComponent extends BaseTest
{
const REG_BUTTONS = '/CIBlock::GetPanelButtons[\w\s\d()$[\]\'",;:\/А-я\=}{><\-]*CIBlock::GetPanelButtons/iu';

protected static function run()
{
AssertComponent::componentLocator(CustomVacanciesList::class);
Assert::directoryLocator(VacanciesListComponent::class);
if ($directory = VacanciesListComponent::find()) {
$file = FileSystem::getInnerFile($directory, 'component.php');
Assert::fseExists($file);
if($file->isExists()){
Assert::fileContentMatches($file, new Regex(static::REG_BUTTONS,
Loc::getMessage('INTERVOLGA_EDU.COURSE_2.LESSON_1_2.HERMITAGE_BUTTONS')));
}
}
}
}
Loading