function testTriggerEvent() { $r = new AjaxHTTPResponse(); $r->triggerEvent('cartchange', array('qty' => 4)); $r->triggerEvent('addtocart'); $json = $r->getBody(); $data = json_decode($json, true); $this->assertNotEmpty($data[AjaxHTTPResponse::EVENTS_KEY], 'should contain an events key'); $this->assertEquals(1, $data[AjaxHTTPResponse::EVENTS_KEY]['addtocart'], 'should contain a record of the addtocart event'); $this->assertEquals(4, $data[AjaxHTTPResponse::EVENTS_KEY]['cartchange']['qty'], 'should correctly pass on the event data'); }
/** * Add status message to the response (only if `show_ajax_messages` config is set) * @param AjaxHTTPResponse $response * @param Form|null $form the form instance */ protected function triggerStatusMessage($response, $form = null) { if (!self::config()->show_ajax_messages) { return; } $message = ''; $type = ''; if ($this->owner->cart) { $message = $this->owner->cart->getMessage(); $type = $this->owner->cart->getMessageType(); $this->owner->cart->clearMessage(); } if ($form) { // if the message was not previously set via cart, get the message from $form if (empty($message)) { $message = $form->Message(); $type = $form->MessageType(); } $form->clearMessage(); } if (!empty($message)) { $response->triggerEvent('statusmessage', array('content' => $message, 'type' => $type)); } }