/** * Ensure that update and create trigger appropriate flows */ public function testContacts() { X2FlowTestingAuxLib::clearLogs($this); $this->action = 'model'; $this->assertEquals(array(), TriggerLog::model()->findAll()); // Create $contact = array('firstName' => 'Walt', 'lastName' => 'White', 'email' => '*****@*****.**', 'visibility' => 1, 'trackingKey' => '1234'); $ch = $this->getCurlHandle('POST', array('{modelAction}' => 'Contacts'), 'admin', $contact); $response = json_decode(curl_exec($ch), 1); $id = $response['id']; $this->assertResponseCodeIs(201, $ch); $this->assertTrue((bool) ($newContact = Contacts::model()->findBySql('SELECT * FROM x2_contacts WHERE firstName="Walt" AND lastName="White" AND email="*****@*****.**" AND trackingKey="1234"'))); $logs = TriggerLog::model()->findAll(); $this->assertEquals(1, count($logs)); $trace = X2FlowTestingAuxLib::getTraceByFlowId($this->flows('flow1')->id); $this->assertTrue(is_array($trace)); $this->assertTrue(X2FlowTestingAuxLib::checkTrace($trace)); // Update $contact['firstName'] = 'Walter'; $ch = $this->getCurlHandle('PUT', array('{modelAction}' => "Contacts/{$id}.json"), 'admin', $contact); $response = json_decode(curl_exec($ch), 1); $this->assertResponseCodeIs(200, $ch); $newContact->refresh(); $this->assertEquals($contact['firstName'], $newContact['firstName']); $logs = TriggerLog::model()->findAll(); $this->assertEquals(2, count($logs)); $trace = X2FlowTestingAuxLib::getTraceByFlowId($this->flows('flow2')->id); $this->assertTrue(is_array($trace)); $this->assertTrue(X2FlowTestingAuxLib::checkTrace($trace)); }
/** * Returns trace of log for specified flow * @return null|array */ public static function getTraceByFlowId($flowId) { $log = TriggerLog::model()->findByAttributes(array('flowId' => $flowId)); if ($log) { $decodedLog = CJSON::decode($log->triggerLog); return $decodedLog[1]; } else { return $log; } }
public function testRecordLimit() { $this->clearLogs(); Yii::app()->settings->triggerLogMax = 5; Yii::app()->settings->save(); //TriggerLog::model ()->asa ('RecordLimitBehavior')->limit = 5; $contact = $this->contacts('testUser'); $params = array('model' => $this->contacts('testUser')); X2Flow::trigger('RecordViewTrigger', $params); $this->assertEquals(1, TriggerLog::model()->count()); sleep(1); // ensure that log timestamps differ X2Flow::trigger('RecordViewTrigger', $params); $this->assertEquals(2, TriggerLog::model()->count()); sleep(1); X2Flow::trigger('RecordViewTrigger', $params); $this->assertEquals(3, TriggerLog::model()->count()); sleep(1); X2Flow::trigger('RecordViewTrigger', $params); $this->assertEquals(4, TriggerLog::model()->count()); sleep(1); X2Flow::trigger('RecordViewTrigger', $params); $this->assertEquals(5, TriggerLog::model()->count()); $triggerLogMinTS = Yii::app()->db->createCommand()->select('min(triggeredAt)')->from('x2_trigger_logs')->queryScalar(); sleep(1); X2Flow::trigger('RecordViewTrigger', $params); $this->assertEquals(5, TriggerLog::model()->count()); $triggerLogNewMinTS = Yii::app()->db->createCommand()->select('min(triggeredAt)')->from('x2_trigger_logs')->queryScalar(); // ensure that oldest log was removed $this->assertNotEquals($triggerLogMinTS, $triggerLogNewMinTS); // now remove the limit $triggerLogMinTS = $triggerLogNewMinTS; Yii::app()->settings->triggerLogMax = null; Yii::app()->settings->save(); //TriggerLog::model ()->asa ('RecordLimitBehavior')->limit = null; sleep(1); X2Flow::trigger('RecordViewTrigger', $params); $this->assertEquals(6, TriggerLog::model()->count()); $triggerLogNewMinTS = Yii::app()->db->createCommand()->select('min(triggeredAt)')->from('x2_trigger_logs')->queryScalar(); $this->assertEquals($triggerLogMinTS, $triggerLogNewMinTS); }
public function actionDeleteTriggerLog($id) { if (isset($id)) { $triggerLog = TriggerLog::model()->findByAttributes(array('id' => $id)); if (!empty($triggerLog)) { $triggerLog->delete(); echo "success"; return; } } echo "failure"; }