Skip to content

Commit ec36ee2

Browse files
committed
Increase config code coverage
1 parent a3d103e commit ec36ee2

2 files changed

Lines changed: 142 additions & 3 deletions

File tree

src/util/config.spec.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import fs from 'fs';
33
import path from 'path';
44
import { describe, expect, test } from 'vitest';
55

6-
import { getWpConfig, getWpConfigByPath } from './config';
6+
import { getWpConfig, getWpConfigByPath, setupInitialWpConfig } from './config';
77

88
describe('getWpConfigByPath()', () => {
99
test('should call getWpConfig()', () => {
1010
const result = getWpConfigByPath(path.join(appRootPath, 'test/wordpress'));
11-
console.log(result);
11+
expect(result.dbHost).toBe('localhost');
12+
expect(result.dbPort).toBe(3306);
13+
expect(result.dbUser).toBe('username_here');
14+
expect(result.database).toBe('database_name_here');
1215
});
1316
});
1417

1518
describe('getWpConfig()', () => {
16-
test('parse wordpress config and get correct result', () => {
19+
test('parse wordpress sample config and get correct result', () => {
1720
const wpConfigSample = fs.readFileSync(
1821
path.join(appRootPath, 'test/wordpress/wp-config-sample.php'),
1922
'utf8'
@@ -24,4 +27,38 @@ describe('getWpConfig()', () => {
2427
expect(result.dbUser).toBe('username_here');
2528
expect(result.database).toBe('database_name_here');
2629
});
30+
test('parse wordpress config and get correct result', () => {
31+
const wpConfigSample = fs.readFileSync(
32+
path.join(appRootPath, 'test/wordpress/wp-config.php'),
33+
'utf8'
34+
);
35+
const result = getWpConfig(wpConfigSample);
36+
expect(result.dbHost).toBe('database.host.local');
37+
expect(result.dbPort).toBe(3389);
38+
expect(result.dbUser).toBe('username');
39+
expect(result.database).toBe('new_database');
40+
});
41+
});
42+
43+
describe('setupInitialWpConfig()', () => {
44+
test('should inject correct parameters', () => {
45+
const wpConfigSample = fs.readFileSync(
46+
path.join(appRootPath, 'test/wordpress/wp-config-sample.php'),
47+
'utf8'
48+
);
49+
const wpConfig = fs.readFileSync(
50+
path.join(appRootPath, 'test/wordpress/wp-config.php'),
51+
'utf8'
52+
);
53+
const newWpConfig = setupInitialWpConfig(
54+
wpConfigSample,
55+
'database.host.local',
56+
3389,
57+
'username',
58+
'password',
59+
'new_database',
60+
'test_passphrase'
61+
);
62+
expect(newWpConfig).equal(wpConfig);
63+
});
2764
});

test/wordpress/wp-config.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* The base configuration for WordPress
4+
*
5+
* The wp-config.php creation script uses this file during the installation.
6+
* You don't have to use the website, you can copy this file to "wp-config.php"
7+
* and fill in the values.
8+
*
9+
* This file contains the following configurations:
10+
*
11+
* * Database settings
12+
* * Secret keys
13+
* * Database table prefix
14+
* * ABSPATH
15+
*
16+
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
17+
*
18+
* @package WordPress
19+
*/
20+
21+
// ** Database settings - You can get this info from your web host ** //
22+
/** The name of the database for WordPress */
23+
define( 'DB_NAME', 'new_database' );
24+
25+
/** Database username */
26+
define( 'DB_USER', 'username' );
27+
28+
/** Database password */
29+
define( 'DB_PASSWORD', 'password' );
30+
31+
/** Database hostname */
32+
define( 'DB_HOST', 'database.host.local:3389' );
33+
34+
/** Database charset to use in creating database tables. */
35+
define( 'DB_CHARSET', 'utf8' );
36+
37+
/** The database collate type. Don't change this if in doubt. */
38+
define( 'DB_COLLATE', '' );
39+
40+
/**#@+
41+
* Authentication unique keys and salts.
42+
*
43+
* Change these to different unique phrases! You can generate these using
44+
* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
45+
*
46+
* You can change these at any point in time to invalidate all existing cookies.
47+
* This will force all users to have to log in again.
48+
*
49+
* @since 2.6.0
50+
*/
51+
define( 'AUTH_KEY', 'test_passphrase' );
52+
define( 'SECURE_AUTH_KEY', 'test_passphrase' );
53+
define( 'LOGGED_IN_KEY', 'test_passphrase' );
54+
define( 'NONCE_KEY', 'test_passphrase' );
55+
define( 'AUTH_SALT', 'test_passphrase' );
56+
define( 'SECURE_AUTH_SALT', 'test_passphrase' );
57+
define( 'LOGGED_IN_SALT', 'test_passphrase' );
58+
define( 'NONCE_SALT', 'test_passphrase' );
59+
60+
/**#@-*/
61+
62+
/**
63+
* WordPress database table prefix.
64+
*
65+
* You can have multiple installations in one database if you give each
66+
* a unique prefix. Only numbers, letters, and underscores please!
67+
*
68+
* At the installation time, database tables are created with the specified prefix.
69+
* Changing this value after WordPress is installed will make your site think
70+
* it has not been installed.
71+
*
72+
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix
73+
*/
74+
$table_prefix = 'wp_';
75+
76+
/**
77+
* For developers: WordPress debugging mode.
78+
*
79+
* Change this to true to enable the display of notices during development.
80+
* It is strongly recommended that plugin and theme developers use WP_DEBUG
81+
* in their development environments.
82+
*
83+
* For information on other constants that can be used for debugging,
84+
* visit the documentation.
85+
*
86+
* @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
87+
*/
88+
define( 'WP_DEBUG', false );
89+
90+
/* Add any custom values between this line and the "stop editing" line. */
91+
92+
93+
94+
/* That's all, stop editing! Happy publishing. */
95+
96+
/** Absolute path to the WordPress directory. */
97+
if ( ! defined( 'ABSPATH' ) ) {
98+
define( 'ABSPATH', __DIR__ . '/' );
99+
}
100+
101+
/** Sets up WordPress vars and included files. */
102+
require_once ABSPATH . 'wp-settings.php';

0 commit comments

Comments
 (0)