/** * @covers sAdmin::sGetDispatchTranslation */ public function testsGetDispatchTranslation() { // Backup existing data and inject demo data $existingData = Shopware()->Db()->fetchRow("\n SELECT * FROM s_core_translations\n WHERE objecttype = 'config_dispatch' AND objectlanguage = 2\n "); $demoData = array('objectkey' => 1, 'objectlanguage' => 2, 'objecttype' => 'config_dispatch', 'objectdata' => serialize(array(9 => array('dispatch_name' => 'Standard shipping', 'dispatch_description' => 'Standard shipping description', 'dispatch_status_link' => 'http://www.dhl.com'), 10 => array('dispatch_name' => 'Shipping by weight', 'dispatch_description' => 'Shipping by weight description', 'dispatch_status_link' => 'url')))); if ($existingData) { Shopware()->Db()->update('s_core_translations', $demoData, 'id = ' . $existingData['id']); } else { Shopware()->Db()->insert('s_core_translations', $demoData); } // Test loading all data, should return the test data $shopId = Shopware()->Container()->get('shopware_storefront.context_service')->getShopContext()->getShop()->getId(); Shopware()->Container()->get('shopware_storefront.context_service')->getShopContext()->getShop()->setId(2); $result = $this->module->sGetDispatchTranslation(); $this->assertCount(2, $result); $this->assertArrayHasKey(9, $result); $this->assertArrayHasKey(10, $result); $this->assertArrayHasKey('dispatch_name', $result[9]); $this->assertArrayHasKey('dispatch_description', $result[9]); $this->assertArrayHasKey('dispatch_status_link', $result[9]); $this->assertArrayHasKey('dispatch_name', $result[10]); $this->assertArrayHasKey('dispatch_description', $result[10]); $this->assertArrayHasKey('dispatch_status_link', $result[10]); $this->assertEquals('Standard shipping', $result[9]['dispatch_name']); $this->assertEquals('Standard shipping description', $result[9]['dispatch_description']); $this->assertEquals('http://www.dhl.com', $result[9]['dispatch_status_link']); $this->assertEquals('Shipping by weight', $result[10]['dispatch_name']); $this->assertEquals('Shipping by weight description', $result[10]['dispatch_description']); $this->assertEquals('url', $result[10]['dispatch_status_link']); // Test with just one shipping method $result = $this->module->sGetDispatchTranslation(array('id' => 9, 'randomField' => 'randomValue')); $this->assertCount(5, $result); $this->assertArrayHasKey('id', $result); $this->assertArrayHasKey('name', $result); $this->assertArrayHasKey('description', $result); $this->assertArrayHasKey('status_link', $result); $this->assertArrayHasKey('randomField', $result); $this->assertEquals(9, $result['id']); $this->assertEquals('Standard shipping', $result['name']); $this->assertEquals('Standard shipping description', $result['description']); $this->assertEquals('http://www.dhl.com', $result['status_link']); $this->assertEquals('randomValue', $result['randomField']); // If backup data exists, restore it if ($existingData) { $existingDataId = $existingData['id']; unset($existingData['id']); Shopware()->Db()->update('s_core_translations', $existingData, 'id = ' . $existingDataId); } Shopware()->Container()->get('shopware_storefront.context_service')->getShopContext()->getShop()->setId($shopId); }
/** * @covers sAdmin::sGetDispatchTranslation */ public function testsGetDispatchTranslation() { // Backup existing data and inject demo data $existingData = Shopware()->Db()->fetchRow("\n SELECT * FROM s_core_translations\n WHERE objecttype = 'config_dispatch' AND objectlanguage = 2\n "); $demoData = array('objectkey' => 1, 'objectlanguage' => 2, 'objecttype' => 'config_dispatch', 'objectdata' => 'a:2:{i:9;a:3:{s:13:"dispatch_name";s:17:"Standard shipping";s:20:"dispatch_description";s:29:"Standard shipping description";s:20:"dispatch_status_link";s:18:"http://www.dhl.com";}i:10;a:3:{s:13:"dispatch_name";s:18:"Shipping by weight";s:20:"dispatch_description";s:30:"Shipping by weight description";s:20:"dispatch_status_link";s:3:"url";}}'); if ($existingData) { Shopware()->Db()->update('s_core_translations', $demoData, 'id = ' . $existingData['id']); } else { Shopware()->Db()->insert('s_core_translations', $demoData); } // Test loading all data, should return the test data $this->module->sSYSTEM->sLanguage = 2; $result = $this->module->sGetDispatchTranslation(); $this->assertCount(2, $result); $this->assertArrayHasKey(9, $result); $this->assertArrayHasKey(10, $result); $this->assertArrayHasKey('dispatch_name', $result[9]); $this->assertArrayHasKey('dispatch_description', $result[9]); $this->assertArrayHasKey('dispatch_status_link', $result[9]); $this->assertArrayHasKey('dispatch_name', $result[10]); $this->assertArrayHasKey('dispatch_description', $result[10]); $this->assertArrayHasKey('dispatch_status_link', $result[10]); $this->assertEquals('Standard shipping', $result[9]['dispatch_name']); $this->assertEquals('Standard shipping description', $result[9]['dispatch_description']); $this->assertEquals('http://www.dhl.com', $result[9]['dispatch_status_link']); $this->assertEquals('Shipping by weight', $result[10]['dispatch_name']); $this->assertEquals('Shipping by weight description', $result[10]['dispatch_description']); $this->assertEquals('url', $result[10]['dispatch_status_link']); // Test with just one shipping method $result = $this->module->sGetDispatchTranslation(array('id' => 9, 'randomField' => 'randomValue')); $this->assertCount(5, $result); $this->assertArrayHasKey('id', $result); $this->assertArrayHasKey('name', $result); $this->assertArrayHasKey('description', $result); $this->assertArrayHasKey('status_link', $result); $this->assertArrayHasKey('randomField', $result); $this->assertEquals(9, $result['id']); $this->assertEquals('Standard shipping', $result['name']); $this->assertEquals('Standard shipping description', $result['description']); $this->assertEquals('http://www.dhl.com', $result['status_link']); $this->assertEquals('randomValue', $result['randomField']); // If backup data exists, restore it if ($existingData) { $existingDataId = $existingData['id']; unset($existingData['id']); Shopware()->Db()->update('s_core_translations', $existingData, 'id = ' . $existingDataId); } }