diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-03-30 16:36:04 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-03-30 16:36:04 +0400 |
commit | bb247aaa2598e50e26e3f1b31603b2e43fadd1fd (patch) | |
tree | 0457f4018b4a03f86069922932f39c5e66287cfc /plugins/SitesManager | |
parent | 0b08873d5c8a442facb82cdcbad5ce3b8130867d (diff) |
Fixes #1001 Adding currency setting per website
Defaulting currency to USD for all existing websites
Simplifying website admin screen by rolling all settings into the same form (still using ajax)
Adding SitesManager and UsersManager to the list of hidden plugins
Slightly refactored printing money values to accomodate per website preference
Diffstat (limited to 'plugins/SitesManager')
-rw-r--r-- | plugins/SitesManager/API.php | 131 | ||||
-rw-r--r-- | plugins/SitesManager/Controller.php | 25 | ||||
-rw-r--r-- | plugins/SitesManager/templates/SitesManager.js | 78 | ||||
-rw-r--r-- | plugins/SitesManager/templates/SitesManager.tpl | 79 | ||||
-rw-r--r-- | plugins/SitesManager/tests/SitesManager.test.php | 41 |
5 files changed, 282 insertions, 72 deletions
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index 5ffe6a7ae4..62d3196dd9 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -33,6 +33,7 @@ class Piwik_SitesManager_API const OPTION_EXCLUDED_IPS_GLOBAL = 'SitesManager_ExcludedIpsGlobal'; const OPTION_DEFAULT_TIMEZONE = 'SitesManager_DefaultTimezone'; + const OPTION_DEFAULT_CURRENCY = 'SitesManager_DefaultCurrency'; /** * Returns the javascript tag for the given idSite. @@ -226,7 +227,7 @@ class Piwik_SitesManager_API * * @return int the website ID created */ - public function addSite( $siteName, $urls, $excludedIps = null, $timezone = null ) + public function addSite( $siteName, $urls, $excludedIps = null, $timezone = null, $currency = null ) { Piwik::checkUserIsSuperUser(); @@ -242,6 +243,12 @@ class Piwik_SitesManager_API } $this->checkValidTimezone($timezone); + if(empty($currency)) + { + $currency = $this->getDefaultCurrency(); + } + $this->checkValidCurrency($currency); + $db = Zend_Registry::get('db'); $url = $urls[0]; @@ -254,6 +261,7 @@ class Piwik_SitesManager_API $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps); $bind['timezone'] = $timezone; + $bind['currency'] = $currency; $db->insert(Piwik::prefixTable("site"), $bind); $idSite = $db->lastInsertId(); @@ -339,6 +347,14 @@ class Piwik_SitesManager_API throw new Exception('The timezone "'.$timezone.'" is not valid. Please enter a valid timezone.'); } + private function checkValidCurrency($currency) + { + if(!in_array($currency, array_keys($this->getCurrencyList()))) + { + throw new Exception('The currency "'.$currency.'" is not valid. Please enter a valid currency symbol (USD, EUR, etc.)'); + } + } + /** * Checks that the submitted IPs (comma separated list) are valid * Returns the cleaned up IPs @@ -411,6 +427,36 @@ class Piwik_SitesManager_API } /** + * Returns the default currency that will be set when creating a website through the API. + * + * @return string Currency ID eg. 'USD' + */ + public function getDefaultCurrency() + { + Piwik::checkUserIsSuperUser(); + $defaultCurrency = Piwik_GetOption(self::OPTION_DEFAULT_CURRENCY); + if($defaultCurrency) + { + return $defaultCurrency; + } + return 'USD'; + } + + /** + * Sets the default currency that will be used when creating websites + * + * @param $defaultCurrency string eg. 'USD' + * @return bool + */ + public function setDefaultCurrency($defaultCurrency) + { + Piwik::checkUserIsSuperUser(); + $this->checkValidCurrency($defaultCurrency); + Piwik_SetOption(self::OPTION_DEFAULT_CURRENCY, $defaultCurrency); + return true; + } + + /** * Returns the default timezone that will be set when creating a website through the API. * Via the UI, if the default timezone is not UTC, it will be pre-selected in the drop down * @@ -430,7 +476,7 @@ class Piwik_SitesManager_API /** * Sets the default timezone that will be used when creating websites * - * @param $timezone string eg. Europe/Paris or UTC+8 + * @param $defaultTimezone string eg. Europe/Paris or UTC+8 * @return bool */ public function setDefaultTimezone($defaultTimezone) @@ -456,7 +502,7 @@ class Piwik_SitesManager_API * * @return bool true on success */ - public function updateSite( $idSite, $siteName, $urls = null, $excludedIps = null, $timezone = null) + public function updateSite( $idSite, $siteName, $urls = null, $excludedIps = null, $timezone = null, $currency = null) { Piwik::checkUserHasAdminAccess($idSite); @@ -474,7 +520,13 @@ class Piwik_SitesManager_API $bind['main_url'] = $url; } - + + if(!is_null($currency)) + { + $currency = trim($currency); + $this->checkValidCurrency($currency); + $bind['currency'] = $currency; + } if(!is_null($timezone)) { $timezone = trim($timezone); @@ -500,6 +552,77 @@ class Piwik_SitesManager_API } /** + * Returns the list of supported currencies + * @see getCurrencySymbols() + * @return array ( currencyId => currencyName) + */ + public function getCurrencyList() + { + return array( + 'USD' => 'US Dollar ($)', + 'EUR' => 'Euro (€)', + 'JPY' => 'Japanese Yen (¥)', + 'GBP' => 'British Pound Sterling (K£)', + 'AUD' => 'Australian Dollar (A$)', + 'KRW' => 'South Korean Won (₩)', + 'BRL' => 'Brazilian Real (R$)', + 'CNY' => 'Chinese Yuan Renminbi (CN¥)', + 'DKK' => 'Danish Krone (Dkr)', + 'RUB' => 'Russian Ruble (RUB)', + 'SEK' => 'Swedish Krona (Skr)', + 'NOK' => 'Norwegian Krone (Nkr)', + 'PLN' => 'Polish Zloty (zł)', + 'TRY' => 'Turkish Lira (TL)', + 'TWD' => 'New Taiwan Dollar (NT$)', + 'HKD' => 'Hong Kong Dollar (HK$)', + 'THB' => 'Thai Baht (฿)', + 'IDR' => 'Indonesian Rupiah (Rp)', + 'ARS' => 'Argentine Peso (AR$)', + 'MXN' => 'Mexican Peso (MXN)', + 'VND' => 'Vietnamese Dong (₫)', + 'PHP' => 'Philippine Peso (Php)', + 'INR' => 'Indian Rupee (Rs.)', + 'CHF' => 'Swiss Franc (Fr.)', + ); + } + + /** + * Returns the list of currency symbols + * @see getCurrencyList() + * @return array( currencyId => currencySymbol ) + */ + public function getCurrencySymbols() + { + return array( + 'USD' => '$', + 'EUR' => '€', + 'JPY' => '¥', + 'GBP' => 'UK£', + 'AUD' => 'A$', + 'KRW' => '₩', + 'BRL' => 'R$', + 'CNY' => 'CN¥', + 'DKK' => 'Dkr', + 'RUB' => 'RUB', + 'SEK' => 'Skr', + 'NOK' => 'Nkr', + 'PLN' => 'zł', + 'TRY' => 'TL', + 'TWD' => 'NT$', + 'HKD' => 'HK$', + 'THB' => '฿', + 'IDR' => 'Rp', + 'ARS' => 'AR$', + 'MXN' => 'MXN', + 'VND' => '₫', + 'PHP' => 'Php', + 'INR' => 'Rs.', + 'CHF' => 'Fr.', + ); + } + + + /** * Returns the list of timezones supported. * Used for addSite and updateSite * diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 140de42455..5c01f46e85 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -34,10 +34,14 @@ class Piwik_SitesManager_Controller extends Piwik_Controller } $view->timezoneSupported = Piwik::isTimezoneSupportEnabled(); $view->timezones = json_encode($timezones); + $view->defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone(); + + $view->currencies = json_encode(Piwik_SitesManager_API::getInstance()->getCurrencyList()); + $view->defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency(); + $view->utcTime = Piwik_Date::now()->getDatetime(); $excludedIpsGlobal = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal(); $view->globalExcludedIps = str_replace(',',"\n", $excludedIpsGlobal); - $view->defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone(); $view->currentIpAddress = Piwik_Common::getIpString(); $this->setGeneralVariablesView($view); @@ -45,6 +49,25 @@ class Piwik_SitesManager_Controller extends Piwik_Controller echo $view->render(); } + function setGlobalSettings() + { + $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format')); + + try { + $this->checkTokenInUrl(); + $timezone = Piwik_Common::getRequestVar('timezone', false); + $excludedIps = Piwik_Common::getRequestVar('excludedIps', false); + $currency = Piwik_Common::getRequestVar('currency', false); + Piwik_SitesManager_API::getInstance()->setDefaultTimezone($timezone); + Piwik_SitesManager_API::getInstance()->setDefaultCurrency($currency); + Piwik_SitesManager_API::getInstance()->setGlobalExcludedIps($excludedIps); + $toReturn = $response->getResponse(); + } catch(Exception $e ) { + $toReturn = $response->getResponseException( $e ); + } + echo $toReturn; + } + function displayJavascriptCode() { $idSite = Piwik_Common::getRequestVar('idsite', 1); diff --git a/plugins/SitesManager/templates/SitesManager.js b/plugins/SitesManager/templates/SitesManager.js index f60b0b615a..5d764fd4fb 100644 --- a/plugins/SitesManager/templates/SitesManager.js +++ b/plugins/SitesManager/templates/SitesManager.js @@ -24,7 +24,8 @@ function getAddSiteAJAX( row ) var urls = getApiFormatUrls(urls); var excludedIps = $(row).find('textarea#siteadd_excludedIps').val(); excludedIps = getApiFormatExcludedIps(excludedIps); - var timezone = encodeURIComponent($(row).find('option:selected').val()); + var timezone = encodeURIComponent($(row).find('#timezones option:selected').val()); + var currency = encodeURIComponent($(row).find('#currencies option:selected').val()); var request = ''; request += '&module=API'; @@ -33,6 +34,7 @@ function getAddSiteAJAX( row ) siteName = encodeURIComponent(siteName); request += '&siteName='+siteName; request += '&timezone='+timezone; + request += '¤cy='+currency; request += '&excludedIps='+excludedIps; $.each(urls, function (key,value){ request+= '&urls[]='+escape(value);} ); request += '&token_auth=' + piwik.token_auth; @@ -61,7 +63,8 @@ function getUpdateSiteAJAX( row ) urls = getApiFormatUrls(urls); var excludedIps = $(row).find('textarea#excludedIps').val(); excludedIps = getApiFormatExcludedIps(excludedIps); - var timezone = encodeURIComponent($(row).find('option:selected').val()); + var timezone = encodeURIComponent($(row).find('#timezones option:selected').val()); + var currency = encodeURIComponent($(row).find('#currencies option:selected').val()); var request = ''; request += '&module=API'; request += '&format=json'; @@ -70,6 +73,7 @@ function getUpdateSiteAJAX( row ) request += '&siteName='+siteName; request += '&idSite='+idSite; request += '&timezone='+timezone; + request += '¤cy='+currency; request += '&excludedIps='+excludedIps; $.each(urls, function (key,value){ if(value.length>1) request+= '&urls[]='+value;} ); request += '&token_auth=' + piwik.token_auth; @@ -79,29 +83,19 @@ function getUpdateSiteAJAX( row ) return ajaxRequest; } -function getDefaultTimezoneAJAX() +function getGlobalSettingsAJAX() { - var ajaxRequest = piwikHelper.getStandardAjaxConf('ajaxLoadingDefaultTimezone', 'ajaxErrorDefaultTimezone'); + var ajaxRequest = piwikHelper.getStandardAjaxConf('ajaxLoadingGlobalSettings', 'ajaxErrorGlobalSettings'); var timezone = encodeURIComponent($('#defaultTimezone option:selected').val()); - var request = ''; - request += '&module=API'; - request += '&format=json'; - request += '&method=SitesManager.setDefaultTimezone'; - request += '&defaultTimezone='+timezone; - request += '&token_auth=' + piwik.token_auth; - ajaxRequest.data = request; - return ajaxRequest; -} - -function getSetGlobalExcludedIpsAJAX() -{ - var ajaxRequest = piwikHelper.getStandardAjaxConf('ajaxLoadingExcludedIps', 'ajaxErrorExcludedIps'); + var currency = encodeURIComponent($('#defaultCurrency option:selected').val()); var excludedIps = $('textarea#globalExcludedIps').val(); excludedIps = getApiFormatExcludedIps(excludedIps); var request = ''; - request += '&module=API'; + request += 'module=SitesManager'; + request += '&action=setGlobalSettings'; request += '&format=json'; - request += '&method=SitesManager.setGlobalExcludedIps'; + request += '&timezone='+timezone; + request += '¤cy='+currency; request += '&excludedIps='+excludedIps; request += '&token_auth=' + piwik.token_auth; ajaxRequest.data = request; @@ -118,10 +112,11 @@ $(document).ready( function() { $(' <tr id="'+newRowId+'">\ <td> </td>\ - <td><input id="siteadd_name" value="Name" size="25" /></td>\ - <td><textarea cols="30" rows="3" id="siteadd_urls">http://siteUrl.com/\nhttp://siteUrl2.com/</textarea><br />'+aliasUrlsHelp+'</td>\ - <td><textarea cols="30" rows="3" id="siteadd_excludedIps"></textarea><br />'+excludedIpHelp+'</td>\ + <td><input id="siteadd_name" value="Name" size="15" /></td>\ + <td><textarea cols="25" rows="3" id="siteadd_urls">http://siteUrl.com/\nhttp://siteUrl2.com/</textarea><br />'+aliasUrlsHelp+'</td>\ + <td><textarea cols="20" rows="4" id="siteadd_excludedIps"></textarea><br />'+excludedIpHelp+'</td>\ <td>'+getTimezoneSelector(defaultTimezone)+'<br />' + timezoneHelp + '</td>\ + <td>'+getCurrencySelector(defaultCurrency)+'<br />' + currencyHelp + '</td>\ <td><img src="plugins/UsersManager/images/ok.png" class="addsite" href="#" /></td>\ <td><img src="plugins/UsersManager/images/remove.png" class="cancel" /></td>\ </tr>') @@ -160,20 +155,20 @@ $(document).ready( function() { var idName = $(n).attr('id'); if(idName == 'siteName') { - var contentAfter = '<input id="'+idName+'" value="'+contentBefore+'" size="25" />'; + var contentAfter = '<input id="'+idName+'" value="'+contentBefore+'" size="15" />'; $(n) .html(contentAfter) .keypress( submitSiteOnEnter ); } if(idName == 'urls') { - var contentAfter = '<textarea cols="30" rows="3" id="urls">'+contentBefore.replace(/<br *\/? *>/gi,"\n")+'</textarea>'; + var contentAfter = '<textarea cols="25" rows="3" id="urls">'+contentBefore.replace(/<br *\/? *>/gi,"\n")+'</textarea>'; contentAfter += '<br />'+aliasUrlsHelp; $(n).html(contentAfter); } if(idName == 'excludedIps') { - var contentAfter = '<textarea cols="30" rows="3" id="excludedIps">'+contentBefore.replace(/<br *\/? *>/gi,"\n")+'</textarea>'; + var contentAfter = '<textarea cols="20" rows="4" id="excludedIps">'+contentBefore.replace(/<br *\/? *>/gi,"\n")+'</textarea>'; contentAfter += '<br />'+excludedIpHelp; $(n).html(contentAfter); } @@ -183,6 +178,12 @@ $(document).ready( function() { contentAfter += '<br />' + timezoneHelp; $(n).html(contentAfter); } + if(idName == 'currency') + { + var contentAfter = getCurrencySelector(contentBefore); + contentAfter += '<br />' + currencyHelp; + $(n).html(contentAfter); + } } ); $(this) @@ -194,15 +195,12 @@ $(document).ready( function() { } ); - $('#globalExcludedIpsSubmit').click( function() { - $.ajax( getSetGlobalExcludedIpsAJAX() ); + $('#globalSettingsSubmit').click( function() { + $.ajax( getGlobalSettingsAJAX() ); }); $('#defaultTimezone').html( getTimezoneSelector(defaultTimezone)); - - $('#defaultTimezoneSubmit').click( function() { - $.ajax( getDefaultTimezoneAJAX() ); - }); + $('#defaultCurrency').html( getCurrencySelector(defaultCurrency)); $('td.editableSite').click( function(){ $(this).parent().find('.editSite').click(); } ); }); @@ -210,10 +208,6 @@ $(document).ready( function() { function getTimezoneSelector(selectedTimezone) { var html = '<select id="timezones">'; - if(!selectedTimezone) - { - html += '<option selected="selected" value="'+selectACity+'">'+selectACity+'</option>'; - } for(var continent in timezones) { html += '<optgroup label="' + continent + '">'; for(var timezoneId in timezones[continent]) { @@ -230,6 +224,20 @@ function getTimezoneSelector(selectedTimezone) } +function getCurrencySelector(selectedCurrency) +{ + var html = '<select id="currencies">'; + for(var currency in currencies) { + var selected = ''; + if(currency == selectedCurrency) { + selected = ' selected="selected" '; + } + html += '<option ' + selected + ' value="'+ currency + '">' + currencies[currency] + '</option>'; + } + html += '</select>'; + return html; +} + function submitSiteOnEnter(e) { var key=e.keyCode || e.which; diff --git a/plugins/SitesManager/templates/SitesManager.tpl b/plugins/SitesManager/templates/SitesManager.tpl index 43607ab226..7dcd768f3c 100644 --- a/plugins/SitesManager/templates/SitesManager.tpl +++ b/plugins/SitesManager/templates/SitesManager.tpl @@ -22,11 +22,17 @@ var aliasUrlsHelp = '{'SitesManager_AliasUrlHelp'|translate|inlineHelp|escape:ja <br /><br />{'SitesManager_ChangingYourTimezoneWillOnlyAffectDataForward'|translate} {/capture} +{capture assign=currencyHelpPlain} + {'SitesManager_CurrencySymbolWillBeUsedForGoals'|translate|inlineHelp} +{/capture} + var timezoneHelp = '{$timezoneHelpPlain|inlineHelp|escape:javascript}'; +var currencyHelp = '{$currencyHelpPlain|escape:javascript}'; {assign var=defaultTimezoneHelp value=$defaultTimezoneHelpPlain|inlineHelp}; var timezones = {$timezones}; +var currencies = {$currencies}; var defaultTimezone = '{$defaultTimezone}'; -var selectACity = '{'SitesManager_SelectCity'|translate}'; +var defaultCurrency = '{$defaultCurrency}'; </script> <script type="text/javascript" src="plugins/SitesManager/templates/SitesManager.js"></script> @@ -51,13 +57,20 @@ var selectACity = '{'SitesManager_SelectCity'|translate}'; option, select { font-size:11px; } + +.globalSettings td { +vertical-align:top; +} +.globalSettings .ui-inline-help { +margin-top:0; +} </style> {/literal} <h2>{'SitesManager_WebsitesManagement'|translate}</h2> <p>{'SitesManager_MainDescription'|translate} {if $isSuperUser} -<br/>{'SitesManager_SuperUserCan'|translate:"<a href='#globalIpExclusion'>":"</a>":"<a href='#defaultTimezone'>":"</a>"} +<br/>{'SitesManager_SuperUserCan'|translate:"<a href='#globalSettings'>":"</a>"} {/if} </p> {ajaxErrorDiv} @@ -75,6 +88,7 @@ option, select { <th>{'SitesManager_Urls'|translate}</th> <th>{'SitesManager_ExcludedIps'|translate}</th> <th>{'SitesManager_Timezone'|translate}</th> + <th>{'SitesManager_Currency'|translate}</th> <th> </th> <th> </th> <th> {'SitesManager_JsTrackingTag'|translate} </th> @@ -88,6 +102,7 @@ option, select { <td id="urls" class="editableSite">{foreach from=$site.alias_urls item=url}{$url}<br />{/foreach}</td> <td id="excludedIps" class="editableSite">{foreach from=$site.excluded_ips item=ip}{$ip}<br />{/foreach}</td> <td id="timezone" class="editableSite">{$site.timezone}</td> + <td id="currency" class="editableSite">{$site.currency}</td> <td><img src='plugins/UsersManager/images/edit.png' class="editSite" id="row{$i}" href='#' title="{'General_Edit'|translate}" /></td> <td><img src='plugins/UsersManager/images/remove.png' class="deleteSite" id="row{$i}" title="{'General_Delete'|translate}" value="{'General_Delete'|translate}" /></td> <td><a href='{url action=displayJavascriptCode idsite=$site.idsite}'>{'SitesManager_ShowTrackingTag'|translate}</a></td> @@ -101,28 +116,46 @@ option, select { {/if} {if $isSuperUser} - <a name='globalIpExclusion'></a><h2>{'SitesManager_GlobalListExcludedIps'|translate}</h2> - <p>{'SitesManager_ListOfIpsToBeExcludedOnAllWebsites'|translate} </p> - {ajaxErrorDiv id=ajaxErrorExcludedIps} - {ajaxLoadingDiv id=ajaxLoadingExcludedIps} - <textarea cols="30" rows="3" id="globalExcludedIps">{$globalExcludedIps} - </textarea><br/> - {$excludedIpHelp} - <input type="hidden" name="token_auth" value="{$token_auth}" /> - <p><input type="submit" class="submit" id='globalExcludedIpsSubmit' value="{'General_Save'|translate}" /></p> - - - <a name='defaultTimezone'></a><h2>{'SitesManager_DefaultTimezone'|translate}</h2> - <p>{'SitesManager_SelectDefaultTimezone'|translate} - {ajaxErrorDiv id=ajaxErrorDefaultTimezone} - {ajaxLoadingDiv id=ajaxLoadingDefaultTimezone} - <div id='defaultTimezone'></div> +<br/> + <a name='globalSettings'></a> + <h2>{'SitesManager_GlobalWebsitesSettings'|translate}</h2> <br/> - {$defaultTimezoneHelp} - <input type="hidden" name="token_auth" value="{$token_auth}" /> - <p><input type="submit" class="submit" id='defaultTimezoneSubmit' value="{'General_Save'|translate}" /></p> - - + {ajaxErrorDiv id=ajaxErrorGlobalSettings} + {ajaxLoadingDiv id=ajaxLoadingGlobalSettings} + <table width='600px' class='globalSettings'> + + <tr><td colspan="2"> + <b>{'SitesManager_GlobalListExcludedIps'|translate}</b> + <p>{'SitesManager_ListOfIpsToBeExcludedOnAllWebsites'|translate} </p> + </td></tr> + <tr><td> + <textarea cols="30" rows="3" id="globalExcludedIps">{$globalExcludedIps} +</textarea> + </td><td> + {$excludedIpHelp} + </td></tr> + + <tr><td colspan="2"> + <b>{'SitesManager_DefaultTimezone'|translate}</b> + <p>{'SitesManager_SelectDefaultTimezone'|translate} </p> + </td></tr> + <tr><td> + <div id='defaultTimezone'></div> + </td><td> + {$defaultTimezoneHelp} + </td></tr> + + <tr><td colspan="2"> + <b>{'SitesManager_DefaultCurrency'|translate}</b> + <p>{'SitesManager_SelectDefaultCurrency'|translate} </p> + </td></tr> + <tr><td> + <div id='defaultCurrency'></div> + </td><td> + {$currencyHelpPlain} + </td></tr> + </table> + <p><input type="submit" class="submit" id='globalSettingsSubmit' value="{'General_Save'|translate}" /></p> {/if} <br /><br /><br /><br /> diff --git a/plugins/SitesManager/tests/SitesManager.test.php b/plugins/SitesManager/tests/SitesManager.test.php index 642a6cf970..941e4f136b 100644 --- a/plugins/SitesManager/tests/SitesManager.test.php +++ b/plugins/SitesManager/tests/SitesManager.test.php @@ -110,14 +110,16 @@ class Test_Piwik_SitesManager extends Test_Database /** * Test with valid IPs */ - public function test_addSite_excludedIpsAndtimezone_valid() + public function test_addSite_excludedIpsAndtimezoneAndCurrency_valid() { $ips = '1.2.3.4,1.1.1.*,1.2.*.*,1.*.*.*'; $timezone = 'Europe/Paris'; - $idsite = Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/", $ips, $timezone); + $currency = 'EUR'; + $idsite = Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/", $ips, $timezone, $currency); $siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite); $this->assertEqual($siteInfo['excluded_ips'], $ips); $this->assertEqual($siteInfo['timezone'], $timezone); + $this->assertEqual($siteInfo['currency'], $currency); } /** @@ -487,8 +489,8 @@ class Test_Piwik_SitesManager extends Test_Database $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org")); $resultWanted = array( - 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => "", 'timezone' => 'UTC'), - 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => "", 'timezone' => 'UTC'), + 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => "", 'timezone' => 'UTC', 'currency' => 'USD'), + 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => "", 'timezone' => 'UTC', 'currency' => 'USD'), ); FakeAccess::setIdSitesAdmin (array(1,3)); @@ -523,8 +525,8 @@ class Test_Piwik_SitesManager extends Test_Database $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org")); $resultWanted = array( - 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => "", 'timezone' => 'UTC'), - 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => "", 'timezone' => 'UTC'), + 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => "", 'timezone' => 'UTC', 'currency' => 'USD'), + 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => "", 'timezone' => 'UTC', 'currency' => 'USD'), ); FakeAccess::setIdSitesView (array(1,3)); @@ -559,8 +561,8 @@ class Test_Piwik_SitesManager extends Test_Database $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org")); $resultWanted = array( - 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => "", 'timezone' => 'UTC'), - 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => "", 'timezone' => 'UTC'), + 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => "", 'timezone' => 'UTC', 'currency' => 'USD'), + 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => "", 'timezone' => 'UTC', 'currency' => 'USD'), ); FakeAccess::setIdSitesView (array(1,3)); @@ -708,24 +710,45 @@ class Test_Piwik_SitesManager extends Test_Database $this->pass(); } - function test_setDefaultTimezone() + function test_addSites_invalidCurrency() + { + $invalidCurrency = '€'; + try { + $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'), '', 'UTC', $invalidCurrency); + $this->fail('invalid currency should raise an exception'); + } catch(Exception $e) { + } + $this->pass(); + } + + function test_setDefaultTimezoneAndCurrency() { $defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone(); $this->assertEqual($defaultTimezone, 'UTC'); + $defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency(); + $this->assertEqual($defaultCurrency, 'USD'); $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'), ''); $site = new Piwik_Site($idsite); $this->assertEqual($site->getTimezone(), 'UTC'); + $this->assertEqual($site->getCurrency(), 'USD'); $newDefaultTimezone = 'UTC+5.5'; Piwik_SitesManager_API::getInstance()->setDefaultTimezone($newDefaultTimezone); $defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone(); $this->assertEqual($defaultTimezone, $newDefaultTimezone); + + $newDefaultCurrency = 'EUR'; + Piwik_SitesManager_API::getInstance()->setDefaultCurrency($newDefaultCurrency); + $defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency(); + $this->assertEqual($defaultCurrency, $newDefaultCurrency); $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'), '', $newDefaultTimezone); $site = new Piwik_Site($idsite); $this->assertEqual($site->getTimezone(), $newDefaultTimezone); $this->assertEqual($site->getCreationDate(), date('Y-m-d')); + $this->assertEqual($site->getCurrency(), $newDefaultCurrency); } + } |