2)) ); } /** * @dataProvider providerTestM */ function testM($post_to_use) { global $post, $__attachments; $post = (object)array('ID' => 1); $backend = $this->getMock('ComicPressFakeBackend', array('generate_from_post')); $post_to_test = (!is_null($post_to_use)) ? $post_to_use : $post; $backend->expects($this->once())->method('generate_from_post')->with($post_to_test)->will($this->returnValue(array('test-1', 'test-2', 'test-3'))); $comicpress = ComicPress::get_instance(); $comicpress->backends = array($backend); $comicpress->comicpress_options['image_types'] = array(); update_post_meta($post_to_test->ID, 'image-ordering', array( 'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2')) )); $result = M($post_to_use); $this->assertEquals(array( array('default' => 'test-1', 'rss' => 'test-2') ), $result); $this->assertEquals($result, $__attachments); $this->assertEquals(array( 'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2')) ), get_post_meta($post_to_test->ID, 'image-ordering', true)); } function testProtect() { global $post, $wp_query, $__post, $__wp_query; $__post = null; $__wp_query = null; $post = "test"; $wp_query = "test2"; Protect(); $this->assertEquals($post, $__post); $this->assertEquals($wp_query, $__wp_query); } function testRestore() { global $post, $__post; $post = 'not'; $__post = 'test'; Restore(); $this->assertEquals($__post, $post); } function testUnprotect() { global $post, $__post, $wp_query, $__wp_query; $__post = $__wp_query = 'test'; $post = $wp_query = 'not'; Unprotect(); $this->assertEquals('test', $post); $this->assertEquals('test', $wp_query); $this->assertTrue(is_null($__post)); $this->assertTrue(is_null($__wp_query)); } function providerTestPrepR() { $post = (object)array('ID' => 1); return array( array( array(), array() ), array( 'from_post', array('from_post' => $post) ), array( array('test' => 'test'), array('test' => 'test') ), array( array('test' => '__post'), array('test' => $post) ), array( array('test' => array('test')), array('test' => array('test')) ), ); } /** * @dataProvider providerTestPrepR */ function testPrepR($restrictions, $expected_result) { $this->assertEquals($expected_result, __prep_R($restrictions, (object)array('ID' => 1))); } function providerTestEM() { return array( array(array(), 'embed', 'default', false, false), array( array('default' => 'test-1'), 'embed', 'default', 'test-1', 'embed' ), array( array('default' => 'test-1'), 'cats', 'default', 'test-1', false ), array( array('default' => 'test-1'), 'embed', 'comic', false, false ), array( array('default' => 'test-1', 'comic' => 'test-2'), 'embed', 'comic', 'test-2', 'embed' ), ); } /** * @dataProvider providerTestEM */ function testEM($info, $action, $which, $will_get_id, $expected_result) { $backend = $this->getMock('ComicPressFakeBackend', array('generate_from_id', 'embed', 'url')); if (is_string($will_get_id)) { $backend->expects($this->once())->method('generate_from_id')->with($will_get_id)->will($this->returnValue($backend)); if (method_exists($backend, $action)) { $backend->expects($this->once())->method($action)->will($this->returnValue($expected_result)); } else { $backend->expects($this->never())->method($action); } } else { $backend->expects($this->never())->method('generate_from_id'); } $comicpress = ComicPress::get_instance(); $comicpress->backends = array($backend); $this->assertEquals($expected_result, EM($info, $which, $action)); } }