Changeset 777152
- Timestamp:
- 09/23/2013 08:54:40 AM (13 years ago)
- Location:
- post-by-email/trunk
- Files:
-
- 2 added
- 5 edited
-
class-post-by-email.php (modified) (6 diffs)
-
post-by-email.php (modified) (1 diff)
-
readme.md (modified) (2 diffs)
-
readme.txt (modified) (6 diffs)
-
tests/messages (added)
-
tests/messages/message_with_attachments (added)
-
tests/test-post-by-email.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
post-by-email/trunk/class-post-by-email.php
r777049 r777152 25 25 * @var string 26 26 */ 27 protected $version = '1.0. 3';27 protected $version = '1.0.4'; 28 28 29 29 /** … … 245 245 update_option( 'post_by_email_options', $options ); 246 246 247 $this->connection = $this->open_mailbox_connection( $options ); 248 249 if (! $this->connection ) { 247 $connection_options = array( 248 'username' => $options['mailserver_login'], 249 'password' => $options['mailserver_pass'], 250 'hostspec' => $options['mailserver_url'], 251 'port' => $options['mailserver_port'], 252 'secure' => $options['ssl'] ? 'ssl' : false, 253 ); 254 255 $this->connection = $this->open_mailbox_connection( $connection_options ); 256 257 if ( ! $this->connection ) { 250 258 return; 251 259 } … … 255 263 if ( 0 === sizeof( $uids ) ) { 256 264 $this->save_log_message( __( 'There doesn’t seem to be any new mail.', 'post-by-email' ) ); 257 $this->c onnection->shutdown();265 $this->close_connection(); 258 266 return; 259 267 } … … 445 453 $this->mark_as_read( $uids, $options['delete_messages'] ); 446 454 447 $this->c onnection->shutdown();455 $this->close_connection(); 448 456 } 449 457 … … 471 479 * @return object 472 480 */ 473 protected function open_mailbox_connection( $options ) { 474 $connection_options = array( 475 'username' => $options['mailserver_login'], 476 'password' => $options['mailserver_pass'], 477 'hostspec' => $options['mailserver_url'], 478 'port' => $options['mailserver_port'], 479 'secure' => $options['ssl'] ? 'ssl' : false, 480 ); 481 481 protected function open_mailbox_connection( $connection_options ) { 482 482 if ( 'POP3' == $options['mailserver_protocol'] ) { 483 $this->protocol = 'POP3'; 483 484 $connection = new Horde_Imap_Client_Socket_Pop3( $connection_options ); 484 $this->protocol = 'POP3';485 485 } else { // IMAP 486 $this->protocol = 'IMAP'; 486 487 $connection = new Horde_Imap_Client_Socket( $connection_options ); 487 $this->protocol = 'IMAP';488 488 } 489 489 $connection->_setInit( 'authmethod', 'USER' ); … … 498 498 499 499 return $connection; 500 } 501 502 /** 503 * Closes the connection to the mailserver. 504 * 505 * @since 1.0.4 506 */ 507 protected function close_connection() { 508 $this->connection->shutdown(); 500 509 } 501 510 -
post-by-email/trunk/post-by-email.php
r773033 r777152 13 13 * Plugin URI: http://codebykat.wordpress.com 14 14 * Description: Create new posts on your WordPress blog by sending email to a specific email address. 15 * Version: 1.0. 315 * Version: 1.0.4 16 16 * Author: Kat Hagan 17 17 * Author URI: http://profiles.wordpress.org/codebykat -
post-by-email/trunk/readme.md
r777065 r777152 127 127 128 128 1. WordPress version (e.g. 3.6.x). 129 1. Plugin version (e.g. 1.0. 3).129 1. Plugin version (e.g. 1.0.4). 130 130 1. PHP version (e.g. 5.2.x or 5.3.x). 131 131 1. Your mailbox settings (URL, protocol, port and whether SSL is enabled; not your login and password). … … 140 140 * Added support for user-included gallery shortcode (allows use of WP's gallery options). 141 141 * Added warning when checking email before changed settings have been saved. 142 * Added more unit tests. 142 143 * Code style fixes as per http://gsoc.trac.wordpress.org/ticket/377 143 144 * Fixed https://github.com/codebykat/wp-post-by-email/issues/3 -
post-by-email/trunk/readme.txt
r777065 r777152 4 4 Requires at least: 3.6 5 5 Tested up to: 3.7 6 Stable tag: trunk 6 7 License: GPLv2 or later 7 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 97 98 == Testing == 98 99 99 ### Automated Tests ### 100 = Automated Tests = 100 101 101 102 Like WordPress Core, this plugin includes automated unit tests written in PHPUnit. … … 106 107 1. From the plugin directory, run `WP_TESTS_DIR=/path/to/WordPress/test/install phpunit` 107 108 108 ### Manual Testing ### 109 = Manual Testing = 109 110 110 111 1. Set up a test email address (services such as Gmail work great for this) and enable IMAP or POP3 access. (Refer to <a href="http://wordpress.org/plugins/post-by-email/installation/">Installation</a> for detailed instructions.) … … 113 114 1. Navigate to the "Activity Log" tab and press the "Check Now" button. When the page reloads, you should see a new entry in the log file describing the results of the mail check. 114 115 115 **Caveat** 116 There is sometimes a delay between sending an email and having it show up in the mailbox, especially with POP3. If you're using IMAP, you can connect using a third-party mail client to verify that messages have been received, then mark them as unread so Post By Email will pick them up. 116 **Caveat:** There is sometimes a delay between sending an email and having it show up in the mailbox, especially with POP3. If you're using IMAP, you can connect using a third-party mail client to verify that messages have been received, then mark them as unread so Post By Email will pick them up. 117 117 118 118 … … 124 124 125 125 1. WordPress version (e.g. 3.6.x). 126 1. Plugin version (e.g. 1.0. 3).126 1. Plugin version (e.g. 1.0.4). 127 127 1. PHP version (e.g. 5.2.x or 5.3.x). 128 128 1. Your mailbox settings (URL, protocol, port and whether SSL is enabled; not your login and password). … … 137 137 * Added support for user-included gallery shortcode (allows use of WP's gallery options). 138 138 * Added warning when checking email before changed settings have been saved. 139 * Added more unit tests. 139 140 * Code style fixes as per http://gsoc.trac.wordpress.org/ticket/377 140 141 * Fixed https://github.com/codebykat/wp-post-by-email/issues/3 -
post-by-email/trunk/tests/test-post-by-email.php
r764618 r777152 1 1 <?php 2 2 /** 3 * Post By Email Unit Tests 4 * 5 * @package PostByEmail 6 * @author Kat Hagan <kat@codebykat.com> 7 * @license GPL-2.0+ 8 * @link http://codebykat.wordpress.com 9 * @copyright 2013 Kat Hagan 10 */ 11 12 /** 13 * Plugin test class. 14 * 15 * @package PostByEmail 16 * @author Kat Hagan <kat@codebykat.com> 17 */ 3 18 class Tests_Post_By_Email_Plugin extends WP_UnitTestCase { 4 19 20 /** 21 * Instantiation of the plugin. 22 * 23 * @since 1.0.4 24 * 25 * @var object 26 */ 5 27 protected $plugin; 6 28 7 function setUp() { 29 /** 30 * Set up the tests. 31 * 32 * @since 1.0.4 33 */ 34 public function setUp() { 8 35 parent::setUp(); 9 36 $this->plugin = Post_By_Email::get_instance(); 10 $this->pluginAdmin = Post_By_Email_Admin::get_instance(); 11 } 12 13 function test_plugin_activation() { 37 $options = Post_By_Email::$default_options; 38 $option['status'] = ''; 39 update_option( 'post_by_email_options', $options ); 40 } 41 42 /** 43 * Set an option in the plugin's options array. 44 * 45 * @since 1.0.4 46 * 47 * @var $key Option name 48 * @var $value Option value 49 */ 50 protected function set_option( $key, $value ) { 51 $options = get_option( 'post_by_email_options' ); 52 $options[ $key ] = $value; 53 update_option( 'post_by_email_options', $options ); 54 } 55 56 /** 57 * Get an option from the plugin's options array. 58 * 59 * @since 1.0.4 60 * 61 * @var string Option name to retrieve 62 * 63 * @return string Option's value 64 */ 65 protected function get_option( $key ) { 66 $options = get_option( 'post_by_email_options' ); 67 return $options[ $key ]; 68 } 69 70 /** 71 * Get the last message logged by the plugin. 72 * 73 * @since 1.0.4 74 * 75 * @return string Last message logged 76 */ 77 protected function get_last_log_message() { 78 $log = get_option( 'post_by_email_log' ); 79 if ( $log ) { 80 $last_entry = array_shift( $log ); 81 return $last_entry['message']; 82 } 83 return 'Nothing logged.'; 84 } 85 86 /** 87 * Test plugin activation. 88 * 89 * @since 0.9.7 90 */ 91 public function test_plugin_activation() { 14 92 // with no preexisting options and no global ones, use defaults 15 93 delete_option( 'post_by_email_options' ); … … 17 95 $this->plugin->activate( false ); 18 96 19 $options = get_option( 'post_by_email_options' ); 20 $this->assertEquals( 'mail.example.com', $options['mailserver_url'] ); 97 $this->assertEquals( 'mail.example.com', $this->get_option( 'mailserver_url' ) ); 21 98 22 99 // copy over the global options if they exist … … 26 103 27 104 $this->assertNotEquals( false, get_option ('post_by_email_options' ) ); 28 $options = get_option( 'post_by_email_options' ); 29 $this->assertEquals( 'testing.example.com', $options['mailserver_url'] ); 105 $this->assertEquals( 'testing.example.com', $this->get_option( 'mailserver_url' ) ); 30 106 31 107 // when we have preexisting options, those should take precedence 32 108 update_option( 'mailserver_url', 'another.example.com' ); 33 109 $this->plugin->activate( false ); 34 $options = get_option( 'post_by_email_options' ); 35 $this->assertNotEquals( 'another.example.com', $options['mailserver_url'] ); 36 } 37 38 function test_wp_cron_setup() { 110 $this->assertNotEquals( 'another.example.com', $this->get_option( 'mailserver_url' ) ); 111 } 112 113 /** 114 * Test setup of wp_cron on activate/deactivate. 115 * 116 * @since 0.9.8 117 */ 118 public function test_wp_cron_setup() { 39 119 // plugin activation should schedule an event with wp_cron 40 120 $this->plugin->activate( false ); … … 46 126 } 47 127 48 function test_check_email() { 49 $this->markTestIncomplete(); 50 } 51 52 function test_save_log_message() { 53 // testing a protected method: bad idea? 54 $this->markTestIncomplete(); 55 56 // // if the log doesn't exist, it should be created 57 // $options = get_option( 'post_by_email_options' ); 58 // unset($options['log']); 59 // update_option( 'post_by_email_options', $options); 60 61 // $this->plugin->save_log_message("Test message"); 62 63 // $options = get_option( 'post_by_email_options' ); 64 // $this->assertEquals( 1, sizeof( $options['log'] ) ); 65 66 // // if the log exists already, the new message should be added to it 67 // $this->plugin->save_log_message("Test message two"); 68 69 // $options = get_option( 'post_by_email_options' ); 70 // $this->assertEquals( 2, sizeof( $options['log'] ) ); 71 } 128 /** 129 * Test that plugin does nothing if options haven't been set. 130 * 131 * @since 1.0.4 132 */ 133 public function test_return_if_options_not_set() { 134 $this->set_option( 'mailserver_url', 'mail.example.com' ); 135 $this->set_option( 'status', 'unconfigured' ); 136 137 $stub = $this->getMock( 'Post_By_Email', array( 'open_mailbox_connection', 'get_messages', 'close_connection' ), array(), '', false ); 138 139 $stub->check_email(); 140 141 // should immediately return without doing anything 142 $stub->expects( $this->never() ) 143 ->method( 'open_mailbox_connection' ); 144 145 $stub->expects( $this->never() ) 146 ->method( 'get_messages' ); 147 148 $this->assertEquals( 'Nothing logged.', $this->get_last_log_message() ); 149 } 150 151 /** 152 * Test opening a POP3 connection with the right options. 153 * 154 * @since 1.0.4 155 */ 156 public function test_open_POP3_connection() { 157 $stub = $this->getMock( 'Post_By_Email', array( 'open_mailbox_connection', 'get_messages', 'close_connection' ), array(), '', false ); 158 159 $this->set_option( 'mailserver_url', 'mail.test.com' ); 160 $this->set_option( 'mailserver_port', '110' ); 161 $this->set_option( 'ssl', false ); 162 $this->set_option( 'mailserver_protocol', 'POP3' ); 163 $this->set_option( 'mailserver_login', 'test@test.com' ); 164 $this->set_option( 'mailserver_pass', 'password' ); 165 $this->set_option( 'status', '' ); 166 167 $connection_options = array( 168 'username' => 'test@test.com', 169 'password' => 'password', 170 'hostspec' => 'mail.test.com', 171 'port' => 110, 172 'secure' => false, 173 ); 174 175 $stub->expects( $this->once() ) 176 ->method( 'open_mailbox_connection' ) 177 ->with( $this->equalTo( $connection_options ) ); 178 179 $stub->check_email(); 180 181 $this->assertEquals( 'Nothing logged.', $this->get_last_log_message() ); 182 } 183 184 /** 185 * Test checking mailbox with no new messages found. 186 * 187 * @since 1.0.4 188 */ 189 public function test_check_email_no_new_messages() { 190 $this->set_option( 'status', '' ); 191 192 $stub = $this->getMock( 'Post_By_Email', array( 'open_mailbox_connection', 'get_messages', 'close_connection' ), array(), '', false ); 193 194 $stub->expects( $this->once() ) 195 ->method( 'open_mailbox_connection' ) 196 ->will( $this->returnValue( true ) ); 197 198 $stub->expects( $this->once() ) 199 ->method( 'get_messages' ) 200 ->will( $this->returnValue( array() ) ); 201 202 $stub->expects( $this->once() ) 203 ->method( 'close_connection' ); 204 205 $stub->check_email(); 206 207 $this->assertEquals( "There doesn’t seem to be any new mail.", $this->get_last_log_message() ); 208 } 209 210 /** 211 * Test checking mailbox and finding a new message. 212 * 213 * @since 1.0.4 214 */ 215 public function test_check_mail() { 216 $this->set_option( 'status', '' ); 217 218 $methods_to_stub = array( 219 'open_mailbox_connection', 220 'get_messages', 221 'close_connection', 222 'get_message_headers', 223 'get_message_body', 224 'save_attachments', 225 'mark_as_read', 226 ); 227 $stub = $this->getMock( 'Post_By_Email', $methods_to_stub, array(), '', false ); 228 229 $stub->expects( $this->once() ) 230 ->method( 'open_mailbox_connection' ) 231 ->will( $this->returnValue( true ) ); 232 233 $message_text = file_get_contents( 'messages/message_with_attachments', true ); 234 $headers = Horde_Mime_Headers::parseHeaders( $message_text ); 235 236 $stub->expects( $this->once() ) 237 ->method( 'get_messages' ) 238 ->will( $this->returnValue( array( 1 ) ) ); 239 240 $stub->expects( $this->once() ) 241 ->method( 'get_message_headers' ) 242 ->will( $this->returnValue( $headers ) ); 243 244 $message = Horde_Mime_Part::parseMessage( $message_text ); 245 $body = $message->getPart('1.1')->toString(); 246 247 $stub->expects( $this->once() ) 248 ->method( 'get_message_body' ) 249 ->will( $this->returnValue( $body ) ); 250 251 $stub->expects( $this->once() ) 252 ->method( 'save_attachments' ); 253 254 $stub->expects( $this->once() ) 255 ->method( 'mark_as_read' ); 256 257 $stub->expects( $this->once() ) 258 ->method( 'close_connection' ); 259 260 $stub->check_email(); 261 262 $this->stringContains( "Found 1 new message.", $this->get_last_log_message() ); 263 $this->assertRegExp( '/Posted(.*?)' . $headers->getValue('Subject') . '/', $this->get_last_log_message() ); 264 } 265 72 266 }
Note: See TracChangeset
for help on using the changeset viewer.