summaryrefslogtreecommitdiff
path: root/test/ConfigurationTest.php
blob: 7ee8ed2b76169c7b30fb3832af955b30b034533f (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
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
 * Created by PhpStorm.
 * User: topot
 * Date: 09.03.2018
 * Time: 16:26
 */

namespace andreskrey\Readability\Test;

use andreskrey\Readability\Configuration;

/**
 * Class ConfigurationTest
 * @package andreskrey\Readability\Test
 */
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider getParams
     * @param array $params
     */
    public function testConfigurationConstructorSetsParameters(array $params)
    {
        $config = new Configuration($params);
        $this->doEqualsAsserts($config, $params);
    }
    
    /**
     * @dataProvider getParams
     * @param array $params
     */
    public function testInvalidParameterIsNotInConfig(array $params)
    {
        $config = new Configuration($params);
        $this->assertArrayNotHasKey('invalidParameter', $config->toArray(), 'Invalid param key is not present in config');
    }
    
    /**
     * @param Configuration $config
     * @param array $options
     */
    private function doEqualsAsserts(Configuration $config, array $options)
    {
        // just part of params, it's enough
        $this->assertEquals($options['originalURL'], $config->getOriginalURL());
        $this->assertEquals($options['fixRelativeURLs'], $config->getFixRelativeURLs());
        $this->assertEquals($options['articleByLine'], $config->getArticleByLine());
        $this->assertEquals($options['maxTopCandidates'], $config->getMaxTopCandidates());
        $this->assertEquals($options['stripUnlikelyCandidates'], $config->getStripUnlikelyCandidates());
        $this->assertEquals($options['substituteEntities'], $config->getSubstituteEntities());
    }
    
    /**
     * @return array
     */
    public function getParams()
    {
        return [
            [
                [
                    'originalURL'             => 'my.original.url',
                    'fixRelativeURLs'         => true,
                    'articleByLine'           => true,
                    'maxTopCandidates'        => 3,
                    'stripUnlikelyCandidates' => false,
                    'substituteEntities'      => true,
                    'invalidParameter'        => 'invalidParameterValue',
                ],
            ],
        ];
    }
}