Welcome to mirror list, hosted at ThFree Co, Russian Federation.

install.php « install « tests « tests - github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5387520b792a609ba4693c274164e839dee6d1ae (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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php

/**
 * Checks install misc functions
 *
 * @group install
 */
class Install_Tests extends PHPUnit\Framework\TestCase {

    /**
	 * Check if YOURLS is declared installed
	 */
	public function test_install() {
		$this->assertTrue( yourls_is_installed() );
	}

	/**
	 * Check that tables were correctly populated during install
	 */
	public function test_init_tables() {
		// This should fail because these inserts have been taken care of during install
		$this->assertFalse( yourls_initialize_options() );
		$this->assertFalse( yourls_insert_sample_links() );
	}

	/**
	 * Test (sort of) table creation
	 */
	public function test_create_tables() {

        /* The expected result has:
         *   - success messages: the table are created with a "CREATE IF NOT EXISTS",
         *     hence, will not be recreated once more, they're already created
         *     upon install procedure
         *   - error messages: the function cannot initialize options and links, since
         *     they have been populated during install procedure as well
         *
         * A more thorough test would be to mockup the DB connection and create another
         * set of tables (with another prefix for instance).
         * Well. Consider this for next DB engine maybe? :)
         */

        $expected = array(
            'success' => array (
                "Table 'yourls_url' created.",
                "Table 'yourls_options' created.",
                "Table 'yourls_log' created.",
                "YOURLS tables successfully created.",
            ),
            'error' => array (
                'Could not initialize options',
                'Could not insert sample short URLs',
            ),
        );

        $this->assertSame( $expected, yourls_create_sql_tables() );
	}

	/**
	 * Test (sort of) defining constants
	 */
    public function test_correct_config() {
        $test = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);

        // This should return a readable file
        $readable = is_readable($test->find_config(YOURLS_CONFIGFILE));
        $this->assertTrue($readable);
        // For the record, $this->assertFileIsReadable() was introduced around PHPUnit 5.6

        // redefining YOURLS_ constants should not throw any error ("constant already defined...")
        // or define any new constants
        $consts = get_defined_constants(true);
        $before = $consts['user'];
        $test->define_core_constants();
        $consts = get_defined_constants(true);
        $after = $consts['user'];
        $this->assertSame($before,$after);
    }

	/**
	 * Test incorrect config provided
	 */
    public function test_incorrect_config() {
        $this->expectException(YOURLS\Exceptions\ConfigException::class);
        $this->expectExceptionMessageMatches('/User defined config not found at \'[0-9a-z]+\'/');

        $test = new \YOURLS\Config\Config(rand_str());
        $test->find_config();
    }

	/**
	 * Test config not found
	 */
    public function test_not_found_config() {
        $this->expectException(YOURLS\Exceptions\ConfigException::class);
        $this->expectExceptionMessage('Cannot find config.php. Please read the readme.html to learn how to install YOURLS');

        $test = new \YOURLS\Config\Config();
        $test->set_root(rand_str());
        $test->find_config();
    }

	/**
	 * Test Init actions. Not sure this is a good idea, might become cumbersome to maintain?
	 */
    public function test_init_defaults() {
        $test = new \YOURLS\Config\InitDefaults();

        $expected = array (
            'include_core_funcs' => true,
            'default_timezone' => true,
            'load_default_textdomain' => true,
            'check_maintenance_mode' => true,
            'fix_request_uri' => true,
            'redirect_ssl' => true,
            'include_db' => true,
            'include_cache' => true,
            'return_if_fast_init' => true,
            'get_all_options' => true,
            'register_shutdown' => true,
            'core_loaded' => true,
            'redirect_to_install' => true,
            'check_if_upgrade_needed' => true,
            'load_plugins' => true,
            'plugins_loaded_action' => true,
            'check_new_version' => true,
            'init_admin' => true,
        );

        $actual = get_class_vars(get_class($test));

        $this->assertSame($expected, $actual);
    }

}