Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Referrers/tests/Unit/ReferrersTest.php')
-rw-r--r--plugins/Referrers/tests/Unit/ReferrersTest.php210
1 files changed, 4 insertions, 206 deletions
diff --git a/plugins/Referrers/tests/Unit/ReferrersTest.php b/plugins/Referrers/tests/Unit/ReferrersTest.php
index 909e6bf65e..e5dea866e9 100644
--- a/plugins/Referrers/tests/Unit/ReferrersTest.php
+++ b/plugins/Referrers/tests/Unit/ReferrersTest.php
@@ -11,217 +11,15 @@ namespace Piwik\Plugins\Referrers\tests;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Period;
+use Piwik\Plugins\Referrers\SearchEngine;
require_once PIWIK_INCLUDE_PATH . '/plugins/Referrers/Referrers.php';
+/**
+ * @group Plugin
+ */
class ReferrersTest extends \PHPUnit_Framework_TestCase
{
- /**
- * Dataprovider serving all search engine data
- */
- public function getSearchEngines()
- {
- include PIWIK_PATH_TEST_TO_ROOT . '/core/DataFiles/SearchEngines.php';
-
- $searchEngines = array();
- foreach ($GLOBALS['Piwik_SearchEngines'] as $url => $searchEngine) {
- $searchEngines[] = array($url, $searchEngine);
- }
- return $searchEngines;
- }
-
- /**
- * search engine has at least one keyword
- *
- * @group Plugins
- *
- * @dataProvider getSearchEngines
- */
- public function testMissingSearchEngineKeyword($url, $searchEngine)
- {
- // Get list of search engines and first appearing URL
- static $searchEngines = array();
-
- $name = parse_url('http://' . $url);
- if (!array_key_exists($searchEngine[0], $searchEngines)) {
- $searchEngines[$searchEngine[0]] = $url;
-
- $this->assertTrue(!empty($searchEngine[1]), $name['host']);
- }
- }
-
- /**
- * search engine is defined in DataFiles/SearchEngines.php but there's no favicon
- *
- * @group Plugins
- *
- * @dataProvider getSearchEngines
- */
- public function testMissingSearchEngineIcons($url, $searchEngine)
- {
- // Get list of existing favicons
- $favicons = scandir(PIWIK_PATH_TEST_TO_ROOT . '/plugins/Referrers/images/searchEngines/');
-
- // Get list of search engines and first appearing URL
- static $searchEngines = array();
-
- $name = parse_url('http://' . $url);
- if (!array_key_exists($searchEngine[0], $searchEngines)) {
- $searchEngines[$searchEngine[0]] = $url;
-
- $this->assertTrue(in_array($name['host'] . '.png', $favicons), $name['host']);
- }
- }
-
- /**
- * favicon exists but there's no corresponding search engine defined in DataFiles/SearchEngines.php
- *
- * @group Plugins
- */
- public function testObsoleteSearchEngineIcons()
- {
- include PIWIK_PATH_TEST_TO_ROOT . '/core/DataFiles/SearchEngines.php';
-
- // Get list of search engines and first appearing URL
- $searchEngines = array();
- foreach ($GLOBALS['Piwik_SearchEngines'] as $url => $searchEngine) {
- $name = parse_url('http://' . $url);
- if (!array_key_exists($name['host'], $searchEngines)) {
- $searchEngines[$name['host']] = true;
- }
- }
-
- // Get list of existing favicons
- $favicons = scandir(PIWIK_PATH_TEST_TO_ROOT . '/plugins/Referrers/images/searchEngines/');
- foreach ($favicons as $name) {
- if ($name[0] == '.' || strpos($name, 'xx.') === 0) {
- continue;
- }
-
- $host = substr($name, 0, -4);
- $this->assertTrue(array_key_exists($host, $searchEngines), $host);
- }
- }
-
- /**
- * get search engine host from url
- *
- * @group Plugins
- */
- public function testGetSearchEngineHostFromUrl()
- {
- $data = array(
- 'http://www.google.com/cse' => array('www.google.com', 'www.google.com/cse'),
- 'http://www.google.com' => array('www.google.com', 'www.google.com'),
- );
-
- foreach ($data as $url => $expected) {
- $this->assertEquals($expected[0], \Piwik\Plugins\Referrers\getSearchEngineHostFromUrl($url));
- $this->assertEquals($expected[1], \Piwik\Plugins\Referrers\getSearchEngineHostPathFromUrl($url));
- }
- }
-
- /**
- * Dataprovider for testGetSearchEngineUrlFromUrlAndKeyword
- */
- public function getSearchEngineUrlFromUrlAndKeywordTestData()
- {
- return array(
- array('http://apollo.lv/portal/search/', 'piwik', 'http://apollo.lv/portal/search/?cof=FORID%3A11&q=piwik&search_where=www'),
- array('http://bing.com/images/search', 'piwik', 'http://bing.com/images/search/?q=piwik'),
- array('http://google.com', 'piwik', 'http://google.com/search?q=piwik'),
- );
- }
-
- /**
- * get search engine url from name and keyword
- *
- * @group Plugins
- *
- * @dataProvider getSearchEngineUrlFromUrlAndKeywordTestData
- */
- public function testGetSearchEngineUrlFromUrlAndKeyword($url, $keyword, $expected)
- {
- include PIWIK_PATH_TEST_TO_ROOT . '/core/DataFiles/SearchEngines.php';
- $this->assertEquals($expected, \Piwik\Plugins\Referrers\getSearchEngineUrlFromUrlAndKeyword($url, $keyword));
- }
-
- /**
- * Dataprovider for getSocialNetworkFromDomainTestData
- */
- public function getSocialNetworkFromDomainTestData()
- {
- return array(
- array('http://www.facebook.com', 'Facebook'),
- array('http://www.facebook.com/piwik', 'Facebook'),
- array('http://m.facebook.com', 'Facebook'),
- array('https://m.facebook.com', 'Facebook'),
- array('m.facebook.com', 'Facebook'),
- array('http://lastfm.com.tr', 'Last.fm'),
- array('http://t.co/test', 'Twitter'),
- array('http://xxt.co/test', \Piwik\Piwik::translate('General_Unknown')),
- array('asdfasdfadsf.com', \Piwik\Piwik::translate('General_Unknown')),
- array('http://xwayn.com', \Piwik\Piwik::translate('General_Unknown')),
- array('http://live.com/test', \Piwik\Piwik::translate('General_Unknown')),
- );
- }
-
- /**
- * @group Plugins
- *
- * @dataProvider getSocialNetworkFromDomainTestData
- */
- public function testGetSocialNetworkFromDomain($url, $expected)
- {
- include PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php';
- $this->assertEquals($expected, \Piwik\Plugins\Referrers\getSocialNetworkFromDomain($url));
- }
-
- public function getSocialsLogoFromUrlTestData()
- {
- return array(
- array('http://www.facebook.com', 'facebook.com.png'),
- array('www.facebook.com', 'facebook.com.png',),
- array('http://lastfm.com.tr', 'last.fm.png'),
- array('http://asdfasdf.org/test', 'xx.png'),
- array('http://www.google.com', 'xx.png'),
- );
- }
-
- /**
- * @group Plugins
- *
- * @dataProvider getSocialsLogoFromUrlTestData
- */
- public function testGetSocialsLogoFromUrl($url, $expected)
- {
- include PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php';
- $this->assertContains($expected, \Piwik\Plugins\Referrers\getSocialsLogoFromUrl($url));
- }
-
- public function isSocialUrlTestData()
- {
- return array(
- array('http://www.facebook.com', 'Facebook', true),
- array('http://www.facebook.com', 'Twitter', false),
- array('http://m.facebook.com', false, true),
- array('http://lastfm.com.tr', 'Last.fm', true),
- array('http://asdfasdf.org/test', false, false),
- array('http://asdfasdf.com/test', 'Facebook', false),
- );
- }
-
- /**
- * @group Plugins
- *
- * @dataProvider isSocialUrlTestData
- */
- public function testIsSocialUrl($url, $assumedSocial, $expected)
- {
- include PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php';
- $this->assertEquals($expected, \Piwik\Plugins\Referrers\isSocialUrl($url, $assumedSocial));
- }
-
public function removeUrlProtocolTestData()
{
return array(