public function testAdd() { $this->_injectDutyCollector(); $ibType = \CIBlockType::GetList()->Fetch(); $ib = new \CIBlock(); $ibId = $ib->Add(array('IBLOCK_TYPE_ID' => $ibType['ID'], 'NAME' => 'New Iblock', 'SITE_ID' => 's1')); $this->assertNotEmpty($ibId, $this->errorMessage('not create iblock id', array(':lastError' => $ib->LAST_ERROR))); $prop = new \CIBlockProperty(); $propId = $prop->Add(array('IBLOCK_ID' => $ibId, 'CODE' => 'propCode', 'NAME' => 'Property NAME')); $this->assertNotEmpty($propId, $this->errorMessage('not create property iblock id', array(':lastError' => $ib->LAST_ERROR))); $sec = new \CIBlockSection(); $secId = $sec->Add(array('IBLOCK_ID' => $ibId, 'NAME' => 'Iblock Section')); $this->assertNotEmpty($secId, $this->errorMessage('not create section iblock id', array(':lastError' => $ib->LAST_ERROR))); // ¬ итоге должны получитс¤ // данные по добавлению »Ѕ $this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockHandler::className())); // данные по добавлению свойства $this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockPropertyHandler::className())); // данные по добавлению секции $this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockSectionHandler::className())); $refFixes = $this->_getCollectorFixes('reference'); // фиксаци¤ изменений Module::getInstance()->commitDutyChanges(); // добавлены записи журнала обновлений (в базу) /** @var $logRecords AppliedChangesLogModel[] */ $logRecords = AppliedChangesLogModel::find(array('order' => array('id' => 'desc'), 'limit' => 10)); $this->assertTrue(count($logRecords) > 3); $iterationsCount = 0; foreach ($logRecords as $logRecord) { if ($logRecord->processName == Module::SPECIAL_PROCESS_FIX_REFERENCE) { continue; } if ($logRecord->processName != AddProcess::className()) { $this->throwError($this->errorMessage('last log records need been update process'), $logRecord->processName); } if (++$iterationsCount > 3) { break; } $data = $logRecord->updateData; switch ($logRecord->subjectName) { case IblockHandler::className(): (!$data['iblock'] || $data['iblock']['ID'] != $ibId) && $this->throwError($this->errorMessage('iblock not registered after update', array(':actual' => $data['iblock']['ID'], ':need' => $ibId))); break; case IblockPropertyHandler::className(): $data['ID'] != $propId && $this->throwError($this->errorMessage('property iblock not registered after update', array(':original' => $propId, ':actual' => $data['ID']))); break; case IblockSectionHandler::className(): $data['ID'] != $secId && $this->throwError($this->errorMessage('section iblock not registered after update', array(':original' => $secId, ':actual' => $data['ID']))); break; } } // добавлены три вида ссылок в фиксаци¤х $this->assertEquals(3, count($refFixes), $this->errorMessage('links expected count', array(':count' => 3))); $this->_iblockId = $ibId; $this->_propertyId = $propId; $this->_sectionId = $secId; }
/** * @param $class * @return BaseProcess */ public function getProcess($class) { switch ($class) { case AddProcess::className(): return $this->_getProcessAdd(); break; case UpdateProcess::className(): return $this->_getProcessUpdate(); break; case DeleteProcess::className(): return $this->_getProcessDelete(); break; } }