Commit 2695f23a authored by Karl's avatar Karl

Es wird jetzt einiges aus der MetaGer.php auf grundlegende Funktionalität getestet.

parent 3c6da552
...@@ -541,12 +541,12 @@ class MetaGer ...@@ -541,12 +541,12 @@ class MetaGer
public function sumaIsAdsuche($suma, $overtureEnabled) public function sumaIsAdsuche($suma, $overtureEnabled)
{ {
$sumaName = $suma["name"]->__toString();
return return
$suma["name"]->__toString() === "qualigo" $sumaName === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads" || $sumaName === "similar_product_ads"
|| (!$overtureEnabled || (!$overtureEnabled && $sumaName === "overtureAds")
&& $suma["name"]->__toString() === "overtureAds") || $sumaName == "rlvproduct";
|| $suma["name"]->__toString() == "rlvproduct";
} }
public function sumaIsDisabled($suma) public function sumaIsDisabled($suma)
...@@ -869,29 +869,36 @@ class MetaGer ...@@ -869,29 +869,36 @@ class MetaGer
public function checkSpecialSearches(Request $request) public function checkSpecialSearches(Request $request)
{ {
$this->searchCheckSitesearch($request); $query = $this->q;
$this->searchCheckHostBlacklist(); if ($request->has('site')) {
$this->searchCheckDomainBlacklist(); $site = $request->input('site');
$this->searchCheckStopwords(); } else {
$this->searchCheckPhrase(); $site = "";
}
$this->searchCheckSitesearch($query, $site);
$this->searchCheckHostBlacklist($query);
$this->searchCheckDomainBlacklist($query);
$this->searchCheckStopwords($query);
$this->searchCheckPhrase($query);
} }
public function searchCheckSitesearch($request) public function searchCheckSitesearch($query, $site)
{ {
if (preg_match("/(.*)\bsite:(\S+)(.*)/si", $this->q, $match)) { if (preg_match("/(.*)\bsite:(\S+)(.*)/si", $query, $match)) {
$this->site = $match[2]; $this->site = $match[2];
$this->q = $match[1] . $match[3]; $this->q = $match[1] . $match[3];
} }
if ($request->has('site')) { if ($site !== "") {
$this->site = $request->input('site'); $this->site = $site;
} }
} }
public function searchCheckHostBlacklist() public function searchCheckHostBlacklist($query)
{ {
while (preg_match("/(.*)(^|\s)-host:(\S+)(.*)/si", $this->q, $match)) { while (preg_match("/(.*)(^|\s)-host:(\S+)(.*)/si", $query, $match)) {
$this->hostBlacklist[] = $match[3]; $this->hostBlacklist[] = $match[3];
$this->q = $match[1] . $match[4]; $query = $match[1] . $match[4];
$this->q = $query;
} }
if (sizeof($this->hostBlacklist) > 0) { if (sizeof($this->hostBlacklist) > 0) {
$hostString = ""; $hostString = "";
...@@ -903,11 +910,12 @@ class MetaGer ...@@ -903,11 +910,12 @@ class MetaGer
} }
} }
public function searchCheckDomainBlacklist() public function searchCheckDomainBlacklist($query)
{ {
while (preg_match("/(.*)(^|\s)-domain:(\S+)(.*)/si", $this->q, $match)) { while (preg_match("/(.*)(^|\s)-domain:(\S+)(.*)/si", $query, $match)) {
$this->domainBlacklist[] = $match[3]; $this->domainBlacklist[] = $match[3];
$this->q = $match[1] . $match[4]; $query = $match[1] . $match[4];
$this->q = $query;
} }
if (sizeof($this->domainBlacklist) > 0) { if (sizeof($this->domainBlacklist) > 0) {
$domainString = ""; $domainString = "";
...@@ -919,11 +927,12 @@ class MetaGer ...@@ -919,11 +927,12 @@ class MetaGer
} }
} }
public function searchCheckStopwords() public function searchCheckStopwords($query)
{ {
while (preg_match("/(.*)(^|\s)-(\S+)(.*)/si", $this->q, $match)) { while (preg_match("/(.*)(^|\s)-(\S+)(.*)/si", $query, $match)) {
$this->stopWords[] = $match[3]; $this->stopWords[] = $match[3];
$this->q = $match[1] . $match[4]; $query = $match[1] . $match[4];
$this->q = $query;
} }
if (sizeof($this->stopWords) > 0) { if (sizeof($this->stopWords) > 0) {
$stopwordsString = ""; $stopwordsString = "";
...@@ -935,10 +944,10 @@ class MetaGer ...@@ -935,10 +944,10 @@ class MetaGer
} }
} }
public function searchCheckPhrase() public function searchCheckPhrase($query)
{ {
$p = ""; $p = "";
$tmp = $this->q; $tmp = $query;
while (preg_match("/(.*)\"(.+)\"(.*)/si", $tmp, $match)) { while (preg_match("/(.*)\"(.+)\"(.*)/si", $tmp, $match)) {
$tmp = $match[1] . $match[3]; $tmp = $match[1] . $match[3];
$this->phrases[] = strtolower($match[2]); $this->phrases[] = strtolower($match[2]);
......
<?php <?php
use App\MetaGer;
use Illuminate\Http\Request;
class MetaGerPhpTest extends TestCase class MetaGerPhpTest extends TestCase
{ {
/** /**
...@@ -7,18 +10,100 @@ class MetaGerPhpTest extends TestCase ...@@ -7,18 +10,100 @@ class MetaGerPhpTest extends TestCase
* *
* @return void * @return void
*/ */
public function testExample() public function test()
{ {
$this->assertTrue(true); $metager = new MetaGer();
$this->visit('/') $request = $this->createDummyRequest();
->see('MetaGer') $this->fullRunTest($metager, $request);
->dontSee('Google'); $this->specialSearchTest($metager);
$this->visit('/') $this->createSearchEnginesTest($metager);
->click('Datenschutz') $this->linkGeneratorTest($metager);
->seePageIs('/datenschutz'); }
$this->visit('/')
->type('test', 'eingabe') public function fullRunTest($metager, $request)
->press('submit') {
->seePageIs('/meta/meta.ger3'); $metager->parseFormData($request);
$metager->checkSpecialSearches($request);
$metager->createSearchEngines($request);
$metager->rankAll();
$metager->prepareResults();
$metager->createView();
}
public function createDummyRequest()
{
/**
* Constructor.
*
* @param array $query The GET parameters
* @param array $request The POST parameters
* @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
* @param array $cookies The COOKIE parameters
* @param array $files The FILES parameters
* @param array $server The SERVER parameters
* @param string|resource $content The raw body data
*/
#new Request(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
$query = [];
$query["eingabe"] = "garten";
$query["focus"] = "angepasst";
$query["encoding"] = "utf8";
$query["lang"] = "all";
$query["time"] = "1000";
$query["sprueche"] = "on";
$query["resultCount"] = "20";
$query["tab"] = "on";
$query["onenewspage"] = "on";
return new Request($query);
}
public function specialSearchTest($metager)
{
$metager->searchCheckSitesearch("hund katze site:wolf.de", "");
$this->assertEquals("wolf.de", $metager->getSite());
$metager->searchCheckHostBlacklist("hund katze -host:wolf.de");
$this->assertEquals("wolf.de", $metager->getUserHostBlacklist()[0]);
$metager->searchCheckDomainBlacklist("hund katze -domain:wolf.de");
$this->assertEquals("wolf.de", $metager->getUserDomainBlacklist()[0]);
$metager->searchCheckStopwords("hund katze -wolf");
$this->assertEquals("wolf", $metager->getStopWords()[0]);
$metager->searchCheckPhrase('hund katze "wolf"');
$this->assertEquals("wolf", $metager->getPhrases()[0]);
}
public function createSearchEnginesTest($metager)
{
$this->specialSumaTest($metager);
}
public function specialSumaTest($metager)
{
$suma = new SimpleXMLElement("<suma></suma>");
$suma["name"] = "qualigo";
$this->assertTrue($metager->sumaIsAdsuche($suma, false));
$suma["disabled"] = "1";
$this->assertTrue($metager->sumaIsDisabled($suma));
$suma["name"] = 'overture';
$this->assertTrue($metager->sumaIsOverture($suma));
$suma["name"] = 'bing';
$this->assertTrue($metager->sumaIsNotAdsuche($suma));
}
public function linkGeneratorTest($metager)
{
$this->callbackTester($metager, "generateSearchLink", ["bilder"], "http://localhost/meta/meta.ger3?eingabe=garten&focus=bilder&encoding=utf8&lang=all&time=1000&sprueche=on&resultCount=20&tab=on&onenewspage=on&out=results");
$this->callbackTester($metager, "generateQuicktipLink", [], "http://localhost/qt");
$this->callbackTester($metager, "generateSiteSearchLink", ["wolf.de"], "http://localhost/meta/meta.ger3?eingabe=garten+site%3Awolf.de&focus=web&encoding=utf8&lang=all&time=1000&sprueche=on&resultCount=20&tab=on&onenewspage=on");
$this->callbackTester($metager, "generateRemovedHostLink", ["wolf.de"], "http://localhost/meta/meta.ger3?eingabe=garten+-host%3Awolf.de&focus=angepasst&encoding=utf8&lang=all&time=1000&sprueche=on&resultCount=20&tab=on&onenewspage=on");
$this->callbackTester($metager, "generateRemovedDomainLink", ["wolf.de"], "http://localhost/meta/meta.ger3?eingabe=garten+-domain%3Awolf.de&focus=angepasst&encoding=utf8&lang=all&time=1000&sprueche=on&resultCount=20&tab=on&onenewspage=on");
}
public function callbackTester($metager, $funcName, $input, $expectedOutput)
{
$output = call_user_func_array(array($metager, $funcName), $input);
$this->assertEquals($expectedOutput, $output);
} }
} }
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