public function testEncodeStaticUrlsInsertingNewRecords() { $aStaticUrl = array('oxseo__oxseourl' => array('de/de', 'eng/eng'), 'oxseo__oxstdurl' => 'xxx', 'oxseo__oxobjectid' => '-1'); $oEncoder = $this->getMock('oxSeoEncoder', array('_getUniqueSeoUrl', '_trimUrl')); $oEncoder->expects($this->exactly(2))->method('_getUniqueSeoUrl')->will($this->returnValue('yyy')); $oEncoder->expects($this->atLeastOnce())->method('_trimUrl')->will($this->returnValue('yyy')); $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('execute')->will($this->returnCallback(array($this, 'fillDbQueryBuffer'))); oxDb::setDbObject($dbMock); $oEncoder->encodeStaticUrls($aStaticUrl, 1, 0); $this->assertEquals(1, count($this->dbQueryBuffer)); $sQ = "insert into oxseo ( oxobjectid, oxident, oxshopid, oxlang, oxstdurl, oxseourl, oxtype ) values "; $sQ .= "( '" . md5('1yyy') . "', '" . md5('yyy') . "', '1', '0', 'yyy', 'yyy', 'static' ), "; $sQ .= "( '" . md5('1yyy') . "', '" . md5('yyy') . "', '1', '1', 'yyy', 'yyy', 'static' ) "; $this->assertEquals($sQ, $this->dbQueryBuffer[0]); }
/** * DynExportBase::InitArticle() test case * * @return null */ public function testInitArticleProductIsNotAwailable() { $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('selectLimit')->will($this->returnCallback(function ($s, $i, $c) { throw new Exception($s . $i . $c); })); oxDb::setDbObject($dbMock); $oView = new _DynExportBase(); $blClose = true; try { $oView->initArticle("testdynexportbasetable", 0, $blClose); } catch (Exception $oExcp) { $this->assertEquals("select oxid from testdynexportbasetable10", $oExcp->getMessage(), "Error in DynExportBase::InitArticle()"); return; } $this->fail("Error in DynExportBase::InitArticle()"); }
/** * Test get filter sql. * * @return null */ public function testGetFilterSql() { $sCatId = $this->getTestConfig()->getShopEdition() == 'EE' ? '30e44ab85808a1f05.26160932' : '8a142c3e60a535f16.78077188'; $oTest = $this->getProxyClass('oxArticleList'); $sRes = ''; $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('getAll')->will($this->returnCallback(function ($s) { throw new Exception($s); })); oxDb::setDbObject($dbMock); try { $oTest->UNITgetFilterSql($sCatId, array("8a142c3ee0edb75d4.80743302" => "Zeiger", "8a142c3e9cd961518.80299776" => "originell")); } catch (Exception $e) { $sRes = $e->getMessage(); } $this->setLanguage(0); modDB::getInstance()->cleanup(); $sO2CView = getViewName('oxobject2category'); $sO2AView = getViewName('oxobject2attribute'); $sExpt = "select oc.oxobjectid as oxobjectid, count(*)as cnt from\n (SELECT * FROM {$sO2CView} WHERE {$sO2CView}.oxcatnid='{$sCatId}' GROUP BY {$sO2CView}.oxobjectid, {$sO2CView}.oxcatnid) as oc\n INNER JOIN {$sO2AView} as oa ON(oa.oxobjectid=oc.oxobjectid)\n WHERE (oa.oxattrid='8a142c3ee0edb75d4.80743302' and oa.oxvalue='Zeiger')\n or (oa.oxattrid='8a142c3e9cd961518.80299776'andoa.oxvalue='originell')\n GROUPBY oa.oxobjectid\n HAVING cnt=2"; $sExpt = str_replace(array("\n", "\r", " ", "\t"), "", $sExpt); $sRes = str_replace(array("\n", "\r", " ", "\t"), "", $sRes); $this->assertEquals($sExpt, $sRes); }
/** * test */ public function testGetBannerArticle_Existing() { $dbMock = $this->getBannerArticleMockWithSpecificReturn('2000'); oxDb::setDbObject($dbMock); $oArticle = $this->getMock('stdclass', array('load')); $oArticle->expects($this->once())->method('load')->with($this->equalTo('2000'))->will($this->returnValue(true)); oxTestModules::addModuleObject('oxarticle', $oArticle); $oPromo = oxNew('oxActions'); $oPromo->setId('promoid'); $oArt = $oPromo->getBannerArticle(); $this->assertNotNull($oArt); $this->assertSame($oArticle, $oArt); }
/** * base test */ public function testInsert() { $oObj = $this->getMock('oxi18n', array('_getLanguageSetTables')); $oObj->expects($this->any())->method('_getLanguageSetTables')->will($this->returnValue(array('oxstates_set11'))); $oObj->init('oxstates'); $oObj->setId("test_insert"); $oObj->oxstates__oxtitle = new oxField('test_x'); $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('select')->will($this->returnValue(false)); $dbMock->expects($this->any())->method('execute')->will($this->evalFunction('{Unit_Core_oxi18ntest::$aLoggedSqls[] = $args[0];return true;}')); oxDb::setDbObject($dbMock); $oObj->setLanguage(0); Unit_Core_oxi18ntest::$aLoggedSqls = array(); $oObj->UNITinsert(); $this->assertEquals(array("Insert into oxstates set oxid = 'test_insert',oxcountryid = '',oxtitle = 'test_x',oxisoalpha2 = ''", "insert into oxstates_set11 set oxid = 'test_insert'"), array_map('trim', Unit_Core_oxi18ntest::$aLoggedSqls)); $oObj->setLanguage(90); Unit_Core_oxi18ntest::$aLoggedSqls = array(); $oObj->UNITinsert(); $this->assertEquals(array("Insert into oxstates set oxid = 'test_insert',oxcountryid = '',oxisoalpha2 = ''", "insert into oxstates_set11 set oxid = 'test_insert',oxtitle_90 = 'test_x'"), array_map('trim', Unit_Core_oxi18ntest::$aLoggedSqls)); }
/** * oxActionList::areAnyActivePromotions() test case * test if return value is in the true case "true" and the other way around. * * @dataProvider testAreAnyActivePromotionsDataProvider */ public function testAreAnyActivePromotions($response, $expected) { $sShopId = $this->getConfig()->getShopId(); $sView = getViewName('oxactions'); $sSql = "select 1 from {$sView} where oxtype=2 and oxactive=1 and oxshopid='" . $sShopId . "' limit 1"; $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('getOne')->with($this->equalTo($sSql))->will($this->returnValue($response)); oxDb::setDbObject($dbMock); $oAL = oxNew('oxActionList'); $this->assertEquals($expected, $oAL->areAnyActivePromotions()); }
/** * base functionality test */ public function testGetMissingTemplateBlocksIfFound() { $oCfg = $this->getMock('oxconfig', array('getShopId')); $oCfg->expects($this->exactly(1))->method('getShopId')->will($this->returnValue(15)); oxTestModules::addModuleObject('oxconfig', $oCfg); $oRs = $this->getMock('stdclass', array('moveNext', 'recordCount')); $oRs->expects($this->exactly(1))->method('moveNext')->will($this->evalFunction('{$_this->EOF = true;}')); $oRs->expects($this->exactly(1))->method('recordCount')->will($this->returnValue(1)); $oRs->fields = array('OXTEMPLATE' => '_OXTEMPLATE_', 'OXBLOCKNAME' => '_OXBLOCKNAME_', 'OXMODULE' => '_OXMODULE_'); $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('execute')->with($this->equalTo("select * from oxtplblocks where oxactive=1 and oxshopid='15'"))->will($this->returnValue($oRs)); oxDb::setDbObject($dbMock); $oSR = $this->getMock('oxSysRequirements', array('_checkTemplateBlock')); $oSR->expects($this->exactly(1))->method('_checkTemplateBlock')->with($this->equalTo("_OXTEMPLATE_"), $this->equalTo("_OXBLOCKNAME_"))->will($this->returnValue(true)); $this->assertEquals(array(), $oSR->getMissingTemplateBlocks()); }
/** * Test in price category with exception case. * * @return null */ public function testInPriceCategoryException() { $oA = oxNew('oxArticle'); $oA->setId('_testx'); $oA->oxarticles__oxprice = new oxField(95); $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('getOne')->will($this->returnCallback(function ($s) { throw new Exception($s); })); oxDb::setDbObject($dbMock); try { $oA->inPriceCategory('sCatNid'); } catch (Exception $e) { if ($this->getConfig()->getEdition() === 'EE') { $this->assertEquals("select 1 from oxv_oxcategories_1_de where oxid='sCatNid' and( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= '95' and oxpriceto >= '95') or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= '95') or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= '95'))", $e->getMessage()); } else { $this->assertEquals("select 1 from oxv_oxcategories_de where oxid='sCatNid' and( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= '95' and oxpriceto >= '95') or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= '95') or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= '95'))", $e->getMessage()); } return; } $this->fail('exception from oxdb not thrown'); }
public function testCheckAccessRightsChecksSubshopAdminShop() { $mySession = oxRegistry::getSession(); $backUpAuth = $mySession->getVariable("auth"); $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->any())->method('getOne')->will($this->returnValue(1)); oxDb::setDbObject($dbMock); $e = null; try { $mySession->setVariable("auth", "blafooUser"); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('fnc', 'chshp'); $this->assertEquals(false, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('fnc', null); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('actshop', 1); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('actshop', 2); $this->assertEquals(false, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('actshop', null); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('shp', 1); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('shp', 2); $this->assertEquals(false, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('shp', null); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('currentadminshop', 1); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('currentadminshop', 2); $this->assertEquals(false, oxRegistry::getUtils()->checkAccessRights()); $this->setRequestParameter('currentadminshop', null); $this->assertEquals(true, oxRegistry::getUtils()->checkAccessRights()); } catch (Exception $e) { } $mySession->setVariable("auth", $backUpAuth); if ($e) { throw $e; } }
/** * Test IsPicDeletable with nopic.jpg case. */ public function testIsPicDeletableNoPic() { $myUtils = oxNew('oxUtilsPic'); $dbMock = $this->getDbObjectMock(); $dbMock->expects($this->never())->method('getOne'); oxDb::setDbObject($dbMock); $this->assertEquals(false, $myUtils->UNITisPicDeletable('nopic.jpg', 'test', 'file')); }