Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

QueryTest.php 3.82 KB
Newer Older
Olivier Lequeux's avatar
Olivier Lequeux committed
1
<?php
2 3
//
//require_once dirname(__FILE__) . '/../Query.php';
4
//require_once dirname(__FILE__) . '/../HydratorInterface.php';
5 6
//require_once dirname(__FILE__) . '/../Hydrators/DefaultHydrator.php';
//require_once dirname(__FILE__) . '/../Hydrators/EntriesHydrator.php';
Olivier Lequeux's avatar
Olivier Lequeux committed
7 8 9 10 11 12

use \Lavoisier\Query;


class QueryTest extends \PHPUnit_Framework_TestCase
{
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    public function testUseHydrators() {

        // SimpleXML
        $stubQuery = $this->getMock('Lavoisier\Query', array('curl'), array('localhost'));
        $stubQuery->expects($this->any())
            ->method('curl')
            ->will($this->returnValue(array('content'=>
                        file_get_contents(dirname(__FILE__) . "/Resources/tickets.xml"))));

        $hydrator = new \Lavoisier\Hydrators\SimpleXMLHydrator();
        $hydrator->registerEntriesNamespace(false);
        $stubQuery->setHydrator($hydrator);
        $result = $stubQuery->execute();

        $this->assertEquals(50455, strval($result->entries[0]->entry[0]));
    }



Olivier Lequeux's avatar
Olivier Lequeux committed
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
    public function testQuery()
    {
        $xlq = new Query('localhost', 'myView');

        $expected_query_string = "http://localhost:8080/lavoisier/myView/NGIs/NGI[@name='foo' or @name='bar']?accept=xml";
        $path = sprintf('/NGIs/NGI[%s]', Query::buildPredicate('@name', array('foo', 'bar')));
        $xlq->setPath($path);
        $this->assertEquals($expected_query_string, $xlq->getUrl());

        $expected_query_string = "http://localhost:9000/notify/yourView";
        $xlq->setPath($path);
        $xlq->setOperation('notify');
        $xlq->setPort('9000');
        $xlq->setView('yourView');
        $this->assertEquals($expected_query_string, $xlq->getUrl());
    }

    public function testHelpers()
    {

        $output_expected = "F1=V1&F2=V2";
        $fields_string = Query::urlify(array('F1' => 'V1', 'F2' => 'V2'));
        $this->assertEquals($output_expected, $fields_string);
    }

    public function testBuildPredicate()
    {

        $predicate = Query::buildPredicate('@key', array('IN2P3-CC', 'IN2P3-CC-T2', 'AM-02-SEUA', 'AEGIS01-IPB-SCL'));
        $this->assertEquals("@key='IN2P3-CC' or @key='IN2P3-CC-T2' or @key='AM-02-SEUA' or @key='AEGIS01-IPB-SCL'", $predicate);

        $predicate = Query::buildEntriesPredicate(
            array('GHD_Affected_Site' => 'IN2P3-CC', 'GHD_Status' => 'assigned'),
            'or', false);
        $this->assertEquals(
            "(@key='GHD_Affected_Site' and text()='IN2P3-CC') or (@key='GHD_Status' and text()='assigned')",
            $predicate);

        $predicate = Query::buildEntriesPredicate(
            array('GHD_Affected_Site' => array('IN2P3-CC', 'IN2P3-CC-T2'), 'GHD_Status' => 'assigned'),
            'or', false);
        $this->assertEquals(
            "(@key='GHD_Affected_Site' and text()='IN2P3-CC') or (@key='GHD_Affected_Site' and text()='IN2P3-CC-T2') or (@key='GHD_Status' and text()='assigned')",
            $predicate);

        $predicate = Query::buildEntriesPredicate(array(), 'or');
        $this->assertEquals('true()', $predicate);
        $predicate = Query::buildEntriesPredicate(array('EMPTY_ARRAY' => array()), 'or');
        $this->assertEquals('true()', $predicate);


    }

Olivier Lequeux's avatar
Olivier Lequeux committed
85 86 87 88 89 90 91 92
    public function testIsRunning() {

        $q =new Query("nohost");
        $this->assertEquals("http://nohost:8080/lavoisier", $q ->getUrl(false, "console"));
        $this->assertEquals(false, $q->isInstanceRunning());

    }

Thibaut Salanon's avatar
Thibaut Salanon committed
93 94 95 96 97 98 99 100 101 102 103 104 105
    public function testParsedUrl(){

        $q = new Query('cclavoisierfr.in2p3.fr:8080', 'OPSCORE_SITE', 'lavoisier');
        $this->assertEquals('cclavoisierfr.in2p3.fr', $q->getHostname());
        $this->assertEquals('8080', $q->getPort());


        $q = new Query('cclavoisierfr.in2p3.fr', 'OPSCORE_SITE', 'lavoisier');
        $this->assertEquals('cclavoisierfr.in2p3.fr', $q->getHostname());
        $this->assertEquals('8080', $q->getPort());

    }

Olivier Lequeux's avatar
Olivier Lequeux committed
106
}