summaryrefslogtreecommitdiff
path: root/lib/querypath/test/Tests/QueryPath/OptionsTest.php
blob: d2efbc9f1c51372b2e25a9d7edd7d6c95e4f5f4e (plain)
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
<?php
/**
 * Tests for the QueryPath library.
 * @author M Butcher <matt@aleph-null.tv>
 * @license The GNU Lesser GPL (LGPL) or an MIT-like license.
 */
namespace QueryPath\Tests;
require_once __DIR__ . '/TestCase.php';
use \QueryPath\Options;

/**
 * @ingroup querypath_tests
 */
class OptionsTest extends TestCase {

  public function testOptions() {
    $expect = array('test1' => 'val1', 'test2' => 'val2');
    $options = array('test1' => 'val1', 'test2' => 'val2');

    Options::set($options);

    $results = Options::get();
    $this->assertEquals($expect, $results);

    $this->assertEquals('val1', $results['test1']);
  }

  public function testQPOverrideOrder() {
    $expect = array('test1' => 'val3', 'test2' => 'val2');
    $options = array('test1' => 'val1', 'test2' => 'val2');

    Options::set($options);
    $qpOpts = qp(NULL, NULL, array('test1'=>'val3', 'replace_entities' => TRUE))->getOptions();

    $this->assertEquals($expect['test1'], $qpOpts['test1']);
    $this->assertEquals(TRUE, $qpOpts['replace_entities']);
    $this->assertNull($qpOpts['parser_flags']);
    $this->assertEquals($expect['test2'], $qpOpts['test2']);
  }

  public function testQPHas() {
    $options = array('test1' => 'val1', 'test2' => 'val2');

    Options::set($options);
    $this->assertTrue(Options::has('test1'));
    $this->assertFalse(Options::has('test3'));
  }
  public function testQPMerge() {
    $options = array('test1' => 'val1', 'test2' => 'val2');
    $options2 = array('test1' => 'val3', 'test4' => 'val4');

    Options::set($options);
    Options::merge($options2);

    $results = Options::get();
    $this->assertTrue(Options::has('test4'));
    $this->assertEquals('val3', $results['test1']);
  }

}