Skip to content

Instantly share code, notes, and snippets.

@Feiron
Last active June 9, 2021 11:20
Show Gist options
  • Select an option

  • Save Feiron/d644a14a239fc26afbfaabda29b9f7ee to your computer and use it in GitHub Desktop.

Select an option

Save Feiron/d644a14a239fc26afbfaabda29b9f7ee to your computer and use it in GitHub Desktop.

Revisions

  1. Feiron revised this gist Jun 9, 2021. No changes.
  2. Feiron revised this gist Mar 6, 2019. 1 changed file with 35 additions and 0 deletions.
    35 changes: 35 additions & 0 deletions start.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <?
    require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php");
    $APPLICATION->SetTitle("Тестирование");

    CModule::IncludeModule('gpw.testing');
    CModule::IncludeModule('im');
    CModule::IncludeModule('bizproc');


    $iTemplateID = XXX;
    $ID = 15949;

    $arDocumentID = [
    "crm",
    "CCrmDocumentDeal",
    "DEAL_" . $ID
    ];

    $arFields = [
    //'RATE' => 6,
    //'UF_CRM_EMAIL' => ['n0' => '[email protected]']
    ];

    try {
    GPW\Testing\Tests\Bitrix\BP::Run($iTemplateID, $arDocumentID, $arFields, ['STORE' => false]);

    } catch (\Exception $e) {
    ShowError($e->getMessage());
    if(method_exists($e, 'getParameter')){
    echo '<pre>'; var_dump($e->getParameter()); echo '</pre>';
    }
    }

    require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php");
    ?>
  3. Feiron revised this gist Mar 6, 2019. 1 changed file with 68 additions and 40 deletions.
    108 changes: 68 additions & 40 deletions testing_bp.php
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@

    namespace GPW\Testing\Tests\Bitrix;

    use Bitrix\Main\ArgumentException;

    if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();

    class BP
    @@ -30,9 +32,10 @@ public static function Run($iTemplateID, $arDocumentID, $arFields, $arParams)
    try {

    $wid = self::Start($iTemplateID, $arDocumentID, $arFields);

    $strLog = self::GetTrackingByWID($wid);

    if (!$arParams['SILENT']) {
    echo self::GetTrackingByWID($wid);
    echo $strLog;
    }
    if (!$arParams['STORE']) {
    self::Delete($wid);
    @@ -63,18 +66,43 @@ public static function Delete($WID, $bTerminate = false, $arDocumentID = null)
    */
    public static function Start($iTemplateID, $arDocumentID, $arFields = [])
    {
    $wid = \CBPDocument::StartWorkflow(
    $iTemplateID,
    $arDocumentID,
    $dbWorkflowTemplate = \CBPWorkflowTemplateLoader::GetList(
    array(),
    array(
    "ID" => $iTemplateID,
    ),
    false,
    false,
    array("ID", "NAME", "DESCRIPTION", "MODIFIED", "USER_ID", "PARAMETERS")
    );
    if ($dbWorkflowTemplate->SelectedRowsCount() < 0) {
    throw new \Exception('TEMPLATE_NOT_FOUND');
    }
    $arWorkflowTemplate = $dbWorkflowTemplate->Fetch();

    $arWorkflowParameters = \CBPWorkflowTemplateLoader::CheckWorkflowParameters(
    $arWorkflowTemplate["PARAMETERS"],
    $arFields,
    $arDocumentID,
    $arErrors
    );

    if (empty($arErrors)) {
    return $wid;

    $wid = \CBPDocument::StartWorkflow(
    $iTemplateID,
    $arDocumentID,
    $arWorkflowParameters,
    $arErrors
    );

    if (empty($arErrors)) {
    return $wid;
    }
    throw new \Exception('INVALID_PARAMETERS', $arErrors);
    }

    throw new \Exception($arErrors);
    throw new ArgumentException('INVALID_PARAMETERS', $arErrors);
    }

    /**
    @@ -99,39 +127,39 @@ public static function GetTrackingByWID($WID)
    ob_start();
    ?>

    <div><?= $arTask['ID'] ?></div>
    <div><?= $arTask['STARTED'] ?></div>
    <div><?= $arTask['TEMPLATE_DESCRIPTION'] ?></div>
    <div><?= $arTask['STATE_NAME'] ?><br><?= $arTask['STATE_TITLE'] ?></div>

    <table style="width: 700px;">
    <thead>
    <tr>
    <th>Тип</th>
    <th>Дата</th>
    <th>Имя</th>
    <th>Статус</th>
    <th>Текст</th>
    </tr>
    </thead>
    <tbody>
    <?
    while ($arTrack = $dbTrack->Fetch()) {
    ?>
    <tr>
    <td><?= $arTrack['TYPE'] ?></td>
    <td><?= $arTrack['MODIFIED'] ?></td>
    <td><?= $arTrack['ACTION_NAME'] ?><br><?= $arTrack['ACTION_TITLE'] ?></td>
    <td><?= $arTrack['EXECUTION_STATUS'] ?></td>
    <td>
    <textarea readonly="" name="ACTION_NOTE" id="" cols="60" rows="4"><?= $arTrack['ACTION_NOTE'] ?></textarea>
    </td>
    </tr>
    <?
    }
    ?>
    </tbody>
    </table>
    <div><?= $arTask['ID'] ?></div>
    <div><?= $arTask['STARTED'] ?></div>
    <div><?= $arTask['TEMPLATE_DESCRIPTION'] ?></div>
    <div><?= $arTask['STATE_NAME'] ?><br><?= $arTask['STATE_TITLE'] ?></div>

    <table style="width: 700px;">
    <thead>
    <tr>
    <th>Тип</th>
    <th>Дата</th>
    <th>Имя</th>
    <th>Статус</th>
    <th>Текст</th>
    </tr>
    </thead>
    <tbody>
    <?
    while ($arTrack = $dbTrack->Fetch()) {
    ?>
    <tr>
    <td><?= $arTrack['TYPE'] ?></td>
    <td><?= $arTrack['MODIFIED'] ?></td>
    <td><?= $arTrack['ACTION_NAME'] ?><br><?= $arTrack['ACTION_TITLE'] ?></td>
    <td><?= $arTrack['EXECUTION_STATUS'] ?></td>
    <td>
    <textarea readonly="" name="ACTION_NOTE" id="" cols="60" rows="4"><?= $arTrack['ACTION_NOTE'] ?></textarea>
    </td>
    </tr>
    <?
    }
    ?>
    </tbody>
    </table>
    <?

    return (string)ob_get_clean();
  4. Feiron renamed this gist Mar 6, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. Feiron revised this gist Mar 6, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions Template
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <?php
    $this->WriteToTrackingService($strAddInfo);
    $this->SetVariable("BB_ADDINFO", $strAddInfo);
    $this->GetVariable("BB_ADDINFO");
    $RootActivity = $this->GetRootActivity();
    $iUserID = $RootActivity->RESPONSIBLE;
  6. Feiron renamed this gist Mar 5, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. Feiron revised this gist Mar 5, 2019. 1 changed file with 33 additions and 33 deletions.
    66 changes: 33 additions & 33 deletions bp.php
    Original file line number Diff line number Diff line change
    @@ -99,39 +99,39 @@ public static function GetTrackingByWID($WID)
    ob_start();
    ?>

    <div><?= $arTask['ID'] ?></div>
    <div><?= $arTask['STARTED'] ?></div>
    <div><?= $arTask['TEMPLATE_DESCRIPTION'] ?></div>
    <div><?= $arTask['STATE_NAME'] ?><br><?= $arTask['STATE_TITLE'] ?></div>

    <table style="width: 700px;">
    <thead>
    <tr>
    <th>Тип</th>
    <th>Дата</th>
    <th>Имя</th>
    <th>Статус</th>
    <th>Текст</th>
    </tr>
    </thead>
    <tbody>
    <?
    while ($arTrack = $dbTrack->Fetch()) {
    ?>
    <tr>
    <td><?= $arTrack['TYPE'] ?></td>
    <td><?= $arTrack['MODIFIED'] ?></td>
    <td><?= $arTrack['ACTION_NAME'] ?><br><?= $arTrack['ACTION_TITLE'] ?></td>
    <td><?= $arTrack['EXECUTION_STATUS'] ?></td>
    <td>
    <textarea readonly="" name="ACTION_NOTE" id="" cols="60" rows="4"><?= $arTrack['ACTION_NOTE'] ?></textarea>
    </td>
    </tr>
    <?
    }
    ?>
    </tbody>
    </table>
    <div><?= $arTask['ID'] ?></div>
    <div><?= $arTask['STARTED'] ?></div>
    <div><?= $arTask['TEMPLATE_DESCRIPTION'] ?></div>
    <div><?= $arTask['STATE_NAME'] ?><br><?= $arTask['STATE_TITLE'] ?></div>

    <table style="width: 700px;">
    <thead>
    <tr>
    <th>Тип</th>
    <th>Дата</th>
    <th>Имя</th>
    <th>Статус</th>
    <th>Текст</th>
    </tr>
    </thead>
    <tbody>
    <?
    while ($arTrack = $dbTrack->Fetch()) {
    ?>
    <tr>
    <td><?= $arTrack['TYPE'] ?></td>
    <td><?= $arTrack['MODIFIED'] ?></td>
    <td><?= $arTrack['ACTION_NAME'] ?><br><?= $arTrack['ACTION_TITLE'] ?></td>
    <td><?= $arTrack['EXECUTION_STATUS'] ?></td>
    <td>
    <textarea readonly="" name="ACTION_NOTE" id="" cols="60" rows="4"><?= $arTrack['ACTION_NOTE'] ?></textarea>
    </td>
    </tr>
    <?
    }
    ?>
    </tbody>
    </table>
    <?

    return (string)ob_get_clean();
  8. Feiron revised this gist Mar 5, 2019. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions bp.php
    Original file line number Diff line number Diff line change
    @@ -30,10 +30,9 @@ public static function Run($iTemplateID, $arDocumentID, $arFields, $arParams)
    try {

    $wid = self::Start($iTemplateID, $arDocumentID, $arFields);
    $strLog = self::GetTrackingByWID($wid);


    if (!$arParams['SILENT']) {
    echo $strLog;
    echo self::GetTrackingByWID($wid);
    }
    if (!$arParams['STORE']) {
    self::Delete($wid);
  9. Feiron created this gist Mar 5, 2019.
    143 changes: 143 additions & 0 deletions bp.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,143 @@
    <?php
    /**
    * User: Feiron
    * Date: 04.06.2018
    * Time: 15:37
    *
    * @var array $arParams
    * @var array $arResult
    * @global CMain $APPLICATION
    *
    *
    */

    namespace GPW\Testing\Tests\Bitrix;

    if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();

    class BP
    {
    /**
    * @param $iTemplateID
    * @param $arDocumentID
    * @param $arFields
    * @param [] $arParams SILENT = Нет вывода трейса, STORE - Оставить результат
    *
    * @throws \Exception
    */
    public static function Run($iTemplateID, $arDocumentID, $arFields, $arParams)
    {
    try {

    $wid = self::Start($iTemplateID, $arDocumentID, $arFields);
    $strLog = self::GetTrackingByWID($wid);

    if (!$arParams['SILENT']) {
    echo $strLog;
    }
    if (!$arParams['STORE']) {
    self::Delete($wid);
    }

    } catch (\Exception $e) {
    throw $e;
    }
    }

    /**
    * @param $WID
    * @param bool $bTerminate Останавливает, если нельзя дает ошибку
    * @param null $arDocumentID Необязательно
    */
    public static function Delete($WID, $bTerminate = false, $arDocumentID = null)
    {
    \CBPDocument::killWorkflow($WID, $bTerminate, $arDocumentID);
    }

    /**
    * @param $iTemplateID
    * @param $arDocumentID ["crm", "CCrmDocumentDeal", "DEAL_11"]
    * @param $arFields
    *
    * @return string
    * @throws \Exception
    */
    public static function Start($iTemplateID, $arDocumentID, $arFields = [])
    {
    $wid = \CBPDocument::StartWorkflow(
    $iTemplateID,
    $arDocumentID,
    $arFields,
    $arErrors
    );

    if (empty($arErrors)) {
    return $wid;
    }

    throw new \Exception($arErrors);
    }

    /**
    * @param $WID
    *
    * @return string
    * @throws \Exception
    */
    public static function GetTrackingByWID($WID)
    {
    $dbTrack = \CBPTrackingService::GetList(
    array("ID" => "desc"),
    array(
    "WORKFLOW_ID" => $WID,
    )
    );

    if ($dbTrack->SelectedRowsCount()) {

    $arTask = \CBPStateService::GetWorkflowState($WID);

    ob_start();
    ?>

    <div><?= $arTask['ID'] ?></div>
    <div><?= $arTask['STARTED'] ?></div>
    <div><?= $arTask['TEMPLATE_DESCRIPTION'] ?></div>
    <div><?= $arTask['STATE_NAME'] ?><br><?= $arTask['STATE_TITLE'] ?></div>

    <table style="width: 700px;">
    <thead>
    <tr>
    <th>Тип</th>
    <th>Дата</th>
    <th>Имя</th>
    <th>Статус</th>
    <th>Текст</th>
    </tr>
    </thead>
    <tbody>
    <?
    while ($arTrack = $dbTrack->Fetch()) {
    ?>
    <tr>
    <td><?= $arTrack['TYPE'] ?></td>
    <td><?= $arTrack['MODIFIED'] ?></td>
    <td><?= $arTrack['ACTION_NAME'] ?><br><?= $arTrack['ACTION_TITLE'] ?></td>
    <td><?= $arTrack['EXECUTION_STATUS'] ?></td>
    <td>
    <textarea readonly="" name="ACTION_NOTE" id="" cols="60" rows="4"><?= $arTrack['ACTION_NOTE'] ?></textarea>
    </td>
    </tr>
    <?
    }
    ?>
    </tbody>
    </table>
    <?

    return (string)ob_get_clean();
    } else {
    throw new \Exception('CANT_GET_TRACE: ' . $WID);
    }
    }
    }