Example #1
0
 function test_update_gist_succeed()
 {
     cmb2_update_option(WP_Gistpen::$plugin_name, '_wpgp_gist_token', '1234');
     $this->mock_adapter->shouldReceive('build')->with('gist')->once()->andReturn($this->mock_gist_adapter);
     $this->mock_gist_adapter->shouldReceive('update_by_commit')->once()->andReturn(array());
     $this->mock_github_client->shouldReceive('authenticate')->once()->shouldReceive('update')->once()->withArgs(array('gist_id', array()))->andReturn(array('id' => '1234'));
     $this->mock_commit->shouldReceive('get_head_gist_id')->once()->andReturn('gist_id');
     $result = $this->gist->update_gist($this->mock_commit);
     $this->assertEquals(array('id' => '1234'), $result);
 }
 function test_save_and_retrieve_succeed()
 {
     $this->_setRole('administrator');
     $this->create_post_and_children();
     $this->zip = $this->database->query('head')->by_id($this->gistpen->ID);
     $gist = new GistTest(WP_Gistpen::$plugin_name, WP_Gistpen::$version);
     $gist->set_client($this->mock_github_client);
     App::get('sync')->gist = $gist;
     cmb2_update_option(WP_Gistpen::$plugin_name, '_wpgp_gist_token', '1234');
     $this->mock_github_client->shouldReceive('authenticate')->times(3)->shouldReceive('create')->once()->andReturn(array('id' => 'abcde1234', 'history' => array(array('version' => 'thisversion'))))->shouldReceive('update')->twice()->andReturn(array('id' => 'abcde1234', 'history' => array(array('version' => 'thisversion'))));
     $this->add_and_test_first_save();
     $this->add_and_test_first_save_export();
     $this->add_and_test_second_save();
     $this->add_and_test_second_save_export();
     $this->add_and_test_third_save();
     $this->add_and_test_third_save_export();
 }
Example #3
0
 public function test_cmb2_update_option()
 {
     $new_value = 'James';
     cmb2_update_option($this->options_cmb->cmb_id, 'my_name', $new_value);
     $get = get_option($this->options_cmb->cmb_id);
     $val = cmb2_get_option($this->options_cmb->cmb_id, 'my_name');
     $this->assertEquals($new_value, $get['my_name']);
     $this->assertEquals($val, $get['my_name']);
     $this->assertEquals($val, $new_value);
 }
Example #4
0
 /**
  * Sets the Gist token.
  *
  * Get your Gist token by following
  * the instructions found here:
  * http://jamesdigioia.com/wp-gistpen/#gist-token
  *
  * ## OPTIONS
  *
  * <token>
  * : Your Gist token.
  *
  * ## EXAMPLES
  *
  *     wp wpgp set_token 123545678910abcde
  *
  * @synopsis <token>
  */
 function set_token($args, $assoc_args)
 {
     list($token) = $args;
     $client = new Gist(\WP_Gistpen::$plugin_name, \WP_Gistpen::$version);
     $client->authenticate($token);
     if (is_wp_error($error = $client->check_token())) {
         WP_CLI::error(__('Gist token failed to authenticate. Error: ', \WP_Gistpen::$plugin_name) . $error->get_error_message());
     }
     $success = cmb2_update_option(\WP_Gistpen::$plugin_name, '_wpgp_gist_token', $token);
     if (!$success) {
         WP_CLI::error(__('Gist token update failed.', \WP_Gistpen::$plugin_name));
     }
     WP_CLI::success(__('Gist token updated.', \WP_Gistpen::$plugin_name));
 }
Example #5
0
 function tearDown()
 {
     parent::tearDown();
     m::close();
     cmb2_update_option(WP_Gistpen::$plugin_name, '_wpgp_gist_token', false);
 }
Example #6
0
    /**
     * Display GitHub user info on settings page
     *
     * @since 0.5.0
     */
    public function github_user_layout()
    {
        $token = cmb2_get_option($this->plugin_name, '_wpgp_gist_token');
        if (false === $token) {
            return;
        }
        $user = get_transient('_wpgp_github_token_user_info');
        if (false === $user) {
            $this->client->authenticate($token);
            if (is_wp_error($error = $this->client->check_token())) {
                // If this token doesn't validate, clear it and bail.
                cmb2_update_option($this->plugin_name, '_wpgp_gist_token', '');
                delete_transient('_wpgp_github_token_user_info');
                return;
            }
            $user = get_transient('_wpgp_github_token_user_info');
        }
        $login = array_key_exists('login', $user) ? $user['login'] : '';
        $email = array_key_exists('email', $user) ? $user['email'] : '';
        $public_gists = array_key_exists('public_gists', $user) ? $user['public_gists'] : '0';
        $private_gists = array_key_exists('private_gists', $user) ? $user['private_gists'] : '0';
        ?>
<h3>Authorized User</h3>

		<strong><?php 
        _e('Username: '******'Email: ', $this->plugin_name);
        ?>
</strong><?php 
        echo esc_html($email);
        ?>
<br>
		<strong><?php 
        _e('Public Gists: ', $this->plugin_name);
        ?>
</strong><?php 
        echo esc_html($public_gists);
        ?>
<br>
		<strong><?php 
        _e('Private Gists: ', $this->plugin_name);
        ?>
</strong><?php 
        echo esc_html($private_gists);
        ?>
<br><br>

		<p class="cmb2-metabox-description">
			<?php 
        submit_button('Export Gistpens', 'secondary', 'export-gistpens', false);
        ?>
			<?php 
        _e("When you export  Gistpens, all Gistpens are exported, even if sync is unchecked. Sync will be enabled for those Gistpens; you can disable them individually.", $this->plugin_name);
        ?>
		</p>

		<p class="cmb2-metabox-description">
			<?php 
        submit_button('Import Gists', 'secondary', 'import-gists', false);
        ?>
			<?php 
        _e("When you import Gists, only Gists not previously imported will be added.", $this->plugin_name);
        ?>
		</p>
		<?php 
    }