Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
860c9951
Commit
860c9951
authored
Oct 13, 2016
by
Karl Hasselbring
Browse files
Merge branch '264-metager-testen' into 'development'
Erste Tests See merge request
!496
parents
8d1fd39d
4a64dee8
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/MetaGer.php
View file @
860c9951
...
...
@@ -541,12 +541,12 @@ class MetaGer
public
function
sumaIsAdsuche
(
$suma
,
$overtureEnabled
)
{
$sumaName
=
$suma
[
"name"
]
->
__toString
();
return
$suma
[
"name"
]
->
__toString
()
===
"qualigo"
||
$suma
[
"name"
]
->
__toString
()
===
"similar_product_ads"
||
(
!
$overtureEnabled
&&
$suma
[
"name"
]
->
__toString
()
===
"overtureAds"
)
||
$suma
[
"name"
]
->
__toString
()
==
"rlvproduct"
;
$sumaName
===
"qualigo"
||
$sumaName
===
"similar_product_ads"
||
(
!
$overtureEnabled
&&
$sumaName
===
"overtureAds"
)
||
$sumaName
==
"rlvproduct"
;
}
public
function
sumaIsDisabled
(
$suma
)
...
...
@@ -869,29 +869,36 @@ class MetaGer
public
function
checkSpecialSearches
(
Request
$request
)
{
$this
->
searchCheckSitesearch
(
$request
);
$this
->
searchCheckHostBlacklist
();
$this
->
searchCheckDomainBlacklist
();
$this
->
searchCheckStopwords
();
$this
->
searchCheckPhrase
();
$query
=
$this
->
q
;
if
(
$request
->
has
(
'site'
))
{
$site
=
$request
->
input
(
'site'
);
}
else
{
$site
=
""
;
}
$this
->
searchCheckSitesearch
(
$query
,
$site
);
$this
->
searchCheckHostBlacklist
(
$query
);
$this
->
searchCheckDomainBlacklist
(
$query
);
$this
->
searchCheckStopwords
(
$query
);
$this
->
searchCheckPhrase
(
$query
);
}
public
function
searchCheckSitesearch
(
$
re
que
st
)
public
function
searchCheckSitesearch
(
$que
ry
,
$site
)
{
if
(
preg_match
(
"/(.*)\bsite:(\S+)(.*)/si"
,
$
this
->
q
,
$match
))
{
if
(
preg_match
(
"/(.*)\bsite:(\S+)(.*)/si"
,
$
query
,
$match
))
{
$this
->
site
=
$match
[
2
];
$this
->
q
=
$match
[
1
]
.
$match
[
3
];
}
if
(
$
request
->
has
(
'site'
)
)
{
$this
->
site
=
$
request
->
input
(
'
site
'
)
;
if
(
$
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
->
q
=
$match
[
1
]
.
$match
[
4
];
$query
=
$match
[
1
]
.
$match
[
4
];
$this
->
q
=
$query
;
}
if
(
sizeof
(
$this
->
hostBlacklist
)
>
0
)
{
$hostString
=
""
;
...
...
@@ -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
->
q
=
$match
[
1
]
.
$match
[
4
];
$query
=
$match
[
1
]
.
$match
[
4
];
$this
->
q
=
$query
;
}
if
(
sizeof
(
$this
->
domainBlacklist
)
>
0
)
{
$domainString
=
""
;
...
...
@@ -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
->
q
=
$match
[
1
]
.
$match
[
4
];
$query
=
$match
[
1
]
.
$match
[
4
];
$this
->
q
=
$query
;
}
if
(
sizeof
(
$this
->
stopWords
)
>
0
)
{
$stopwordsString
=
""
;
...
...
@@ -935,10 +944,10 @@ class MetaGer
}
}
public
function
searchCheckPhrase
()
public
function
searchCheckPhrase
(
$query
)
{
$p
=
""
;
$tmp
=
$
this
->
q
;
$tmp
=
$
query
;
while
(
preg_match
(
"/(.*)
\"
(.+)
\"
(.*)/si"
,
$tmp
,
$match
))
{
$tmp
=
$match
[
1
]
.
$match
[
3
];
$this
->
phrases
[]
=
strtolower
(
$match
[
2
]);
...
...
tests/ExampleTest.php
deleted
100644 → 0
View file @
8d1fd39d
<?php
use
Illuminate\Foundation\Testing\WithoutMiddleware
;
use
Illuminate\Foundation\Testing\DatabaseMigrations
;
use
Illuminate\Foundation\Testing\DatabaseTransactions
;
class
ExampleTest
extends
TestCase
{
/**
* A basic functional test example.
*
* @return void
*/
public
function
testBasicExample
()
{
$this
->
visit
(
'/'
)
->
see
(
'Laravel'
);
}
}
tests/MetaGerPhpTest.php
0 → 100644
View file @
860c9951
<?php
use
App\MetaGer
;
use
Illuminate\Http\Request
;
class
MetaGerPhpTest
extends
TestCase
{
/**
* A basic test example.
*
* @return void
*/
public
function
test
()
{
$metager
=
new
MetaGer
();
$request
=
$this
->
createDummyRequest
();
$this
->
fullRunTest
(
$metager
,
$request
);
$this
->
specialSearchTest
(
$metager
);
$this
->
createSearchEnginesTest
(
$metager
);
$this
->
linkGeneratorTest
(
$metager
);
}
public
function
fullRunTest
(
$metager
,
$request
)
{
$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
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment