/** * @covers GravityView_API::replace_variables() * @covers GravityView_Merge_Tags::replace_variables() */ public function test_replace_variables() { $entry = GV_Unit_Tests_Bootstrap::instance()->get_entry(); $form = GV_Unit_Tests_Bootstrap::instance()->get_form(); // No match $this->assertEquals('no bracket', GravityView_API::replace_variables('no bracket', $form, $entry)); // Include bracket with nomatch $this->assertEquals($entry['id'] . ' {nomatch}', GravityView_API::replace_variables('{entry_id} {nomatch}', $form, $entry)); // Match tag, empty value $this->assertEquals('', GravityView_API::replace_variables('{user:example}', $form, $entry)); // Open matching tag $this->assertEquals('{entry_id', GravityView_API::replace_variables('{entry_id', $form, $entry)); // Form ID $this->assertEquals($form['id'], GravityView_API::replace_variables('{form_id}', $form, $entry)); // Form title $this->assertEquals('Example ' . $form['title'], GravityView_API::replace_variables('Example {form_title}', $form, $entry)); $this->assertEquals($entry['post_id'], GravityView_API::replace_variables('{post_id}', $form, $entry)); $this->assertEquals(date('m/d/Y'), GravityView_API::replace_variables('{date_mdy}', $form, $entry)); $this->assertEquals(get_option('admin_email'), GravityView_API::replace_variables('{admin_email}', $form, $entry)); $user = wp_set_current_user($entry['created_by']); // Test new Roles merge tag $this->assertEquals(implode(', ', $user->roles), GravityView_API::replace_variables('{created_by:roles}', $form, $entry)); $user->add_role('editor'); // Test new Roles merge tag again, with another role. $this->assertEquals(implode(', ', $user->roles), GravityView_API::replace_variables('{created_by:roles}', $form, $entry)); $var_content = '<p>I expect <strong>Entry #{entry_id}</strong> will be in Form #{form_id}</p>'; $expected_content = '<p>I expect <strong>Entry #' . $entry['id'] . '</strong> will be in Form #' . $form['id'] . '</p>'; $this->assertEquals($expected_content, GravityView_API::replace_variables($var_content, $form, $entry)); }
/** * Get the script and process uninstall * @since 1.15 */ function uninstall() { if (!defined('WP_UNINSTALL_PLUGIN')) { define('WP_UNINSTALL_PLUGIN', true); } if (!class_exists('GravityView_Uninstall')) { require_once GV_Unit_Tests_Bootstrap::instance()->plugin_dir . '/uninstall.php'; } else { new GravityView_Uninstall(); } }
/** * Get the single class instance * * @since 1.9 * @return GV_Unit_Tests_Bootstrap */ public static function instance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }