Commit 2062081e authored by Karl's avatar Karl

Nicht triviale Tests hinzugefügt

parent 10492224
......@@ -878,8 +878,8 @@ class MetaGer
$this->searchCheckSitesearch($site);
$this->searchCheckHostBlacklist();
$this->searchCheckDomainBlacklist();
$this->searchCheckStopwords();
$this->searchCheckPhrase();
$this->searchCheckStopwords();
}
public function searchCheckSitesearch($site)
......
......@@ -306,16 +306,16 @@ class Result
return;
} else {
$re = [];
if (isset($match[1])) {$re['schema'] = $match[1];};
if (isset($match[2])) {$re['username'] = $match[2];};
if (isset($match[3])) {$re['password'] = $match[3];};
if (isset($match[4])) {$re['web'] = $match[4];};
if (isset($match[5])) {$re['host'] = $match[5];};
if (isset($match[6])) {$re['domain'] = $match[6];};
if (isset($match[7])) {$re['port'] = $match[7];};
if (isset($match[8])) {$re['path'] = $match[8];};
if (isset($match[9])) {$re['query'] = $match[9];};
if (isset($match[10])) {$re['fragment'] = $match[10];};
if (isset($match[1])) {$re['schema'] = $match[1];} else { $re['schema'] = "";};
if (isset($match[2])) {$re['username'] = $match[2];} else { $re['username'] = "";};
if (isset($match[3])) {$re['password'] = $match[3];} else { $re['password'] = "";};
if (isset($match[4])) {$re['web'] = $match[4];} else { $re['web'] = "";};
if (isset($match[5])) {$re['host'] = $match[5];} else { $re['host'] = "";};
if (isset($match[6])) {$re['domain'] = $match[6];} else { $re['domain'] = "";};
if (isset($match[7])) {$re['port'] = $match[7];} else { $re['port'] = "";};
if (isset($match[8])) {$re['path'] = $match[8];} else { $re['path'] = "";};
if (isset($match[9])) {$re['query'] = $match[9];} else { $re['query'] = "";};
if (isset($match[10])) {$re['fragment'] = $match[10];} else { $re['fragment'] = "";};
return $re;
}
}
......
......@@ -13,9 +13,9 @@ abstract class Searchengine
{
use DispatchesJobs;
protected $ch; # Curl Handle zum erhalten der Ergebnisse
protected $getString = ""; # Der String für die Get-Anfrage
protected $engine; # Die ursprüngliche Engine XML
public $ch; # Curl Handle zum erhalten der Ergebnisse
public $getString = ""; # Der String für die Get-Anfrage
public $engine; # Die ursprüngliche Engine XML
public $enabled = true; # true, wenn die Suchmaschine nicht explizit disabled ist
public $results = []; # Die geladenen Ergebnisse
public $ads = []; # Die geladenen Werbungen
......@@ -34,8 +34,8 @@ abstract class Searchengine
public $hash; # Der Hash-Wert dieser Suchmaschine
public $fp; # Wird für Artefakte benötigt
protected $socketNumber = null; # Wird für Artefakte benötigt
protected $counter = 0; # Wird eventuell für Artefakte benötigt
public $socketNumber = null; # Wird für Artefakte benötigt
public $counter = 0; # Wird eventuell für Artefakte benötigt
public $write_time = 0; # Wird eventuell für Artefakte benötigt
public $connection_time = 0; # Wird eventuell für Artefakte benötigt
......@@ -59,6 +59,8 @@ abstract class Searchengine
$this->cacheDuration = 60;
}
$this->enabled = true;
# Eine Suchmaschine kann automatisch temporär deaktiviert werden, wenn es Verbindungsprobleme gab:
if (isset($this->disabled) && strtotime($this->disabled) <= time()) {
# In diesem Fall ist der Timeout der Suchmaschine abgelaufen.
......@@ -142,6 +144,7 @@ abstract class Searchengine
$xml = simplexml_load_file($sumaFile);
unset($xml->xpath("//sumas/suma[@name='" . $this->name . "']")['0']['disabled']);
$xml->saveXML($sumaFile);
$this->enabled = true;
}
public function closeFp()
......
......@@ -5,11 +5,6 @@ use Illuminate\Http\Request;
class MetaGerPhpTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function test()
{
$this->fullRunTest();
......@@ -78,10 +73,33 @@ class MetaGerPhpTest extends TestCase
$metager->parseFormData($request);
$metager->checkSpecialSearches($request);
$this->assertEquals("wantsite", $metager->getSite());
$this->assertEquals("blackhost", $metager->getUserHostBlacklist()[0]);
$this->assertEquals("blackdomain", $metager->getUserDomainBlacklist()[0]);
$this->assertEquals("blackword", $metager->getStopWords()[0]);
$this->assertEquals("i want phrase", $metager->getPhrases()[0]);
$this->assertContains("blackhost", $metager->getUserHostBlacklist());
$this->assertContains("blackdomain", $metager->getUserDomainBlacklist());
$this->assertContains("blackword", $metager->getStopWords());
$this->assertContains("i want phrase", $metager->getPhrases());
$metager = new MetaGer();
$request = new Request(['eingabe' => '-site:peter:test -blackword-test -host:blackhost-test.de.nz/test ich suche nach -host:blackhost:blackhost2.cote/t?p=5 "peter ist obst-garten und -bauern"']);
$metager->parseFormData($request);
$metager->checkSpecialSearches($request);
$this->assertEquals("peter:test", $metager->getSite());
$this->assertContains("blackhost:blackhost2.cote/t?p=5", $metager->getUserHostBlacklist());
$this->assertContains("blackhost-test.de.nz/test", $metager->getUserHostBlacklist());
$this->assertContains("blackword-test", $metager->getStopWords());
$this->assertNotContains("bauern", $metager->getStopWords());
$this->assertContains("peter ist obst-garten und -bauern", $metager->getPhrases());
$metager = new MetaGer();
$request = new Request(['eingabe' => '-host:-domain:test']);
$metager->parseFormData($request);
$metager->checkSpecialSearches($request);
$this->assertContains("-domain:test", $metager->getUserHostBlacklist());
$metager = new MetaGer();
$request = new Request(['eingabe' => '"-host:-domain:test"']);
$metager->parseFormData($request);
$metager->checkSpecialSearches($request);
$this->assertContains("-host:-domain:test", $metager->getPhrases());
}
public function addLinkTest()
......@@ -152,6 +170,15 @@ class MetaGerPhpTest extends TestCase
$enabledSearchengines = $sumas;
$metager->adjustFocus($sumas, $enabledSearchengines);
$this->assertEquals("bilder", $metager->getFokus());
$metager = new MetaGer();
$request = new Request(["focus" => "web"]);
$metager->parseFormData($request);
$this->assertEquals("web", $metager->getFokus());
$sumas = simplexml_load_file("tests/testSumas2.xml")->xpath("suma"); # Eine spezielle test sumas.xml
$enabledSearchengines = array_slice($sumas, 0, 1);
$metager->adjustFocus($sumas, $enabledSearchengines);
$this->assertEquals("bilder", $metager->getFokus());
}
public function checkCanNotSitesearchTest()
......@@ -159,6 +186,14 @@ class MetaGerPhpTest extends TestCase
$metager = new MetaGer();
$enabledSearchengines = simplexml_load_file("tests/testSumas.xml")->xpath("suma"); # Eine spezielle test sumas.xml
$this->assertFalse($metager->checkCanNotSitesearch($enabledSearchengines));
$metager = new MetaGer();
$request = $this->createDummyRequest();
$metager->parseFormData($request);
$metager->checkSpecialSearches($request);
$this->assertEquals("wantsite", $metager->getSite());
$enabledSearchengines = simplexml_load_file("tests/testSumas2.xml")->xpath("suma"); # Eine spezielle test sumas.xml
$this->assertTrue($metager->checkCanNotSitesearch($enabledSearchengines));
}
public function isBildersucheTest()
......
......@@ -6,11 +6,6 @@ use Illuminate\Http\Request;
class ResultPhpTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function test()
{
$this->rankingTest();
......@@ -73,6 +68,27 @@ class ResultPhpTest extends TestCase
$result = $this->getDummyResult();
$metager = $this->getDummyMetaGer();
$this->assertTrue($result->isValid($metager));
$metager = new MetaGer();
$request = new Request(['eingabe' => 'test -host:host.domain.de -domain:domain.de']);
$metager->parseFormData($request);
$metager->checkSpecialSearches($request);
$provider = file_get_contents("tests/testSumas.xml");
$titel = "Titel";
$link = "host.domain.de";
$anzeigeLink = "host.domain.de/ergebnis/1?p=2";
$descr = "Beschreibung: i want phrase";
$gefVon = "";
$sourceRank = 1;
$result = new Result($provider, $titel, $link, $anzeigeLink, $descr, $gefVon, $sourceRank);
$this->assertFalse($result->isValid($metager));
$link = "domain.de/ergebnis/1?p=2";
$result = new Result($provider, $titel, $link, $anzeigeLink, $descr, $gefVon, $sourceRank);
$this->assertFalse($result->isValid($metager));
}
public function linkGeneratorsTest()
......@@ -86,6 +102,15 @@ class ResultPhpTest extends TestCase
'bar.de');
$this->equalCallbackTester($result, "generateProxyLink", ["http://www.foo.bar.de/test?ja=1"],
'https://proxy.suma-ev.de/cgi-bin/nph-proxy.cgi/en/I0/http/www.foo.bar.de/test?ja=1');
$url = "https://leya:organa@www.han.solo.de/unterseite/document.htm?param1=2&param2=1#siebzehn";
$this->equalCallbackTester($result, "getStrippedHost", [$url],
'han.solo.de');
$this->equalCallbackTester($result, "getStrippedDomain", [$url],
'solo.de');
$this->equalCallbackTester($result, "getStrippedLink", [$url],
'han.solo.de/unterseite/document.htm');
}
public function equalCallbackTester($object, $funcName, $input, $expectedInOutput)
......
<?php
use App\MetaGer;
use App\models\parserSkripte\Bing;
use Illuminate\Http\Request;
class SearchenginePhpTest extends TestCase
{
public function test()
{
$this->constructionTest();
$this->enablingTest();
}
public function constructionTest()
{
$engines = simplexml_load_file("tests/testSumas.xml")->xpath("suma");
$metager = new MetaGer();
$request = new Request(["focus" => "web"]);
$metager->parseFormData($request);
$searchengine = new Bing($engines[0], $metager);
$this->assertEquals('<suma name="minism" host="www.suchmaschine.de" skript="/suche/" formData="sprache=de&amp;sortieren=true&amp;queue=&lt;&lt;QUERY&gt;&gt;&amp;rows=&lt;&lt;COUNT&gt;&gt;&amp;fq=subcollection:&lt;&lt;SUBCOLLECTIONS&gt;&gt;" package="suchmaschine" displayName="Meine Suchmaschine" homepage="www.suchmaschine.de/welcome" port="443" inputEncoding="Latin1" userSelectable="1" type="bilder" engineBoost="1.2" additionalHeaders="$#!#$" hasSiteSearch="1" cacheDuration="60"/>',
$searchengine->engine);
$this->assertEquals(true,
$searchengine->enabled);
$this->assertEquals('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1',
$searchengine->useragent);
$this->assertEquals(null,
$searchengine->ip);
$this->assertEquals('<a href="www.suchmaschine.de/welcome" target="_blank">Meine Suchmaschine</a>',
$searchengine->gefVon);
#$this->assertEquals('0.68813000 1476867147', $searchengine->startTime);
$this->assertEquals('/suche/?sprache=de&sortieren=true&queue=&rows=<<COUNT>>&fq=subcollection:<<SUBCOLLECTIONS>>',
$searchengine->getString); # Enthält auch Testen von generateGetString(), urlEncode() und getOvertureAffilData() (nicht in der aktuellen Version)
$this->assertEquals('b1ac991618a8ffc0dab6b9bbb913841e',
$searchengine->hash);
$this->assertEquals('86a9106ae65537651a8e456835b316ab',
$searchengine->resultHash);
$this->assertEquals(true,
$searchengine->canCache);
$this->assertEquals('minism',
$searchengine->name);
$this->assertEquals('www.suchmaschine.de',
$searchengine->host);
$this->assertEquals('/suche/',
$searchengine->skript);
$this->assertEquals('sprache=de&sortieren=true&queue=<<QUERY>>&rows=<<COUNT>>&fq=subcollection:<<SUBCOLLECTIONS>>',
$searchengine->formData);
$this->assertEquals('suchmaschine',
$searchengine->package);
$this->assertEquals('Meine Suchmaschine',
$searchengine->displayName);
$this->assertEquals('443',
$searchengine->port);
$this->assertEquals('Latin1',
$searchengine->inputEncoding);
$this->assertEquals('1',
$searchengine->userSelectable);
$this->assertEquals('bilder',
$searchengine->type);
$this->assertEquals('1.2',
$searchengine->engineBoost);
$this->assertEquals('$#!#$',
$searchengine->additionalHeaders);
$this->assertEquals(null,
$searchengine->disabled);
$this->assertEquals('1',
$searchengine->hasSiteSearch);
$this->assertEquals('60',
$searchengine->cacheDuration);
}
public function enablingTest()
{
$engines = simplexml_load_file("tests/testSumas.xml")->xpath("suma");
$engines[0]['disabled'] = 'next Monday';
$metager = new MetaGer();
$request = new Request(["focus" => "web"]);
$metager->parseFormData($request);
$searchengine = new Bing($engines[0], $metager);
$this->assertFalse($searchengine->isEnabled());
$searchengine->enable("tests/testSumas.xml", "enable suma test");
$this->assertTrue($searchengine->isEnabled());
$engines = simplexml_load_file("tests/testSumas.xml")->xpath("suma");
$metager = new MetaGer();
$request = new Request(["focus" => "web"]);
$metager->parseFormData($request);
$searchengine = new Bing($engines[0], $metager);
$this->assertTrue($searchengine->isEnabled());
}
/*
abstract public function loadResults($result);
private function setStatistic($key, $val)
protected function getHost()
getNext(MetaGer $metager, $result)
startSearch(\App\MetaGer $metager)
rank($eingabe)
closeFp()
getSocket()
retrieveResults(MetaGer $metager)
shutdown()
getCurlInfo()
getCurlErrors()
addCurlHandle($mh)
removeCurlHandle($mh)
*/
public function equalCallbackTester($object, $funcName, $input, $expectedInOutput)
{
$output = call_user_func_array(array($object, $funcName), $input);
$this->assertEquals($expectedInOutput, $output);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<sumas>
<suma
name="minism"
host="www.suchmaschine.de"
skript="/suche/"
formData="sprache=de&amp;sortieren=true&amp;queue=&lt;&lt;QUERY&gt;&gt;&amp;rows=&lt;&lt;COUNT&gt;&gt;&amp;fq=subcollection:&lt;&lt;SUBCOLLECTIONS&gt;&gt;"
package="suchmaschine"
displayName="Meine Suchmaschine"
homepage="www.suchmaschine.de/welcome"
port="443"
inputEncoding="Latin1"
userSelectable="1"
type="bilder"
engineBoost="1.2"
additionalHeaders="$#!#$"
disabled="0"
hasSiteSearch="1"
cacheDuration="60"
></suma>
</sumas>
\ No newline at end of file
<suma name="minism" host="www.suchmaschine.de" skript="/suche/" formData="sprache=de&amp;sortieren=true&amp;queue=&lt;&lt;QUERY&gt;&gt;&amp;rows=&lt;&lt;COUNT&gt;&gt;&amp;fq=subcollection:&lt;&lt;SUBCOLLECTIONS&gt;&gt;" package="suchmaschine" displayName="Meine Suchmaschine" homepage="www.suchmaschine.de/welcome" port="443" inputEncoding="Latin1" userSelectable="1" type="bilder" engineBoost="1.2" additionalHeaders="$#!#$" hasSiteSearch="1" cacheDuration="60"/>
</sumas>
<?xml version="1.0" encoding="UTF-8"?>
<sumas>
<suma name="name1" host="www.suchmaschine1.de" skript="/suche1/" formData="sprache=de&amp;sortieren=true&amp;queue=&lt;&lt;QUERY&gt;&gt;&amp;rows=&lt;&lt;COUNT&gt;&gt;&amp;fq=subcollection:&lt;&lt;SUBCOLLECTIONS&gt;&gt;" package="suchmaschine1" displayName="Meine Suchmaschine1" homepage="www.suchmaschine1.de/welcome" port="443" inputEncoding="Latin1" userSelectable="1" type="bilder" engineBoost="1.2" additionalHeaders="$#!#$" hasSiteSearch="0" cacheDuration="60"/>
<suma name="name2" host="www.suchmaschine2.de" skript="/suche2/" formData="sprache=de&amp;sortieren=true&amp;queue=&lt;&lt;QUERY&gt;&gt;&amp;rows=&lt;&lt;COUNT&gt;&gt;&amp;fq=subcollection:&lt;&lt;SUBCOLLECTIONS&gt;&gt;" package="suchmaschine2" displayName="Meine Suchmaschine2" homepage="www.suchmaschine2.de/welcome" port="443" inputEncoding="Latin1" userSelectable="1" type="web" engineBoost="1.2" additionalHeaders="$#!#$" hasSiteSearch="0" cacheDuration="60"/>
<suma name="name3" host="www.suchmaschine3.de" skript="/suche3/" formData="sprache=de&amp;sortieren=true&amp;queue=&lt;&lt;QUERY&gt;&gt;&amp;rows=&lt;&lt;COUNT&gt;&gt;&amp;fq=subcollection:&lt;&lt;SUBCOLLECTIONS&gt;&gt;" package="suchmaschine3" displayName="Meine Suchmaschine3" homepage="www.suchmaschine3.de/welcome" port="443" inputEncoding="Latin1" userSelectable="1" type="bilder" engineBoost="1.2" additionalHeaders="$#!#$" hasSiteSearch="0" cacheDuration="60"/>
</sumas>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment