/** * @covers sAdmin::sGetCountryTranslation */ public function testsGetCountryTranslation() { // Backup existing data and inject demo data $existingData = Shopware()->Db()->fetchRow("\n SELECT * FROM s_core_translations\n WHERE objecttype = 'config_countries' AND objectlanguage = 2\n "); $demoData = array('objectkey' => 1, 'objectlanguage' => 2, 'objecttype' => 'config_countries', 'objectdata' => serialize(array(2 => array('active' => '1', 'countryname' => 'Germany'), 5 => array('active' => '1', 'countryname' => 'Belgium')))); 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->sGetCountryTranslation(); $this->assertCount(2, $result); $this->assertArrayHasKey(2, $result); $this->assertArrayHasKey(5, $result); $this->assertArrayHasKey('active', $result[2]); $this->assertArrayHasKey('countryname', $result[2]); $this->assertEquals(1, $result[2]['active']); $this->assertEquals('Germany', $result[2]['countryname']); $this->assertArrayHasKey('active', $result[5]); $this->assertArrayHasKey('countryname', $result[5]); $this->assertEquals(1, $result[5]['active']); $this->assertEquals('Belgium', $result[5]['countryname']); // Test with just one country $result = $this->module->sGetCountryTranslation(array('id' => 2, 'randomField' => 'randomValue')); $this->assertCount(4, $result); $this->assertArrayHasKey('id', $result); $this->assertArrayHasKey('active', $result); $this->assertArrayHasKey('countryname', $result); $this->assertArrayHasKey('randomField', $result); $this->assertEquals(2, $result['id']); $this->assertEquals(1, $result['active']); $this->assertEquals('Germany', $result['countryname']); $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::sGetCountryTranslation */ public function testsGetCountryTranslation() { // Backup existing data and inject demo data $existingData = Shopware()->Db()->fetchRow("\n SELECT * FROM s_core_translations\n WHERE objecttype = 'config_countries' AND objectlanguage = 2\n "); $demoData = array('objectkey' => 1, 'objectlanguage' => 2, 'objecttype' => 'config_countries', 'objectdata' => 'a:2:{i:2;a:2:{s:6:"active";s:1:"1";s:11:"countryname";s:7:"Germany";}i:5;a:2:{s:6:"active";s:1:"1";s:11:"countryname";s:7:"Belgium";}}'); 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->systemModule->sLanguage = 2; $result = $this->module->sGetCountryTranslation(); $this->assertCount(2, $result); $this->assertArrayHasKey(2, $result); $this->assertArrayHasKey(5, $result); $this->assertArrayHasKey('active', $result[2]); $this->assertArrayHasKey('countryname', $result[2]); $this->assertEquals(1, $result[2]['active']); $this->assertEquals('Germany', $result[2]['countryname']); $this->assertArrayHasKey('active', $result[5]); $this->assertArrayHasKey('countryname', $result[5]); $this->assertEquals(1, $result[5]['active']); $this->assertEquals('Belgium', $result[5]['countryname']); // Test with just one country $result = $this->module->sGetCountryTranslation(array('id' => 2, 'randomField' => 'randomValue')); $this->assertCount(4, $result); $this->assertArrayHasKey('id', $result); $this->assertArrayHasKey('active', $result); $this->assertArrayHasKey('countryname', $result); $this->assertArrayHasKey('randomField', $result); $this->assertEquals(2, $result['id']); $this->assertEquals(1, $result['active']); $this->assertEquals('Germany', $result['countryname']); $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); } }