jetpack
Last commit date
3rd-party
9 years ago
_inc
1 year ago
bin
9 years ago
css
9 years ago
images
1 year ago
json-endpoints
9 years ago
languages
9 years ago
modules
1 year ago
sal
9 years ago
scss
9 years ago
sync
9 years ago
views
9 years ago
.svnignore
12 years ago
changelog.txt
9 years ago
class.frame-nonce-preview.php
9 years ago
class.jetpack-admin.php
9 years ago
class.jetpack-autoupdate.php
9 years ago
class.jetpack-bbpress-json-api-compat.php
9 years ago
class.jetpack-cli.php
9 years ago
class.jetpack-client-server.php
9 years ago
class.jetpack-client.php
9 years ago
class.jetpack-connection-banner.php
9 years ago
class.jetpack-constants.php
9 years ago
class.jetpack-data.php
9 years ago
class.jetpack-debugger.php
9 years ago
class.jetpack-error.php
10 years ago
class.jetpack-heartbeat.php
9 years ago
class.jetpack-idc.php
9 years ago
class.jetpack-ixr-client.php
10 years ago
class.jetpack-jitm.php
9 years ago
class.jetpack-modules-list-table.php
9 years ago
class.jetpack-network-sites-list-table.php
9 years ago
class.jetpack-network.php
9 years ago
class.jetpack-options.php
9 years ago
class.jetpack-post-images.php
9 years ago
class.jetpack-signature.php
9 years ago
class.jetpack-tracks.php
9 years ago
class.jetpack-twitter-cards.php
9 years ago
class.jetpack-user-agent.php
9 years ago
class.jetpack-xmlrpc-server.php
9 years ago
class.jetpack.php
9 years ago
class.json-api-endpoints.php
3 years ago
class.json-api.php
10 years ago
class.photon.php
9 years ago
composer.json
10 years ago
functions.compat.php
9 years ago
functions.gallery.php
10 years ago
functions.global.php
9 years ago
functions.opengraph.php
9 years ago
functions.photon.php
9 years ago
jetpack.php
1 year ago
json-api-config.php
10 years ago
json-endpoints.php
9 years ago
locales.php
9 years ago
readme.txt
1 year ago
require-lib.php
10 years ago
rest-api.md
9 years ago
uninstall.php
9 years ago
webpack.config.js
9 years ago
wpml-config.xml
10 years ago
class.jetpack-constants.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class Jetpack_Constants |
| 5 | * |
| 6 | * Testing constants is hard. Once you define a constant, it's defined. Jetpack_Constants is an |
| 7 | * abstraction layer so that unit tests can set "constants" for tests. |
| 8 | * |
| 9 | * To test your code, you'll need to swap out `defined( 'CONSTANT' )` with `Jetpack_Constants::is_defined( 'CONSTANT' )` |
| 10 | * and replace `CONSTANT` with `Jetpack_Constants::get_constant( 'CONSTANT' )`. Then in the unit test, you can set the |
| 11 | * constant with `Jetpack::set_constant( 'CONSTANT', $value )` and then clean up after each test with something like |
| 12 | * this: |
| 13 | * |
| 14 | * function tearDown() { |
| 15 | * Jetpack_Constants::clear_constants(); |
| 16 | * } |
| 17 | */ |
| 18 | class Jetpack_Constants { |
| 19 | static $set_constants = array(); |
| 20 | |
| 21 | /** |
| 22 | * Checks if a "constant" has been set in Jetpack_Constants, and if not, |
| 23 | * checks if the constant was defined with define( 'name', 'value ). |
| 24 | * |
| 25 | * @param $name string The name of the constant |
| 26 | * |
| 27 | * @return bool |
| 28 | */ |
| 29 | public static function is_defined( $name ) { |
| 30 | return array_key_exists( $name, self::$set_constants ) |
| 31 | ? true |
| 32 | : defined( $name ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Attempts to retrieve the "constant" from Jetpack_Constants, and if it hasn't been set, |
| 37 | * then attempts to get the constant with the constant() function. |
| 38 | * |
| 39 | * @param $name |
| 40 | * |
| 41 | * @return mixed null if the constant does not exist or the value of the constant. |
| 42 | */ |
| 43 | public static function get_constant( $name ) { |
| 44 | if ( array_key_exists( $name, self::$set_constants ) ) { |
| 45 | return self::$set_constants[ $name ]; |
| 46 | } |
| 47 | |
| 48 | return defined( $name ) ? constant( $name ) : null; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Sets the value of the "constant" within Jetpack_Constants. |
| 53 | * |
| 54 | * @param $name string The name of the "constant" |
| 55 | * @param $value string The value of the "constant" |
| 56 | */ |
| 57 | public static function set_constant( $name, $value ) { |
| 58 | self::$set_constants[ $name ] = $value; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Will unset a "constant" from Jetpack_Constants if the constant exists. |
| 63 | * |
| 64 | * @param $name string The name of the "constant" |
| 65 | * |
| 66 | * @return bool Whether the constant was removed. |
| 67 | */ |
| 68 | public static function clear_single_constant( $name ) { |
| 69 | if ( ! array_key_exists( $name, self::$set_constants ) ) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | unset( self::$set_constants[ $name ] ); |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Resets all of the constants within Jetpack_Constants. |
| 79 | */ |
| 80 | public static function clear_constants() { |
| 81 | self::$set_constants = array(); |
| 82 | } |
| 83 | } |
| 84 |