SearchenginePhpTest.php 4.84 KB
Newer Older
Karl's avatar
Karl committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?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);
    }
}