<commit_before><?php

namespace SimpleSAML\Test\Locale;

use SimpleSAML\Locale\Language;

class LanguageTest extends \PHPUnit_Framework_TestCase
{


    /**
     * Test SimpleSAML\Locale\Language::getDefaultLanguage().
     */
    public function testGetDefaultLanguage()
    {
        // test default
        $c = \SimpleSAML_Configuration::loadFromArray(array());
        $l = new Language($c);
        $this->assertEquals('en', $l->getDefaultLanguage());

        // test defaults coming from configuration
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('xx', 'yy', 'zz'),
            'language.default' => 'yy',
        ));
        $l = new Language($c);
        $this->assertEquals('yy', $l->getDefaultLanguage());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageCookie().
     */
    public function testGetLanguageCookie()
    {
        // test it works when no cookie is set
        \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $this->assertNull(Language::getLanguageCookie());

        // test that it works fine with defaults
        \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $_COOKIE['language'] = 'en';
        $this->assertEquals('en', Language::getLanguageCookie());

        // test that it works with non-defaults
        \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('xx', 'yy', 'zz'),
            'language.cookie.name' => 'xyz'
        ), '', 'simplesaml');
        $_COOKIE['xyz'] = 'Yy'; // test values are converted to lowercase too
        $this->assertEquals('yy', Language::getLanguageCookie());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageList().
     */
    public function testGetLanguageList()
    {
        // test defaults
        $c = \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('en');
        $this->assertEquals(array('en' => true), $l->getLanguageList());

        // test non-defaults
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('xx', 'yy', 'zz'),
        ), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('yy');
        $this->assertEquals(array(
            'xx' => false,
            'yy' => true,
            'zz' => false,
        ), $l->getLanguageList());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageParameterName().
     */
    public function testGetLanguageParameterName()
    {
        // test for default configuration
        $c = \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $l = new Language($c);
        $this->assertEquals('language', $l->getLanguageParameterName());

        // test for valid configuration
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.parameter.name' => 'xyz'
        ), '', 'simplesaml');
        $l = new Language($c);
        $this->assertEquals('xyz', $l->getLanguageParameterName());
    }


    /**
     * Test SimpleSAML\Locale\Language::isLanguageRTL().
     */
    public function testIsLanguageRTL()
    {
        // test defaults
        $c = \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('en');
        $this->assertFalse($l->isLanguageRTL());

        // test non-defaults, non-RTL
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.rtl' => array('xx', 'yy', 'zz'),
        ), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('en');
        $this->assertFalse($l->isLanguageRTL());

        // test non-defaults, RTL
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('xx', 'yy', 'zz', 'en'),
            'language.rtl' => array('xx', 'yy'),
        ), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('yy');
        $this->assertTrue($l->isLanguageRTL());
    }


    /**
     * Test SimpleSAML\Locale\Language::setLanguage().
     */
    public function testSetLanguage()
    {
        // test with valid configuration, no cookies set
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('xx', 'yy', 'zz'),
            'language.parameter.name' => 'xyz',
            'language.parameter.setcookie' => false,
        ), '', 'simplesaml');
        $_GET['xyz'] = 'Zz'; // test also that lang code is transformed to lower caps
        $l = new Language($c);
        $this->assertEquals('zz', $l->getLanguage());

        // test with valid configuration, no cookies, language set unavailable
        $_GET['xyz'] = 'unavailable';
        $l = new Language($c);
        $this->assertEquals('en', $l->getLanguage());
    }
}<commit_msg>Fix tests depending on Language->language_names<commit_after><?php

namespace SimpleSAML\Test\Locale;

use SimpleSAML\Locale\Language;

class LanguageTest extends \PHPUnit_Framework_TestCase
{


    /**
     * Test SimpleSAML\Locale\Language::getDefaultLanguage().
     */
    public function testGetDefaultLanguage()
    {
        // test default
        $c = \SimpleSAML_Configuration::loadFromArray(array());
        $l = new Language($c);
        $this->assertEquals('en', $l->getDefaultLanguage());

        // test defaults coming from configuration
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('en', 'es', 'nn'),
            'language.default' => 'es',
        ));
        $l = new Language($c);
        $this->assertEquals('es', $l->getDefaultLanguage());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageCookie().
     */
    public function testGetLanguageCookie()
    {
        // test it works when no cookie is set
        \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $this->assertNull(Language::getLanguageCookie());

        // test that it works fine with defaults
        \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $_COOKIE['language'] = 'en';
        $this->assertEquals('en', Language::getLanguageCookie());

        // test that it works with non-defaults
        \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('en', 'es', 'nn'),
            'language.cookie.name' => 'xyz'
        ), '', 'simplesaml');
        $_COOKIE['xyz'] = 'Es'; // test values are converted to lowercase too
        $this->assertEquals('es', Language::getLanguageCookie());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageList().
     */
    public function testGetLanguageListNoConfig()
    {
        // test defaults
        $c = \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('en');
        $this->assertEquals(array('en' => true), $l->getLanguageList());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageList().
     */
    public function testGetLanguageListCorrectConfig()
    {
        // test langs from from language_names
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('en', 'nn', 'es'),
        ), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('es');
        $this->assertEquals(array(
            'en' => false,
            'es' => true,
            'nn' => false,
        ), $l->getLanguageList());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageList().
     */
    public function testGetLanguageListIncorrectConfig()
    {
        // test non-existent langs
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('foo', 'bar'),
        ), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('foo');
        $this->assertEquals(array('en' => true), $l->getLanguageList());
    }


    /**
     * Test SimpleSAML\Locale\Language::getLanguageParameterName().
     */
    public function testGetLanguageParameterName()
    {
        // test for default configuration
        $c = \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $l = new Language($c);
        $this->assertEquals('language', $l->getLanguageParameterName());

        // test for valid configuration
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.parameter.name' => 'xyz'
        ), '', 'simplesaml');
        $l = new Language($c);
        $this->assertEquals('xyz', $l->getLanguageParameterName());
    }


    /**
     * Test SimpleSAML\Locale\Language::isLanguageRTL().
     */
    public function testIsLanguageRTL()
    {
        // test defaults
        $c = \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('en');
        $this->assertFalse($l->isLanguageRTL());

        // test non-defaults, non-RTL
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.rtl' => array('foo', 'bar'),
        ), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('en');
        $this->assertFalse($l->isLanguageRTL());

        // test non-defaults, RTL
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('en', 'nn', 'es'),
            'language.rtl' => array('nn', 'es'),
        ), '', 'simplesaml');
        $l = new Language($c);
        $l->setLanguage('es');
        $this->assertTrue($l->isLanguageRTL());
    }


    /**
     * Test SimpleSAML\Locale\Language::setLanguage().
     */
    public function testSetLanguage()
    {
        // test with valid configuration, no cookies set
        $c = \SimpleSAML_Configuration::loadFromArray(array(
            'language.available' => array('en', 'nn', 'es'),
            'language.parameter.name' => 'xyz',
            'language.parameter.setcookie' => false,
        ), '', 'simplesaml');
        $_GET['xyz'] = 'Es'; // test also that lang code is transformed to lower caps
        $l = new Language($c);
        $this->assertEquals('es', $l->getLanguage());

        // test with valid configuration, no cookies, language set unavailable
        $_GET['xyz'] = 'unavailable';
        $l = new Language($c);
        $this->assertEquals('en', $l->getLanguage());
    }
}
{'fraction_non_alphanumeric': 0.16837218116353989, 'fraction_numerical': 0.0, 'mean_word_length': 2.497349237905898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '665233', 'n_tokens_mistral': 3032, 'n_tokens_neox': 2930, 'n_words': 569}