/**
  * @covers \WPGlobus_Utils::hreflangs
  */
 public function test_hreflangs()
 {
     /**
      * Mock object sent as a parameter, because we do now have access to the actual config.
      *
      * @var WPGlobus_Config $config
      */
     $config = $this->getMock('WPGlobus_Config');
     /**
      * These languages are enabled
      */
     $config->enabled_languages = array('en', 'ru', 'pt');
     /**
      * This is the current language
      */
     $config->language = 'pt';
     /**
      * This is the default language
      */
     $config->default_language = 'ru';
     /**
      * This says "Do not use language code in the default URL"
      * So, no /en/page/, just /page/
      */
     $config->hide_default_language = true;
     $config->locale['en'] = "en_US";
     $config->locale['ru'] = "ru_RU";
     $config->locale['pt'] = "pt_PT";
     /**
      * Mock web request
      */
     $_SERVER['HTTP_HOST'] = 'www.example.com';
     $_SERVER['REQUEST_URI'] = '/folder/file?var=value';
     $hreflangs = WPGlobus_Utils::hreflangs($config);
     self::assertEquals('<link rel="alternate" hreflang="ru-RU" href="http://www.example.com/folder/file?var=value"/>', $hreflangs['ru']);
     self::assertEquals('<link rel="alternate" hreflang="pt-PT" href="http://www.example.com/pt/folder/file?var=value"/>', $hreflangs['pt']);
 }
예제 #2
0
 /**
  * Add rel="alternate" links to head section
  * @return void
  */
 public function on_add_hreflang()
 {
     $hreflangs = WPGlobus_Utils::hreflangs();
     /**
      * Filter hreflang.
      * Returning array.
      * @since 1.0.14
      *
      * @param string $hreflangs An array.
      */
     $hreflangs = apply_filters('wpglobus_hreflang_tag', $hreflangs);
     if (!empty($hreflangs)) {
         echo implode("\n", $hreflangs) . "\n";
     }
 }