Example #1
0
 protected function _mockCollection()
 {
     Mage::register('current_channeltype', new Varien_Object());
     $methods = array('joinProductQty', 'prepareStoreSensitiveData', 'addFieldToFilter', 'addAttributeToFilter', 'joinStatusColumn', 'load', 'setOrder');
     $collection = $this->getMock('Xcom_Listing_Model_Resource_Product_Collection', $methods, array(), '', false);
     $collection->expects($this->any())->method('load')->will($this->returnValue(array()));
     $collection->expects($this->any())->method('joinProductQty')->will($this->returnValue($collection));
     $collection->expects($this->any())->method('prepareStoreSensitiveData')->will($this->returnValue($collection));
     $collection->expects($this->any())->method('joinField')->will($this->returnValue($collection));
     $collection->expects($this->any())->method('addFieldToFilter')->will($this->returnValue($collection));
     $collection->expects($this->any())->method('addAttributeToFilter')->will($this->returnValue($collection));
     $collection->expects($this->any())->method('joinStatusColumn')->withAnyParameters()->will($this->returnValue($collection));
     Mage::registerMockResourceModel('xcom_listing/product_collection', $collection);
 }
Example #2
0
 public function testValidateIsRequiredAttributeHasMappedValueWithNotMappedAttributes()
 {
     $objectMock = $this->getMock(get_class($this->_object), array('prepareAttributeSetArray'));
     $objectMock->expects($this->once())->method('prepareAttributeSetArray')->will($this->returnValue(array('set_1')));
     $productTypeMock = $this->getMock('Xcom_Mapping_Model_Resource_Product_Type', array('getMappingProductTypeId'), array(), '', false);
     Mage::registerMockResourceModel('xcom_mapping/product_type', $productTypeMock);
     $productTypeMock->expects($this->once())->method('getMappingProductTypeId')->with($this->equalTo('set_1'))->will($this->returnValue('type_1'));
     $validatorMock = $this->mockModel('xcom_mapping/validator', array('validateIsRequiredAttributeHasMappedValue'));
     $validatorMock->expects($this->once())->method('validateIsRequiredAttributeHasMappedValue')->with($this->equalTo('type_1'), null, $this->equalTo('set_1'))->will($this->returnValue(false));
     $result = $objectMock->validateIsRequiredAttributeHasMappedValue();
     $this->assertTrue($result);
 }
Example #3
0
 protected function _mockCollection()
 {
     $methods = array('addFieldToFilter', 'addPriceData', 'load', 'addAttributeToSelect', 'joinProductQty');
     $collection = $this->getMock('Varien_Data_Collection', $methods);
     Mage::registerMockResourceModel('xcom_listing/product_collection', $collection);
     foreach (array($this->_productOne, $this->_productTwo) as $ob) {
         $collection->addItem($ob);
     }
     foreach ($methods as $method) {
         $collection->expects($this->any())->method($method)->will($this->returnValue($collection));
     }
     return $collection;
 }
Example #4
0
 /**
  * Mock collection resource model
  *
  * @param string $factoryString
  * @param ArrayIterator|array|null $items
  * @param array $methods
  * @return PHPUnit_Framework_MockObject_MockObject
  * @throws PHPUnit_Framework_Exception
  */
 public function mockCollection($factoryString, $items = null, $methods = array())
 {
     //$model = Mage::getModel($factoryString)->getCollection();
     $model = Mage::getResourceModel($factoryString . '_collection');
     if (!$model) {
         throw new PHPUnit_Framework_Exception(sprintf('Resource collection model "%s" not found.', $factoryString));
     }
     $class = get_class($model);
     $collectionMockBuilder = $this->getMockBuilder($class)->disableOriginalConstructor();
     if ($methods) {
         if ($items) {
             foreach (array('getIterator', 'getItems') as $method) {
                 if (false === array_search($method, $methods)) {
                     $methods[] = $method;
                 }
             }
         }
         $collectionMockBuilder->setMethods($methods);
     }
     $collection = $collectionMockBuilder->getMock();
     if ($items) {
         $collectionIterator = new Varien_Data_Collection();
         foreach ($items as &$item) {
             if (!$item instanceof Varien_Object) {
                 $item = new Varien_Object($item);
             }
             $collectionIterator->addItem($item);
         }
         $collection->expects($this->any())->method('getIterator')->will($this->returnValue($collectionIterator));
         $collection->expects($this->any())->method('getItems')->will($this->returnValue($items));
     }
     Mage::registerMockResourceModel($factoryString . '_collection', $collection);
     return $collection;
 }
 public function testMassDisableValidationActionValidateException()
 {
     $objectFixture = new Xcom_Mmp_Model_Resource_ChannelControllerTest_Fixture();
     Mage::registerMockResourceModel('xcom_mmp/channel', $objectFixture);
     $request = $this->_getRequest(true);
     $request->setParam('selected_channels', array(1));
     $response = new Varien_Object();
     $object = new Xcom_Mmp_Adminhtml_ChannelController($request, $response);
     $object->massDisableValidationAction();
     $this->assertContains('{"message":"Test Exception Message"}', $response->getBody());
 }