|
| 1 | +Feature: Update or add a constant or variable in wp-config.php file |
| 2 | + |
| 3 | + Scenario: Update an existing constant in wp-config.php |
| 4 | + Given a WP install |
| 5 | + |
| 6 | + When I run `wp config update DB_HOST db.example.com` |
| 7 | + Then STDOUT should be: |
| 8 | + """ |
| 9 | + Success: Updated the constant 'DB_HOST' in the 'wp-config.php' file with the value 'db.example.com'. |
| 10 | + """ |
| 11 | + |
| 12 | + When I run `wp config get DB_HOST` |
| 13 | + Then STDOUT should be: |
| 14 | + """ |
| 15 | + db.example.com |
| 16 | + """ |
| 17 | + |
| 18 | + Scenario: Add a new constant when it doesn't exist |
| 19 | + Given a WP install |
| 20 | + |
| 21 | + When I run `wp config update NEW_CONSTANT constant_value` |
| 22 | + Then STDOUT should be: |
| 23 | + """ |
| 24 | + Success: Added the constant 'NEW_CONSTANT' to the 'wp-config.php' file with the value 'constant_value'. |
| 25 | + """ |
| 26 | + |
| 27 | + When I run `wp config get NEW_CONSTANT` |
| 28 | + Then STDOUT should be: |
| 29 | + """ |
| 30 | + constant_value |
| 31 | + """ |
| 32 | + |
| 33 | + Scenario: Update an existing constant then add it again |
| 34 | + Given a WP install |
| 35 | + |
| 36 | + When I run `wp config update TEST_CONSTANT first_value` |
| 37 | + Then STDOUT should be: |
| 38 | + """ |
| 39 | + Success: Added the constant 'TEST_CONSTANT' to the 'wp-config.php' file with the value 'first_value'. |
| 40 | + """ |
| 41 | + |
| 42 | + When I run `wp config update TEST_CONSTANT second_value` |
| 43 | + Then STDOUT should be: |
| 44 | + """ |
| 45 | + Success: Updated the constant 'TEST_CONSTANT' in the 'wp-config.php' file with the value 'second_value'. |
| 46 | + """ |
| 47 | + |
| 48 | + When I run `wp config get TEST_CONSTANT` |
| 49 | + Then STDOUT should be: |
| 50 | + """ |
| 51 | + second_value |
| 52 | + """ |
| 53 | + |
| 54 | + Scenario: Update a variable with --type=variable |
| 55 | + Given a WP install |
| 56 | + |
| 57 | + When I run `wp config update new_variable variable_value --type=variable` |
| 58 | + Then STDOUT should be: |
| 59 | + """ |
| 60 | + Success: Added the variable 'new_variable' to the 'wp-config.php' file with the value 'variable_value'. |
| 61 | + """ |
| 62 | + |
| 63 | + When I run `wp config update new_variable updated_value --type=variable` |
| 64 | + Then STDOUT should be: |
| 65 | + """ |
| 66 | + Success: Updated the variable 'new_variable' in the 'wp-config.php' file with the value 'updated_value'. |
| 67 | + """ |
| 68 | + |
| 69 | + When I run `wp config get new_variable` |
| 70 | + Then STDOUT should be: |
| 71 | + """ |
| 72 | + updated_value |
| 73 | + """ |
| 74 | + |
| 75 | + Scenario: Update raw values in wp-config.php |
| 76 | + Given a WP install |
| 77 | + |
| 78 | + When I run `wp config update WP_DEBUG true --raw` |
| 79 | + Then STDOUT should be: |
| 80 | + """ |
| 81 | + Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'. |
| 82 | + """ |
| 83 | + |
| 84 | + When I run `wp config list WP_DEBUG --strict --format=json` |
| 85 | + Then STDOUT should contain: |
| 86 | + """ |
| 87 | + {"name":"WP_DEBUG","value":true,"type":"constant"} |
| 88 | + """ |
| 89 | + |
| 90 | + When I run `wp config update WP_DEBUG false --raw` |
| 91 | + Then STDOUT should be: |
| 92 | + """ |
| 93 | + Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'false'. |
| 94 | + """ |
| 95 | + |
| 96 | + When I run `wp config list WP_DEBUG --strict --format=json` |
| 97 | + Then STDOUT should contain: |
| 98 | + """ |
| 99 | + {"name":"WP_DEBUG","value":false,"type":"constant"} |
| 100 | + """ |
| 101 | + |
| 102 | + @custom-config-file |
| 103 | + Scenario: Update a constant in wp-custom-config.php |
| 104 | + Given an empty directory |
| 105 | + And WP files |
| 106 | + |
| 107 | + When I run `wp config create {CORE_CONFIG_SETTINGS} --skip-check --config-file='wp-custom-config.php'` |
| 108 | + Then STDOUT should contain: |
| 109 | + """ |
| 110 | + Generated 'wp-custom-config.php' file. |
| 111 | + """ |
| 112 | + |
| 113 | + When I run `wp config update DB_HOST db.example.com --config-file='wp-custom-config.php'` |
| 114 | + Then STDOUT should be: |
| 115 | + """ |
| 116 | + Success: Updated the constant 'DB_HOST' in the 'wp-custom-config.php' file with the value 'db.example.com'. |
| 117 | + """ |
| 118 | + |
| 119 | + When I run `wp config get DB_HOST --config-file='wp-custom-config.php'` |
| 120 | + Then STDOUT should be: |
| 121 | + """ |
| 122 | + db.example.com |
| 123 | + """ |
| 124 | + |
| 125 | + Scenario: Ambiguous update requests throw errors |
| 126 | + Given a WP install |
| 127 | + |
| 128 | + When I run `wp config update SOME_NAME some_value --type=constant` |
| 129 | + Then STDOUT should be: |
| 130 | + """ |
| 131 | + Success: Added the constant 'SOME_NAME' to the 'wp-config.php' file with the value 'some_value'. |
| 132 | + """ |
| 133 | + |
| 134 | + When I run `wp config update SOME_NAME some_value --type=variable` |
| 135 | + Then STDOUT should be: |
| 136 | + """ |
| 137 | + Success: Added the variable 'SOME_NAME' to the 'wp-config.php' file with the value 'some_value'. |
| 138 | + """ |
| 139 | + |
| 140 | + When I run `wp config list --fields=name,type SOME_NAME --strict` |
| 141 | + Then STDOUT should be a table containing rows: |
| 142 | + | name | type | |
| 143 | + | SOME_NAME | constant | |
| 144 | + | SOME_NAME | variable | |
| 145 | + |
| 146 | + When I try `wp config update SOME_NAME some_value` |
| 147 | + Then STDERR should be: |
| 148 | + """ |
| 149 | + Error: Found both a constant and a variable 'SOME_NAME' in the 'wp-config.php' file. Use --type=<type> to disambiguate. |
| 150 | + """ |
| 151 | + |
| 152 | + Scenario: Update with placement options for new constants |
| 153 | + Given a WP install |
| 154 | + And a wp-config.php file: |
| 155 | + """ |
| 156 | + define( 'CONST_A', 'val-a' ); |
| 157 | + /** ANCHOR */ |
| 158 | + define( 'CONST_B', 'val-b' ); |
| 159 | + require_once( ABSPATH . 'wp-settings.php' ); |
| 160 | + """ |
| 161 | + |
| 162 | + When I run `wp config update SOME_NAME some_value --anchor="/** ANCHOR */" --placement=before --separator="\n"` |
| 163 | + Then STDOUT should be: |
| 164 | + """ |
| 165 | + Success: Added the constant 'SOME_NAME' to the 'wp-config.php' file with the value 'some_value'. |
| 166 | + """ |
| 167 | + And the wp-config.php file should be: |
| 168 | + """ |
| 169 | + define( 'CONST_A', 'val-a' ); |
| 170 | + define( 'SOME_NAME', 'some_value' ); |
| 171 | + /** ANCHOR */ |
| 172 | + define( 'CONST_B', 'val-b' ); |
| 173 | + require_once( ABSPATH . 'wp-settings.php' ); |
| 174 | + """ |
| 175 | + |
| 176 | + When I run `wp config update SOME_NAME updated_value --anchor="/** ANCHOR */" --placement=before --separator="\n"` |
| 177 | + Then STDOUT should be: |
| 178 | + """ |
| 179 | + Success: Updated the constant 'SOME_NAME' in the 'wp-config.php' file with the value 'updated_value'. |
| 180 | + """ |
| 181 | + And the wp-config.php file should be: |
| 182 | + """ |
| 183 | + define( 'CONST_A', 'val-a' ); |
| 184 | + define( 'SOME_NAME', 'updated_value' ); |
| 185 | + /** ANCHOR */ |
| 186 | + define( 'CONST_B', 'val-b' ); |
| 187 | + require_once( ABSPATH . 'wp-settings.php' ); |
| 188 | + """ |
0 commit comments