Using PHPUnit in a Zend Framework application, how can I get the locale to be used for this test?

I am testing a multilingual site with phpunit. One of the tests that I want to perform is that the application will determine the user's locale and automatically redirect.

That is, the user accesses the site in /. The application detects that they are from France and redirects to / fr -FR /

The application does do it, but trying to write a unit test for this seems impossible. I need to fake locale for test purposes. Can anyone advise?

+3
source share
2 answers

The solution was to make the code more testable.

:

    $locale = new Zend_Locale();

    $locale->setLocale('fr_FR');
    Zend_Registry::set('Zend_Locale', $locale); 

:

    $locale = Zend_Locale::findLocale(); 
    $locale = new Zend_Locale($locale);

. findLocale Zend_Registry .

+4

, Accept-Language, . PHP $_SERVER['HTTP_ACCEPT_LANGUAGE']. , :

$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
+2

Source: https://habr.com/ru/post/1766044/


All Articles