Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MetaGer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer
Commits
2695f23a
Commit
2695f23a
authored
8 years ago
by
Karl
Browse files
Options
Downloads
Patches
Plain Diff
Es wird jetzt einiges aus der MetaGer.php auf grundlegende Funktionalität getestet.
parent
3c6da552
No related branches found
No related tags found
2 merge requests
!496
Erste Tests
,
!475
Development
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/MetaGer.php
+34
-25
34 additions, 25 deletions
app/MetaGer.php
tests/MetaGerPhpTest.php
+98
-13
98 additions, 13 deletions
tests/MetaGerPhpTest.php
with
132 additions
and
38 deletions
app/MetaGer.php
+
34
−
25
View file @
2695f23a
...
...
@@ -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
]);
...
...
This diff is collapsed.
Click to expand it.
tests/MetaGerPhpTest.php
+
98
−
13
View file @
2695f23a
<?php
use
App\MetaGer
;
use
Illuminate\Http\Request
;
class
MetaGerPhpTest
extends
TestCase
{
/**
...
...
@@ -7,18 +10,100 @@ class MetaGerPhpTest extends TestCase
*
* @return void
*/
public
function
testExample
()
{
$this
->
assertTrue
(
true
);
$this
->
visit
(
'/'
)
->
see
(
'MetaGer'
)
->
dontSee
(
'Google'
);
$this
->
visit
(
'/'
)
->
click
(
'Datenschutz'
)
->
seePageIs
(
'/datenschutz'
);
$this
->
visit
(
'/'
)
->
type
(
'test'
,
'eingabe'
)
->
press
(
'submit'
)
->
seePageIs
(
'/meta/meta.ger3'
);
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
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment