public function testFlush() { $options = array('http' => array('header' => "Content-type: application/json\r\n", 'method' => 'POST', 'content' => '{key:value}')); $event1 = new DEG_OrderLifecycle_Model_Lifecycle_Event_Admin_Event(); $collection = new DEG_OrderLifecycle_Model_Lifecycle_Event_Collection(); $collection->addEvent($event1); Mage::register(DEG_OrderLifecycle_Model_Lifecycle_Event_Collection::REGISTRY_LIFECYCLE_EVENT_COLLECTION, $collection); $adapter = $this->mockModel('deg_orderlifecycle/write_adapter_json_post', array('_getUrl', '_sendRequest', '_createContext', 'formatEventData')); $adapter->expects($this->once())->method('_getUrl')->will($this->returnValue('http://www.example.com')); $adapter->expects($this->once())->method('_createContext')->with($this->equalTo($options)); $adapter->expects($this->once())->method('_sendRequest')->with($this->equalTo('http://www.example.com')); $adapter->expects($this->once())->method('formatEventData')->will($this->returnValue('{key:value}')); $order = $this->mockModel('sales/order', array('getStatus', 'getId')); $order->expects($this->any())->method('getStatus')->will($this->returnValue('Complete')); $order->expects($this->any())->method('getId')->will($this->returnValue(12)); $adapter->flush($order->getMockInstance(), 'order'); $this->assertNull(Mage::registry(DEG_OrderLifecycle_Model_Lifecycle_Event_Collection::REGISTRY_LIFECYCLE_EVENT_COLLECTION)); }
public function testLifecycleEventToRegistryExistingCollection() { $user = new Mage_Admin_Model_User(); $adminSessionMock = $this->getModelMockBuilder('admin/session')->disableOriginalConstructor()->setMethods(array('getUser'))->getMock(); $adminSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($user)); $this->replaceByMock('singleton', 'admin/session', $adminSessionMock); $adminSessionQuoteMock = $this->getModelMockBuilder('adminhtml/session_quote')->disableOriginalConstructor()->setMethods(null)->getMock(); $this->replaceByMock('singleton', 'adminhtml/session_quote', $adminSessionQuoteMock); $event = new DEG_OrderLifecycle_Model_Lifecycle_Event_Admin_Event(); $observerObject = new Varien_Event_Observer(); $observerObject->setDataObject($event); $collection = new DEG_OrderLifecycle_Model_Lifecycle_Event_Collection(); $collection->addEvent($event); Mage::register(DEG_OrderLifecycle_Model_Lifecycle_Event_Collection::REGISTRY_LIFECYCLE_EVENT_COLLECTION, $collection); $observer = new DEG_OrderLifecycle_Model_Observer(); $observer->lifecycleEventToRegistry($observerObject); $collection = Mage::registry(DEG_OrderLifecycle_Model_Lifecycle_Event_Collection::REGISTRY_LIFECYCLE_EVENT_COLLECTION); $this->assertEquals(2, sizeof($collection->getEvents())); }
public function testFlush() { $event1 = new DEG_OrderLifecycle_Model_Lifecycle_Event_Admin_Event(); $collection = new DEG_OrderLifecycle_Model_Lifecycle_Event_Collection(); $collection->addEvent($event1); Mage::register(DEG_OrderLifecycle_Model_Lifecycle_Event_Collection::REGISTRY_LIFECYCLE_EVENT_COLLECTION, $collection); $adapter = new DEG_OrderLifecycle_Model_Write_Adapter_Order_History(); $order = $this->mockModel('sales/order', array('getStatus', 'getId')); $order->expects($this->any())->method('getStatus')->will($this->returnValue('Complete')); $order->expects($this->any())->method('getId')->will($this->returnValue(12)); $history = $this->mockModel('sales/order_status_history', array('setParentId', 'setStatus', 'setComment', 'setIsCustomerNotified', 'setIsVisibleOnFront', 'setEntityName', 'save')); $history->expects($this->once())->method('setParentId')->with($this->equalTo(12)); $history->expects($this->once())->method('setStatus')->with($this->equalTo('Complete')); $history->expects($this->once())->method('setComment')->with($this->equalTo('')); $history->expects($this->once())->method('setIsCustomerNotified')->with($this->equalTo(0)); $history->expects($this->once())->method('setIsVisibleOnFront')->with($this->equalTo(0)); $history->expects($this->once())->method('setEntityName')->with($this->equalTo('order')); $history->expects($this->once())->method('save'); $this->replaceByMock('model', 'sales/order_status_history', $history); $adapter->flush($order->getMockInstance(), 'order'); $this->assertNull(Mage::registry(DEG_OrderLifecycle_Model_Lifecycle_Event_Collection::REGISTRY_LIFECYCLE_EVENT_COLLECTION)); }
public function testResetEvents() { $event1 = new Varien_Object(); $event1->setTestValue('test1'); $event2 = new Varien_Object(); $event2->setTestValue('test2'); $collection = new DEG_OrderLifecycle_Model_Lifecycle_Event_Collection(); $this->assertEquals(0, sizeof($collection->getEvents())); $collection->addEvent($event1); $collection->addEvent($event2); $this->assertEquals(2, sizeof($collection->getEvents())); $collection->resetEvents(); $this->assertEquals(0, sizeof($collection->getEvents())); }