Esempio n. 1
0
    public function testKeepCustomParameters()
    {
        $query = AfsQuery::create_from_parameters(array("query" => "topic", "mycustomparameter" => "mycustomvalue"));
        $curlConnector = new SAI_CurlStub();
        $mockBaseUrl = "localhost";
        $aboutRequestOpts = array(CURLOPT_URL => "http://{$mockBaseUrl}/bo-ws/about");
        $aboutResponse = <<<JSON
{
  "x:type":"ws.response",
  "query":{
    "x:type":"ws.response.query",
    "parameters":{
      "x:type":"collection",
      "x:values":[

      ]
    },
    "properties":{
      "x:type":"x:dynamic"
    }
  },
  "result":{
    "x:type":"bows.about",
    "boWsVersion":{
      "x:type":"AfsVersion",
      "build":"3eaebfd1f1fe261780347cbc35bfbd65d613575e",
      "gen":"7.6",
      "major":"4",
      "minor":"0",
      "motto":"Pink Dolphin"
    },
    "copyright":"Copyright (C) 1999-2013 Antidot"
  }
}
JSON;
        $response = <<<JSON
{"header":{"query":{"userId":"user_5354ec142aa12","sessionId":"session_5354ec142aa4b","date":"2014-04-21T13:41:10+0200",
"queryParam":[{"name":"afs:service","value":"71003"},{"name":"afs:status","value":"beta"},{"name":"afs:query","value":"topic"},
{"name":"afs:query@Book","value":"topic"},{"name":"afs:query@Topic","value":"topic"},
{"name":"afs:query@spellcheck","value":"topic"},{"name":"afs:output","value":"json,2"},{"name":"afs:output@Book","value":"json,2"},
{"name":"afs:output@Topic","value":"json,2"},{"name":"afs:output@spellcheck","value":"json,2"},{"name":"mycustomparameter","value":"mycustomvalue"},
{"name":"mycustomparameter@Book","value":"mycustomvalue"},{"name":"mycustomparameter@Topic","value":"mycustomvalue"},
{"name":"mycustomparameter@spellcheck","value":"mycustomvalue"},{"name":"afs:replies","value":"10"},
{"name":"afs:replies@Book","value":"10"},{"name":"afs:replies@Topic","value":"10"},{"name":"afs:replies@spellcheck",
"value":"10"}],"mainCtx":{"textQuery":"topic"},"textQuery":"topic"},"user":{"requestMethod":"GET","agent":"Mozilla 5.0",
"address":"127.0.0.1","output":{"format":"JSON","encoding":"gzip","charset":"UTF-8"}},"performance":{"durationMs":11},"info":{}},
"replySet":[{"meta":{"uri":"Book","totalItems":1,"totalItemsIsExact":true,"pageItems":1,"firstPageItem":1,"lastPageItem":1,
"durationMs":1,"firstPaFId":147,"lastPaFId":147,"producer":"SEARCH"},
"facets":{"facet":[{"afs:t":"FacetTree","node":[{"key":"urn:dita:single_topic.ditamap",
"labels":[{"lang":"EN","label":"urn:dita:single_topic.ditamap"},{"lang":"FR","label":"urn:dita:single_topic.ditamap"}],
"items":1}],"layout":"TREE","type":"STRING","id":"BaseUri","labels":[{"lang":"EN","label":"BaseUri"},
{"lang":"FR","label":"BaseUri"}]},{"afs:t":"FacetTree","node":[{"key":"noditaval","labels":[{"lang":"EN","label":"noditaval"},
{"lang":"FR","label":"noditaval"}],"items":1}],"layout":"TREE","type":"STRING","id":"Ditaval",
"labels":[{"lang":"EN","label":"Ditaval"},{"lang":"FR","label":"Ditaval"}]},{"afs:t":"FacetTree",
"node":[{"key":"en","labels":[{"label":"English"}],"items":1}],"layout":"TREE","type":"STRING","id":"afs:lang",
"labels":[{"label":"Language"}]}]},"content":{"reply":[{"docId":3,"uri":"urn:dita:single_topic.ditamap",
"title":[{"afs:t":"KwicString","text":"Single "},{"afs:t":"KwicMatch","match":"Topic"},
{"afs:t":"KwicString","text":" Map"}],"relevance":{"rank":1},"layerReplies":{"reply":[{"layer":"USER_1",
"reply":{"docId":3,"uri":"","clientData":[{"contents":{"meta":[],"label":"Single Topic Map","ditaval":"noditaval",
"uri":"urn:dita:single_topic.ditamap"},"id":"ditaval","mimeType":"application\\/json"}]}}]}}]}},
{"meta":{"uri":"Topic","totalItems":1,"totalItemsIsExact":true,"pageItems":1,"firstPageItem":1,"lastPageItem":1,"durationMs":2,
"firstPaFId":147,"lastPaFId":147,"producer":"SEARCH"},"facets":{"facet":[{"afs:t":"FacetTree",
"node":[{"key":"others","labels":[{"lang":"EN","label":"others"},{"lang":"FR","label":"others"}],"items":1}],
"layout":"TREE","type":"STRING","id":"Audience","labels":[{"lang":"EN","label":"Audience"},{"lang":"FR","label":"Audience"}]},
{"afs:t":"FacetTree","node":[{"key":"Single Topic Map","labels":[{"lang":"EN","label":"Single Topic Map"},
{"lang":"FR","label":"Single Topic Map"}],"items":1}],"layout":"TREE","type":"STRING","id":"Filter_By_Docs",
"labels":[{"lang":"EN","label":"Filter by Documents"},{"lang":"FR","label":"Filtrer par Documents"}]},
{"afs:t":"FacetTree","node":[{"key":"en","labels":[{"label":"English"}],"items":1}],"layout":"TREE","type":"STRING",
"id":"afs:lang","labels":[{"label":"Language"}]}]},"content":{"reply":[{"docId":2,"uri":"urn:dita:single_topic.dita",
"title":[{"afs:t":"KwicString","text":"Titre du "},{"afs:t":"KwicMatch","match":"topic"},
{"afs:t":"KwicString","text":" unique"}],"abstract":[{"afs:t":"KwicString","text":"Ce "},
{"afs:t":"KwicMatch","match":"topic"},{"afs:t":"KwicString","text":" est seul dans sa ditamap et ceci devrait apparaitre dans le résumé."}],
"relevance":{"rank":1},"layerReplies":{"reply":[{"layer":"USER_2","reply":{"docId":2,"uri":"",
"clientData":[{"contents":{"book":{"uri":"urn:dita:single_topic.ditamap","label":"Single Topic Map"},
"topics":[{"uri":"urn:dita:single_topic.dita","label":"Titre du topic unique"}],"ditaval":"noditaval"},
"id":"breadcrumb","mimeType":"application\\/json"}]}}]}}]}}]}
JSON;
        //Set BO response for AboutConnector
        $curlConnector->setResponse($aboutResponse, $aboutRequestOpts);
        //Set response for query
        $curlConnector->setResponse($response);
        $search = new AfsSearch($mockBaseUrl, '71003', AfsServiceStatus::STABLE, $curlConnector);
        $search->set_query($query);
        $coder = new AfsQueryCoder();
        $search->set_query_coder($coder);
        $helper = $search->execute($query);
        $replysetHelper = $helper->get_replyset("Book");
        $facetHelpers = $replysetHelper->get_facets();
        //Make sure each link of facets contains custom parameter
        foreach ($facetHelpers as $facetHelper) {
            foreach ($facetHelper->get_elements() as $facetValueHelper) {
                $this->assertEquals(1, preg_match("/[&\\?]mycustomparameter=mycustomvalue[&\$]/", $facetValueHelper->link));
            }
        }
        $this->assertEquals("mycustomvalue", $helper->get_query_parameter("mycustomparameter"));
    }
Esempio n. 2
0
 public function setUp()
 {
     $this->_curlStub = new SAI_CurlStub();
     $this->_curlStub->setResponse(self::DEFAULT_RESPONSE);
     $this->_curlStub->setErrorCode(self::DEFAULT_ERRORCODE);
 }
Esempio n. 3
0
    /**
     * @covers AfsPafLiveConnector::process_doc
     * @covers AfsPafLiveConnector::__construct
     */
    public function testProcess()
    {
        $mockBaseUrl = "url";
        $auth = new AfsUserAuthentication('t8', 'antidot', AFS_AUTH_BOWS);
        $service = new AfsService(80108);
        $aboutRequestOpts = array(CURLOPT_URL => "http://{$mockBaseUrl}/bo-ws/about");
        $aboutResponse = <<<JSON
{
  "x:type":"ws.response",
  "query":{
    "x:type":"ws.response.query",
    "parameters":{
      "x:type":"collection",
      "x:values":[

      ]
    },
    "properties":{
      "x:type":"x:dynamic"
    }
  },
  "result":{
    "x:type":"bows.about",
    "boWsVersion":{
      "x:type":"AfsVersion",
      "build":"3eaebfd1f1fe261780347cbc35bfbd65d613575e",
      "gen":"7.6",
      "major":"4",
      "minor":"0",
      "motto":"Pink Dolphin"
    },
    "copyright":"Copyright (C) 1999-2013 Antidot"
  }
}
JSON;
        $testContent = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<test>Francois Hollande mange des flamby</test>
</root>
XML;
        $testDocument = new AfsDocument($testContent, 'text/xml');
        $pafLiveResponse = <<<XML
-----Aa1Bb2Cc3---
Content-Disposition: form-data; name="urn:afs:6d57294f-1cd6-4220-8e10-e8ee9b518c78#CONTENTS"; filename=""
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<test>Francois Hollande mange des flamby</test>
</root>
-----Aa1Bb2Cc3---
Content-Disposition: form-data; name="urn:afs:6d57294f-1cd6-4220-8e10-e8ee9b518c78#USER_1"; filename=""
Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<afs:Entities xmlns:afs="http://ref.antidot.net/v7/afs#"><afs:entity type="PERSON" text="Francois Hollande" count="1" confidence="0.99"></afs:entity></afs:Entities>
-----Aa1Bb2Cc3-----

XML;
        $curlConnector = new SAI_CurlStub();
        //Set BO response for AboutConnector
        $curlConnector->setResponse($aboutResponse, $aboutRequestOpts);
        //Set response for other requests
        $curlConnector->setResponse($pafLiveResponse);
        $paf = new AfsPafLiveConnector($mockBaseUrl, $service, "pafName", $auth, AFS_SCHEME_HTTP, $curlConnector);
        $response = $paf->process_doc($testDocument);
        $contents = $response["CONTENTS"];
        $user = $response["USER_1"];
        $this->assertEquals("text/xml", $contents->get_mime_type());
        $layer_content = $contents->get_content();
        $this->assertFalse(empty($layer_content));
        $xml = simplexml_load_string($layer_content);
        $this->assertEquals("Francois Hollande mange des flamby", (string) $xml->test[0]);
        $layer_content = $user->get_content();
        $this->assertEquals("application/xml", $user->get_mime_type());
        $this->assertFalse(empty($layer_content));
        $xml = simplexml_load_string($layer_content, "SimpleXMLElement", 0, "afs", true);
        $this->assertEquals("Francois Hollande", (string) $xml->entity[0]->attributes()->text);
    }
Esempio n. 4
0
 private function init_introspector($response)
 {
     $curlConnector = new SAI_CurlStub();
     $mockBaseUrl = "localhost";
     $aboutRequestOpts = array(CURLOPT_URL => "http://{$mockBaseUrl}/bo-ws/about");
     $aboutResponse = ABOUT_RESPONSE;
     $curlConnector->setResponse($aboutResponse, $aboutRequestOpts);
     $curlConnector->setResponse($response);
     $search = new AfsSearch($mockBaseUrl, '71003', AfsServiceStatus::STABLE, $curlConnector);
     $intropsector = new AfsIntrospection($search);
     return $intropsector;
 }
Esempio n. 5
0
    /**
     * @expectedException Exception
     */
    public function testNotOrchestratedRequest()
    {
        $query = AfsQuery::create_from_parameters(array("query" => "topic", "mycustomparameter" => "mycustomvalue"));
        $curlConnector = new SAI_CurlStub();
        $mockBaseUrl = "localhost";
        $aboutRequestOpts = array(CURLOPT_URL => "http://{$mockBaseUrl}/bo-ws/about");
        $aboutResponse = <<<JSON
{
  "x:type":"ws.response",
  "query":{
    "x:type":"ws.response.query",
    "parameters":{
      "x:type":"collection",
      "x:values":[

      ]
    },
    "properties":{
      "x:type":"x:dynamic"
    }
  },
  "result":{
    "x:type":"bows.about",
    "boWsVersion":{
      "x:type":"AfsVersion",
      "build":"3eaebfd1f1fe261780347cbc35bfbd65d613575e",
      "gen":"7.6",
      "major":"4",
      "minor":"0",
      "motto":"Pink Dolphin"
    },
    "copyright":"Copyright (C) 1999-2013 Antidot"
  }
}
JSON;
        $response = <<<JSON


{"header":{"query":{"userId":"b756a0de-e252-426f-8a24-66c4bbb96aa0","sessionId":"dd33b13c-dd9f-49a1-abe1-95e89140fb40","date":"2015-10-14T15:12:00+0000","queryParam":[{"name":"afs:service","value":"42"},{"name":"afs:status","value":"beta"},{"name":"afs:query","value":"vert"},{"name":"afs:output","value":"json,2"},{"name":"afs:facetDefault","value":"replies=100"},{"name":"afs:replies","value":"20"},{"name":"afs:sort","value":"disposite, DESC and afs:relevance, DESC"}],"mainCtx":{"textQuery":"vert"},"textQuery":"vert"},"user":{"requestMethod":"GET","agent":"Mozilla\\/5.0 (X11; Linux x86_64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/42.0.2311.90 Safari\\/537.36","address":"172.17.42.1","output":{"format":"JSON","encoding":"gzip","charset":"UTF-8"}},"performance":{"durationMs":5},"info":{}},"replySet":[{"meta":{"uri":"Catalog","totalItems":1,"totalItemsIsExact":true,"pageItems":1,"firstPageItem":1,"lastPageItem":1,"durationMs":1,"firstPaFId":3,"lastPaFId":3,"producer":"SEARCH"},"facets":{"facet":[{"afs:t":"FacetTree","node":[{"key":"fr","labels":[{"label":"Français"}],"items":1}],"layout":"TREE","type":"STRING","id":"afs:lang","labels":[{"label":"Language"}]}]},"content":{"reply":[{"docId":4,"uri":"3612531066812_fr","title":[{"afs:t":"KwicMatch","match":"vert"}],"relevance":{"rank":1},"clientData":[{"contents":"<product xmlns=\\"http:\\/\\/ref.antidot.net\\/store\\/afs#\\" xmlns:xsi=\\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema-instance\\" id=\\"3612531066812\\" xml:lang=\\"fr\\" autocomplete=\\"on\\" xsi:schemaLocation=\\"http:\\/\\/ref.antidot.net\\/store\\/afs# http:\\/\\/ref.antidot.net\\/store\\/v4.1\\/xsd\\/product.xsd\\"><name xmlns=\\"http:\\/\\/ref.antidot.net\\/store\\/afs#\\">vert<\\/name><\\/product>","id":"main","mimeType":"text\\/xml"}]}]}}]}
JSON;
        //Set BO response for AboutConnector
        $curlConnector->setResponse($aboutResponse, $aboutRequestOpts);
        //Set response for query
        $curlConnector->setResponse($response);
        $search = new AfsSearch($mockBaseUrl, '71003', AfsServiceStatus::STABLE, $curlConnector);
        $search->set_query($query);
        $coder = new AfsQueryCoder();
        $search->set_query_coder($coder);
        $helper = $search->execute($query);
        $this->assertEquals($helper->is_orchestrated(), false);
        $helper->get_orchestration_type();
    }