diff --git a/.scrutinizer.yml b/.scrutinizer.yml
new file mode 100644
index 0000000..6b39007
--- /dev/null
+++ b/.scrutinizer.yml
@@ -0,0 +1,14 @@
+# .scrutinizer.yml
+build:
+ nodes:
+ analysis:
+ project_setup:
+ override: true
+ tests:
+ override: [php-scrutinizer-run]
+tools:
+ #external_code_coverage: true
+filter:
+ excluded_paths:
+ - "tests/"
+ - "RoboFile.php"
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index e2fdec7..15d6461 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,52 +1,28 @@
language: php
php:
-- "5.3"
-- "5.4"
-- "5.5"
+- "7.0"
+- "7.1"
env:
-- WP_VERSION=4.1.1 WP_MULTISITE=0
-- WP_VERSION=4.1 WP_MULTISITE=0
-- WP_VERSION=4.0.1 WP_MULTISITE=0
-- WP_VERSION=4.1.1 WP_MULTISITE=1
-- WP_VERSION=4.1 WP_MULTISITE=1
-- WP_VERSION=4.0.1 WP_MULTISITE=1
+- WP_VERSION=4.9.1 WP_MULTISITE=0
+- WP_VERSION=4.9 WP_MULTISITE=0
before_script:
-- curl http://cs.sensiolabs.org/get/php-cs-fixer.phar -o php-cs-fixer.phar
-- curl -s http://getcomposer.org/installer | php
-- php composer.phar install --dev --no-interaction --prefer-source
+- composer install --dev --no-interaction
#Coveralls support
- mkdir -p build/logs
- mkdir -p build/cov
-#phpUnit setup
-#- mkdir -p tmp
-# Initialize the WP core directory
-- export WP_CORE_DIR=/tmp/wordpress/
-- wget -nv -O /tmp/wordpress.tar.gz https://github.com/WordPress/WordPress/tarball/$WP_VERSION
-- mkdir -p $WP_CORE_DIR
-- tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
-# Initialize the WP unit test directory
-- export WP_TESTS_DIR=/tmp/wordpress-tests/
-- svn co http://develop.svn.wordpress.org/tags/$WP_VERSION /tmp/wordpress-tests/
-# Set up the database access
-- cp /tmp/wordpress-tests/wp-tests-config-sample.php /tmp/wordpress-tests/wp-tests-config.php
-- sed -i "s:dirname( __FILE__ ) . '/wordpress/':'$WP_CORE_DIR':" /tmp/wordpress-tests/wp-tests-config.php
-- sed -i "s/youremptytestdbnamehere/wordpress_test/" /tmp/wordpress-tests/wp-tests-config.php
-- sed -i "s/yourusernamehere/root/" /tmp/wordpress-tests/wp-tests-config.php
-- sed -i "s/yourpasswordhere//" /tmp/wordpress-tests/wp-tests-config.php
-- mysql -e 'CREATE DATABASE wordpress_test;' -uroot
script:
-- phpunit
+- ./vendor/bin/robo tests $WP_VERSION
after_script:
-- php vendor/bin/coveralls -v --dry-run
+#- php vendor/bin/coveralls -v --dry-run
notifications:
email:
recipients:
- - daryl@clubduece.com
+ - daryl@clubduece.net
on_success: change
on_failure: always
diff --git a/RoboFile.php b/RoboFile.php
new file mode 100644
index 0000000..78679b5
--- /dev/null
+++ b/RoboFile.php
@@ -0,0 +1,65 @@
+taskExec('mysql -e "CREATE DATABASE IF NOT EXISTS test_db"')->run();
+ $this->taskExec('mysql -e "GRANT ALL ON test_db.* to \'root\'@\'%\'"')->run();
+ $this->taskSvnStack()
+ ->checkout("https://develop.svn.wordpress.org/tags/{$version} wp-tests")
+ ->run();
+
+ $this->setTestConfig();
+ $this->phpunit();
+
+ }
+
+ /**
+ * Run the test suite using the default configuration.
+ *
+ * @param string $config The relative path to the PHPUnit XML configuration file.
+ */
+ function phpunit($config = 'tests/phpunit.xml.dist')
+ {
+ $this->taskPhpUnit('vendor/bin/phpunit')
+ ->configFile($config)
+ ->envVars(array('WP_TESTS_DIR' => 'wp-tests'))
+ ->run();
+ }
+
+ private function setTestConfig()
+ {
+
+ if (file_exists('wp-tests/wp-tests-config-sample.php')) {
+ copy('wp-tests/wp-tests-config-sample.php', 'wp-tests/wp-tests-config.php');
+ }
+
+ $this->taskReplaceInFile( 'wp-tests/wp-tests-config.php')
+ ->from('youremptytestdbnamehere')
+ ->to('test_db')
+ ->run();
+
+ $this->taskReplaceInFile( 'wp-tests/wp-tests-config.php')
+ ->from('yourusernamehere')
+ ->to('root')
+ ->run();
+
+ $this->taskReplaceInFile( 'wp-tests/wp-tests-config.php')
+ ->from('yourpasswordhere')
+ ->to('')
+ ->run();
+ }
+}
diff --git a/controllers/class-base-controller-plugin.php b/controllers/class-base-controller-plugin.php
deleted file mode 100644
index 796cece..0000000
--- a/controllers/class-base-controller-plugin.php
+++ /dev/null
@@ -1,235 +0,0 @@
- null,
- ) );
-
- parent::__construct( $args );
-
- add_action( 'plugins_loaded', array( $this, 'load_text_domain' ) );
- add_action( 'admin_notices', array( $this, 'admin_notice' ) );
- add_action( 'init', array( $this, 'register_post_types' ) );
- }
-
- /**
- * Load the plugin text domain.
- *
- * @internal
- * @access public
- * @since WPMVCBase 0.1
- */
- public function load_text_domain()
- {
- // if ( is_dir( $this->model->get_path() . '/languages/' ) ) {
- // load_plugin_textdomain(
- // $this->model->get_txtdomain(),
- // false,
- // $this->model->get_path() . '/languages/'
- // );
- // }
- }
-
- public function register_post_types()
- {
- foreach ( $this->model->get_post_types() as $slug => $args ) {
- register_post_type( $slug, $args );
- }
- }
-
- /**
- * Render admin notices for admin screens.
- *
- * @internal
- * @access public
- * @since WPMVCBase 0.1
- */
- public function admin_notice()
- {
- $current_screen = get_current_screen();
- $notices = $this->model->get_admin_notices();
-
- if ( isset ( $notices ) && is_array( $notices ) ) {
- foreach ( $notices as $notice ) {
- $screens = $notice->get_screens();
-
- if ( is_array( $screens ) && in_array( $current_screen->id, $screens ) ) {
- echo $notice->get_message();
- }
-
- if ( in_array( 'all', $screens ) ) {
- echo $notice->get_message();
- }
- }
- }
- }
-
- /**
- * The WP load-{$page} action callback
- *
- * @internal
- * @access public
- * @since WPMVCBase 0.1
- */
- public function load_admin_page()
- {
- //determine the page we are on
- $screen = get_current_screen();
-
- //are there help tabs for this screen?
- $tabs = $this->model->get_help_tabs();
- if ( ! empty ($tabs[ $screen->id ] ) ) {
- foreach ( $tabs[ $screen->id ] as $tab ) {
- $tab->add();
- }
- }
-
- //are there javascripts registered for this screen?
- $admin_js = $this->model->get_admin_scripts();
- if ( ! empty( $admin_js[ $screen->id ] ) ) {
- foreach ( $admin_js[ $screen->id ] as $script ) {
- $script->enqueue();
- $script->localize();
- }
- }
-
- //are there styles registered for this screen?
- $css = $this->model->get_admin_css();
- if ( ! empty( $css[ $screen->id ] ) ):
- Helper_Functions::enqueue_styles( $css[ $screen->id ] );
- endif;
- }
-
- /**
- * Enqueue scripts and styles for admin pages
- *
- * @uses Helper_Functions::enqueue_styles
- * @uses Helper_Functions::enqueue_scripts
- * @uses Base_Model_Plugin::get_admin_css
- * @uses Base_Model_Plugin::get_admin_scripts
- * @internal
- * @access public
- * @since WPMVCBase 0.1
- * @todo modify this function to enqueue scripts based on wp_screen object
- */
- public function admin_enqueue_scripts()
- {
- //register the scripts
- $scripts = $this->model->get_admin_scripts();
-
- if ( isset( $scripts ) && is_array( $scripts ) ) {
- foreach ( $scripts as $script ) {
- wp_enqueue_script(
- $script->get_handle(),
- $script->get_src(),
- $script->get_deps(),
- $script->get_version(),
- $script->get_in_footer()
- );
- }
- }
- }
-
- /**
- * Enqueue scripts and styles for frontend pages.
- *
- * @uses Base_Model_Plugin::get_scripts
- * @uses Base_Contoller::enqueue_scripts
- * @internal
- * @access public
- * @since WPMVCBase 0.1
- */
- public function wp_enqueue_scripts()
- {
- //add the global javascripts
- $scripts = $this->model->get_scripts();
-
- if ( isset( $scripts ) && is_array( $scripts ) ) {
- parent::enqueue_scripts( $scripts );
- }
- }
-
- /**
- * Hook actions for the help tabs for the plugin model.
- *
- * @uses Base_Model_Plugin::get_help_tabs
- * @uses Base_Model_Help_Tab::get_screens
- * @since WPMVCBase 0.2
- */
- // protected function init_help_tabs()
- // {
- // // Get the help tabs defined for the plugin model
- // $tabs = $this->model->get_help_tabs();
-
- // if ( isset( $tabs ) && is_array( $tabs ) ) {
- // foreach( $tabs as $tab ) {
- // //get the screens on which to display this tab
- // $screens = $tab->get_screens();
- // foreach( $screens as $screen ) {
- // add_action( $screen, array( &$this, 'render_help_tabs' ) );
- // }
- // }
- // }
- // }
-
- /**
- * Render the help tabs for the plugin model.
- *
- * @uses Base_Model_Plugin::get_help_tabs
- * @uses Base_Controller_Plugin::render_help_tab
- * @since WPMVCBase 0.2
- */
- public function render_help_tabs()
- {
- $tabs = $this->model->get_help_tabs();
- $screen = get_current_screen();
-
- foreach( $tabs as $tab ) {
- if ( in_array( $screen->post_type, $tab->get_post_types() ) ) {
- parent::render_help_tab( $tab );
- }
- }
- }
- }
-} // ! class_exists( 'Base_Controller_Plugin' )
diff --git a/controllers/class-controller-base.php b/controllers/class-controller-base.php
index 6fa59f0..9780144 100644
--- a/controllers/class-controller-base.php
+++ b/controllers/class-controller-base.php
@@ -1,217 +1,221 @@
null,
+ 'view' => null,
+ ) );
+
+ $this->_args = $args;
+ $this->_model = $args['model'];
+ $this->_view = $args['view'];
+
+ add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
+
+ parent::__construct( $args );
+
+ }
+
+ /**
+ * @return Model_Base
+ *
+ * @since 1.0
+ */
+ public function model() {
+
+ return $this->_model;
+
+ }
+
+ /**
+ * @return View_Base
+ *
+ * @since 1.0
+ */
+ public function view() {
+
+ return $this->_view;
+
+ }
+
/**
- * The base controller.
+ * Add shortcodes to WP.
*
- * @package WPMVCBase\Controllers
- * @abstract
- * @version 0.2
- * @since WPMVCBase 0.2
+ * @param array $shortcodes An array of key/value pairs containing the shortcode as key and the callback function as value.
+ * @return \WP_Error|null
+ * @since WPMVCBase 0.1
*/
- abstract class WPMVC_Controller_Base {
-
- /**
- * The args passed to the constructor
- *
- * @var array
- * @access protected
- * @since 0.4
- */
- protected $args;
-
- /**
- * The model for this controller
- *
- * @var object
- * @access protected
- * @since 0.4
- */
- protected $model;
-
- /**
- * The view for this controller
- *
- * @var object
- * @access protected
- * @since 0.4
- */
- protected $view;
-
- /**
- * The class constructor
- *
- * @access public
- * @since WPMVCBase 0.1
- */
- public function __construct( array $args = array() ) {
-
- $args = wp_parse_args( $args, array(
- 'model' => null,
- 'view' => null,
- ) );
-
- $this->args = $args;
- $this->model = $args['model'];
- $this->view = $args['view'];
-
- add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
- add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
+ public function add_shortcodes( array $shortcodes ) {
+ foreach ( $shortcodes as $key => $shortcode ) {
+ add_shortcode( $key, $shortcode );
}
-
- /**
- * Add shortcodes to WP.
- *
- * @param array $shortcodes An array of key/value pairs containing the shortcode as key and the callback function as value.
- * @return WP_Error|null
- * @since WPMVCBase 0.1
- */
- public function add_shortcodes( array $shortcodes ) {
-
- foreach ( $shortcodes as $key => $shortcode ) {
- add_shortcode( $key, $shortcode );
+
+ }
+
+ /**
+ * Enqueue scripts.
+ *
+ * @param array $scripts Array containing Base_Model_JS objects
+ * @return \WP_Error|null WP_Error object on failure.
+ * @since WPMVCBase 0.3
+ */
+ public function enqueue_scripts( array $scripts ) {
+
+ foreach ( $scripts as $key => $script ) {
+ if( is_a( $script, 'Base_Model_JS_Object' ) ) {
+ wp_enqueue_script(
+ $script->get_handle(),
+ $script->get_src(),
+ $script->get_deps(),
+ $script->get_ver(),
+ $script->get_in_footer()
+ );
}
- }
-
- /**
- * Enqueue scripts.
- *
- * @param array $scripts Array containing Base_Model_JS objects
- * @return WP_Error|null WP_Error object on failure.
- * @since WPMVCBase 0.3
- */
- public function enqueue_scripts( array $scripts ) {
-
- foreach ( $scripts as $key => $script ) {
- if( is_a( $script, 'Base_Model_JS_Object' ) ) {
- wp_enqueue_script(
- $script->get_handle(),
- $script->get_src(),
- $script->get_deps(),
- $script->get_ver(),
- $script->get_in_footer()
- );
+ if( ! is_a( $script, 'Base_Model_JS_Object' ) ) {
+ if( ! isset( $wp_error ) ) {
+ $wp_error = new \WP_Error();
}
-
- if( ! is_a( $script, 'Base_Model_JS_Object' ) ) {
- if( ! isset( $wp_error ) ) {
- $wp_error = new WP_Error();
- }
-
- $wp_error->add(
- 'invalid object type',
- sprintf( __( '%s is not a Base_Model_JS_Object', 'wpmvcbase' ), $key ),
- $script
- );
- }
- }
-
- //return the error object for invalid script types
- if( isset( $wp_error ) ) {
- return $wp_error;
+
+ $wp_error->add(
+ 'invalid object type',
+ sprintf( __( '%s is not a Base_Model_JS_Object', 'wpmvcbase' ), $key ),
+ $script
+ );
}
+ }
+ //return the error object for invalid script types
+ if( isset( $wp_error ) ) {
+ return $wp_error;
}
+ }
- /**
- * Render a help tab.
- *
- * @param object Base_Model_Help_Tab
- * access public
- * @since 1.0
- */
- public function render_help_tab( Base_Model_Help_Tab $tab ) {
- $screen = get_current_screen();
-
- $screen->add_help_tab(
- array(
- 'id' => $tab->get_id(),
- 'title' => $tab->get_title(),
- 'content' => $tab->get_content()
- )
- );
+ /**
+ * Render a help tab.
+ *
+ * @param object Base_Model_Help_Tab
+ * @access public
+ * @since 1.0
+ */
+ public function render_help_tab( Base_Model_Help_Tab $tab ) {
- }
+ $screen = get_current_screen();
- /**
- * Implement magic __call method
- *
- * @param string $method The method name
- * @param array $args Parameters passed to the method called
- * @return mixed|WP_Error
- * @access public
- * @since 0.4
- */
- public function __call( $method, $args ) {
-
- $message = sprintf( __( 'Method %s not found in class %s or its model or view', 'wpmvcb' ), $method, get_called_class() );
- $value = new WP_Error( 400, $message );
-
- // try the model and view first
- foreach( array( $this->view, $this->model ) as $object ) {
- if ( is_object( $object ) ) {
- if ( method_exists( $object, $method ) ) {
- $value = call_user_func_array( array( $object, $method ), $args );
- }
- }
- }
+ $screen->add_help_tab(
+ array(
+ 'id' => $tab->get_id(),
+ 'title' => $tab->get_title(),
+ 'content' => $tab->get_content()
+ )
+ );
- if ( is_wp_error( $value ) ) {
- // there is no match
- trigger_error( $message );
+ }
+
+ /**
+ * Implement magic __call method
+ *
+ * @param string $method The method name
+ * @param array $args Parameters passed to the method called
+ * @return mixed
+ *
+ * @since 0.4
+ */
+ public function __call( $method, $args ) {
+
+ do {
+ // All the_xxx methods go to the view
+ if ( preg_match( '#^the_.+?$#', $method ) ) {
+ $value = call_user_func_array( array( $this->view(), $method ), $args );
+ break;
}
- return $value;
+ //Otherwise, they go to the model
+ $value = call_user_func_array( array( $this->model(), $method ), $args );
- }
+ } while ( false );
- /**
- * Implement magic __get method
- *
- * @param string $property The property name
- * @return mixed
- * @access public
- * @since 0.4
- */
- public function __get( $property ) {
-
- $message = sprintf( __( 'Property %s not found in %s or its model or view', 'wpmvcb' ), $property, get_called_class() );
- $value = new WP_Error( 400, $message );
-
- foreach( array( $this->view, $this->model ) as $object ) {
- if ( is_object( $object ) && property_exists( $object, $property ) ) {
- $value = $object->{$property};
- }
- }
+ return $value;
+
+ }
- if ( is_wp_error( $value ) ) {
- trigger_error( $message );
+ /**
+ * Implement magic __get method
+ *
+ * @param string $property The property name
+ * @return mixed
+ * @access public
+ * @since 0.4
+ */
+ public function __get( $property ) {
+
+ $message = sprintf( __( 'Property %s not found in %s or its model or view', 'wpmvcb' ), $property, get_called_class() );
+ $value = new \WP_Error( 400, $message );
+
+ foreach( array( $this->_view, $this->_model ) as $object ) {
+ if ( is_object( $object ) && property_exists( $object, $property ) ) {
+ $value = $object->{$property};
}
+ }
- return $value;
+ if ( is_wp_error( $value ) ) {
+ trigger_error( $message );
}
+ return $value;
}
}
diff --git a/controllers/class-cpt-base.php b/controllers/class-cpt-base.php
deleted file mode 100644
index e069211..0000000
--- a/controllers/class-cpt-base.php
+++ /dev/null
@@ -1,285 +0,0 @@
-ID;
- }
-
- if ( is_callable( array( $post, 'get_id' ) ) ) {
- $post_id = $post::get_id();
- }
- }
-
-
- if ( is_int( $post ) ) {
- $post_id = $post;
- }
-
- $class = get_called_class();
-
- if ( ! 0 == $post_id ) {
- $cache_key = sprintf( '%1$s_%2$s', $class::$post_type, $post_id );
- }
-
- return $cache_key;
-
- }
- /**
- * Filter to ensure the CPT labels are displayed when user updates the CPT
- *
- * @param string $messages The existing messages array.
- * @return array $messages The updated messages array.
- * @internal
- * @access public
- * @since WPMVCBase 0.1
- * @link http://codex.wordpress.org/Plugin_API/Filter_Reference
- */
- public static function post_updated_messages( $messages ) {
-
- $post = get_post();
-
- $post_type_object = get_post_type_object( $post->post_type );
- $singular = $post_type_object->labels->singular_name;
-
- $messages[ $post->post_type ] = array(
- 0 => null, // Unused. Messages start at index 1.
- 1 => sprintf(
- __( '%1$s updated. View %2$s', 'wpmvcb' ),
- $singular,
- strtolower( $singular ),
- esc_url( get_permalink( $post->ID ) )
- ),
- 2 => __( 'Custom field updated.', 'wpmvcb' ),
- 3 => __( 'Custom field deleted.', 'wpmvcb' ),
- 4 => sprintf( __( '%s updated.', 'wpmvcb' ), $singular ),
- /* translators: %2$s: date and time of the revision */
- 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %s', 'wpmvcb' ), $singular, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
- 6 => sprintf( __( '%1$s published. View %1$s', 'wpmvcb' ), $singular, esc_url( get_permalink( $post->ID ) ) ),
- 7 => sprintf( __( '%s saved.', 'wpmvcb' ), $singular ),
- 8 => sprintf(
- __( '%1$s submitted. Preview %2$s', 'wpmvcb' ),
- $singular,
- strtolower( $singular ),
- esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) )
- ),
- 9 => sprintf(
- __( '%3$s scheduled for: %1$s. Preview %4$s', 'wpmvcb' ),
- // translators: Publish box date format, see http://php.net/date
- date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ),
- esc_url( get_permalink( $post->ID ) ),
- $singular,
- strtolower( $singular )
- ),
- 10 => sprintf(
- __( '%1$s draft updated. Preview %2$s', 'wpmvcb' ),
- $singular,
- strtolower( $singular ),
- esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) )
- )
- );
-
- return $messages;
- }
-
- /**
- * Initialize the CPT labels
- *
- * @param string $singular The singular post type name
- * @param string $plural The plural post type name
- * @return string[] The post type labels
- * @access protected
- * @since WPMVCBase 0.1
- */
- protected static function init_labels( $singular = __CLASS__, $plural = __CLASS__ ) {
-
- return array(
- 'name' => $plural,
- 'singular_name' => $singular,
- 'menu_name' => $plural,
- 'parent_item_colon' => sprintf( __( 'Parent %s', 'wpmvcb' ), $singular ),
- 'all_items' => sprintf( __( 'All %s', 'wpmvcb' ), $plural ),
- 'view_item' => sprintf( __( 'View %s', 'wpmvcb' ), $singular ),
- 'add_new_item' => sprintf( __( 'Add New %s', 'wpmvcb' ), $singular ),
- 'add_new' => sprintf( __( 'New %s', 'wpmvcb' ), $singular ),
- 'edit_item' => sprintf( __( 'Edit %s', 'wpmvcb' ), $singular ),
- 'update_item' => sprintf( __( 'Update %s', 'wpmvcb' ), $singular ),
- 'search_items' => sprintf( __( 'Search %s', 'wpmvcb' ), $plural ),
- 'not_found' => sprintf( __( 'No %s found', 'wpmvcb' ), strtolower( $plural ) ),
- 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'wpmvcb' ), strtolower( $plural ) ),
- );
-
- }
-
- /**
- * Register necessary actions, filters, etc. when loading the class
- */
- public static function on_load() {
-
- add_filter( 'post_updated_messages', array( __CLASS__, 'post_updated_messages' ) );
-
- }
-
- /**
- * @param string $method
- * @param array $args
- *
- * @return mixed|WP_Error
- */
- public function __call( $method, $args ) {
-
- $value = parent::__call( $method, $args );
-
- // has a method been called that matches a global WP function ?
- if( ( is_wp_error( $value ) ) ) {
- if ( function_exists( $method ) && $this->model->has_post() ) {
- global $post;
- $original_post = $post;
- $post = $this->model->get_post();
- setup_postdata( $post );
-
- $value = call_user_func_array( $method, $args );
-
- $post = $original_post;
- setup_postdata( $post );
- }
- }
-
- if ( is_wp_error( $value ) ) {
- // there is no match
- trigger_error( $message );
- }
-
- return $value;
- }
-
- /**
- * Verify it is okay to save the post
- *
- * @param array $args
- * @return bool
- * @since 0.3.4
- */
- public static function okay_to_save( $post_id, $args = array() ) {
-
- $okay = true;
- $args = wp_parse_args( $args, array(
- 'post_type' => 'post',
- ) );
-
- //do not respond to inline-save (aka Quick Edit)
- $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING );
- if( 'inline-save' == $action ) {
- $okay = false;
- }
-
- if ( ! current_user_can( 'edit_posts' ) ) {
- $okay = false;
- }
-
- if ( ! ( get_post_type( $post_id ) == $args['post_type'] ) ) {
- $okay = false;
- }
-
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- $okay = false;
- }
-
- return $okay;
-
- }
-
- }
-
-}
diff --git a/controllers/class-metabox-base.php b/controllers/class-metabox-base.php
deleted file mode 100644
index cdc8228..0000000
--- a/controllers/class-metabox-base.php
+++ /dev/null
@@ -1,58 +0,0 @@
- new WPMVCB_Metabox_Default_View(),
- ) );
-
- parent::__construct( $args );
-
- foreach ( $this->model->get_post_types() as $post_type ) {
- add_action( "add_meta_boxes_{$post_type}", array( $this, 'add' ) );
- }
- }
-
- /**
- * Add the metabox
- *
- * @param WP_Post $post
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function add( $post ) {
-
- add_meta_box(
- $this->model->get_id(),
- $this->model->get_title(),
- array( $this->view, 'render' ),
- $post->post_type,
- $this->model->get_context(),
- $this->model->get_priority(),
- $this->model->get_callback_args( $post )
- );
-
- }
-
-}
diff --git a/controllers/class-post-base.php b/controllers/class-post-base.php
new file mode 100644
index 0000000..5887d7a
--- /dev/null
+++ b/controllers/class-post-base.php
@@ -0,0 +1,35 @@
+ new Post_Model_Base( $item, $args ),
+ 'view' => new Post_View_Base( $this ),
+ ) );
+
+ parent::__construct( $args );
+ }
+
+}
\ No newline at end of file
diff --git a/controllers/class-post-type-base.php b/controllers/class-post-type-base.php
new file mode 100644
index 0000000..e538f79
--- /dev/null
+++ b/controllers/class-post-type-base.php
@@ -0,0 +1,223 @@
+post_type );
+ $singular = $post_type_object->labels->singular_name;
+
+ $messages[ $post->post_type ] = array(
+ 0 => null, // Unused. Messages start at index 1.
+ 1 => sprintf(
+ __( '%1$s updated. View %2$s', 'wpmvcb' ),
+ $singular,
+ strtolower( $singular ),
+ esc_url( get_permalink( $post->ID ) )
+ ),
+ 2 => __( 'Custom field updated.', 'wpmvcb' ),
+ 3 => __( 'Custom field deleted.', 'wpmvcb' ),
+ 4 => sprintf( __( '%s updated.', 'wpmvcb' ), $singular ),
+ /* translators: %2$s: date and time of the revision */
+ 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %s', 'wpmvcb' ), $singular, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
+ 6 => sprintf( __( '%1$s published. View %1$s', 'wpmvcb' ), $singular, esc_url( get_permalink( $post->ID ) ) ),
+ 7 => sprintf( __( '%s saved.', 'wpmvcb' ), $singular ),
+ 8 => sprintf(
+ __( '%1$s submitted. Preview %2$s', 'wpmvcb' ),
+ $singular,
+ strtolower( $singular ),
+ esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) )
+ ),
+ 9 => sprintf(
+ __( '%3$s scheduled for: %1$s. Preview %4$s', 'wpmvcb' ),
+ // translators: Publish box date format, see http://php.net/date
+ date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ),
+ esc_url( get_permalink( $post->ID ) ),
+ $singular,
+ strtolower( $singular )
+ ),
+ 10 => sprintf(
+ __( '%1$s draft updated. Preview %2$s', 'wpmvcb' ),
+ $singular,
+ strtolower( $singular ),
+ esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) )
+ )
+ );
+
+ return $messages;
+ }
+
+ /**
+ * Register necessary actions, filters, etc. when loading the class
+ */
+ public static function on_load() {
+
+ add_action( 'init', array( __CLASS__, '_init' ) );
+ add_filter( 'post_updated_messages', array( __CLASS__, 'post_updated_messages' ) );
+
+ }
+
+ /**
+ * Verify it is okay to save the post
+ *
+ * @param array $args
+ * @return bool
+ * @since 0.3.4
+ */
+ public static function okay_to_save( $post_id, $args = array() ) {
+
+ $okay = true;
+ $args = wp_parse_args( $args, array(
+ 'post_type' => 'post',
+ ) );
+
+ //do not respond to inline-save (aka Quick Edit)
+ $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING );
+ if( 'inline-save' == $action ) {
+ $okay = false;
+ }
+
+ if ( ! current_user_can( 'edit_posts' ) ) {
+ $okay = false;
+ }
+
+ if ( ! ( get_post_type( $post_id ) == $args['post_type'] ) ) {
+ $okay = false;
+ }
+
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+ $okay = false;
+ }
+
+ return $okay;
+
+ }
+
+ /**
+ * @hook init
+ */
+ public static function _init() {
+
+ $post_type_args = array_merge( self::$_post_type_args, array(
+ 'labels' => self::init_labels(),
+ ) );
+
+ register_post_type( static::POST_TYPE, $post_type_args );
+
+ }
+
+ /**
+ * Initialize the CPT labels
+ *
+ * @return string[] The post type labels
+ * @access protected
+ * @since WPMVCBase 0.1
+ */
+ protected static function init_labels() {
+
+ $plural = self::$_plural;
+ $singular = self::$_singular;
+
+ return array(
+ 'name' => $plural,
+ 'singular_name' => $singular,
+ 'menu_name' => $plural,
+ 'parent_item_colon' => sprintf( __( 'Parent %s:', 'wpmvcb' ), $singular ),
+ 'all_items' => sprintf( __( 'All %s', 'wpmvcb' ), $plural ),
+ 'view_item' => sprintf( __( 'View %s', 'wpmvcb' ), $singular ),
+ 'add_new_item' => sprintf( __( 'Add New %s', 'wpmvcb' ), $singular ),
+ 'add_new' => sprintf( __( 'New %s', 'wpmvcb' ), $singular ),
+ 'edit_item' => sprintf( __( 'Edit %s', 'wpmvcb' ), $singular ),
+ 'update_item' => sprintf( __( 'Update %s', 'wpmvcb' ), $singular ),
+ 'search_items' => sprintf( __( 'Search %s', 'wpmvcb' ), $plural ),
+ 'not_found' => sprintf( __( 'No %s found', 'wpmvcb' ), strtolower( $plural ) ),
+ 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'wpmvcb' ), strtolower( $plural ) ),
+ );
+
+ }
+}
diff --git a/controllers/class-taxonomy-base.php b/controllers/class-taxonomy-base.php
index 65bde94..6b2b785 100644
--- a/controllers/class-taxonomy-base.php
+++ b/controllers/class-taxonomy-base.php
@@ -1,59 +1,59 @@
$object_types,
- 'args' => $args,
- );
+ self::$_taxonomy_args = $args;
}
@@ -62,9 +62,7 @@ public static function register_taxonomy_args( $slug, $object_types, $args ) {
*/
public static function init() {
- foreach( self::$taxonomy_args as $slug => $taxonomy ) {
- register_taxonomy( $slug, $taxonomy['object_types'], $taxonomy['args'] );
- }
+ register_taxonomy( static::TAXONOMY, static::object_types(), static::taxonomy_args() );
}
@@ -104,5 +102,3 @@ public static function on_load() {
}
}
-
-WPMVCB_Taxonomy_Base::on_load();
diff --git a/includes/class-base.php b/includes/class-base.php
new file mode 100644
index 0000000..f1b5016
--- /dev/null
+++ b/includes/class-base.php
@@ -0,0 +1,103 @@
+ $value ) {
+ do {
+ if ( property_exists( $this, $property = "_{$key}" ) ) {
+ $this->{$property} = $value;
+ break;
+ }
+
+ $this->_args[ $key ] = $value;
+ } while ( false );
+
+ }
+
+ }
+
+ /**
+ * @param string $method
+ * @param array $args
+ *
+ * @return null|mixed
+ */
+ public function __call( $method, $args ) {
+
+ do {
+ if ( property_exists( $this, $property = "_{$method}" ) ) {
+ $value = $this->{$property};
+ break;
+ }
+
+ if ( isset( $this->_args[ $method ] ) ) {
+ $value = $this->_args[ $method ];
+ break;
+ }
+
+ $value = null;
+ } while ( false );
+
+ return $value;
+
+ }
+
+ /**
+ * @param string $method
+ * @param array $args
+ *
+ * @return null|mixed
+ */
+ public static function __callStatic( $method, $args ) {
+
+ do {
+ if ( property_exists( static::class, $property = "_{$method}" ) ) {
+ $value = static::${$property};
+ break;
+ }
+
+ $value = null;
+ } while ( false );
+
+ return $value;
+ }
+
+ /**
+ * @param string $method_name
+ * @param string $replacement
+ */
+ protected function deprecated( $method_name, $replacement ) {
+
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
+ $message = sprintf(
+ __( 'The method %1$s is deprecated. Please use %2$s instead.', 'wpmvcb' ),
+ $method_name,
+ $replacement
+ );
+
+ trigger_error( $message, E_USER_WARNING );
+ }
+
+ }
+
+}
diff --git a/models/class-metabox-model-base.php b/models/class-metabox-model-base.php
deleted file mode 100644
index e1bc98e..0000000
--- a/models/class-metabox-model-base.php
+++ /dev/null
@@ -1,382 +0,0 @@
-callback_args.
- *
- * @var string
- * @access private
- * @since WPMVCBase 0.1
- */
- private $callback;
-
- /**
- * the post types to which this metabox applies
- *
- * The type of Write screen on which to show the edit screen section ('post', 'page', 'link', 'attachment' or 'custom_post_type' where custom_post_type is the custom post type slug)
- *
- * @var array
- * @access private
- * @since WPMVCBase 0.1
- */
- private $post_types = array( 'post' );
-
- /**
- * the metabox context
- *
- * The part of the page where the edit screen section should be shown.
- * Valid values are 'normal', 'advanced', or 'side'.
- *
- * @var string
- * @access private
- * @since WPMVCBase 0.1
- */
- private $context = 'normal';
-
- /**
- * the metabox priority
- *
- * The priority within the context where the boxes should be shown.
- * Valid values are 'high', 'core', 'default', or 'low'.
- *
- * @var string
- * @access private
- * @since WPMVCBase 0.1
- */
- private $priority = 'default';
-
- /**
- * the metabox callback arguments
- *
- * Arguments to pass into your callback function. The callback will receive the $post object and
- * whatever parameters are passed through this variable.
- *
- * Example:
- *
- * Setting the callback args:
- *
- * $sample_metabox->callback_args = array( 'foo' => 'this', "bar => 'that' );
- *
- *
- * The metabox callback:
- *
- * // $post is an object containing the current post (as a $post object)
- * // $metabox is an array with metabox id, title, callback, and args elements.
- * // The args element is an array containing your passed $callback_args variables.
- *
- * function my_metabox_callback ( $post, $metabox ) {
- * echo 'Last Modified: '.$post->post_modified; // outputs last time the post was modified
- * echo $metabox['args']['foo']; // outputs 'this'
- * echo $metabox['args']['bar']; // outputs 'that'
- * echo get_post_meta($post->ID,'my_custom_field',true); // outputs value of custom field
- * }
- *
- *
- * @var array
- * @access private
- * @since WPMVCBase 0.1
- */
- private $callback_args = array();
-
- /**
- * The class constructor.
- *
- * Example:
- *
- * $sample_metabox = new Base_Model_Metabox( array(
- * 'id' => 'sample_metabox',
- * 'title' => __( 'Sample Metabox', 'mytextdomain' ),
- * 'callback' => 'my_callback'
- * 'post_type' => array( 'post', 'page', 'my-custom-cpt' ),
- * 'context' => 'normal',
- * 'priority' => 'default'
- * 'callback_args' => array( 'foo' => 'this', 'bar' => 'that' )
- * );
- *
- *
- * @param array $args
- * @access public
- * @since WPMVCBase 0.1
- */
- public function __construct( $args = array() )
- {
- $args = wp_parse_args( $args, array(
- 'id' => 'sample-metabox',
- 'title' => __( 'Sample Metabox', 'wpmvcb' ),
- 'callback' => array( $this, 'default_callback' ),
- 'post_types' => array( 'post' ),
- 'context' => 'normal',
- 'priority' => 'default',
- 'callback_args' => array(),
- ) );
-
- $this->id = $args['id'];
- $this->title = $args['title'];
- $this->callback = $args['callback'];
- $this->post_types = $args['post_types'];
- $this->context = $args['context'];
- $this->priority = $args['priority'];
- $this->callback_args = $args['callback_args'];
-
- //check for valid values
- if ( ! in_array( $this->context, array( 'normal', 'advanced', 'side' ) ) ) {
- $this->context = 'normal';
- }
-
- if ( ! in_array( $this->priority, array( 'high', 'core', 'default', 'low' ) ) ) {
- $this->priority = 'default';
- }
- }
-
- /**
- * remove the metabox
- *
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function remove()
- {
- foreach( $this->post_types as $post_type ) {
- remove_meta_box( $this->id, $post_type, $this->context );
- }
- }
-
- /**
- * set the id
- *
- * @param string $id
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function set_id( $id )
- {
- $this->id = $id;
- }
-
- /**
- * set the title
- *
- * @param string $title
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function set_title( $title )
- {
- $this->title = $title;
- }
-
- /**
- * set the callback function
- *
- * @param string $callback
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function set_callback( $callback )
- {
- $this->callback = $callback;
- }
-
- /**
- * set the post types
- *
- * @param array $post_types
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function set_post_type( array $post_types )
- {
- $this->post_types = $post_types;
- }
-
- /**
- * set the context
- *
- * @param string $context
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function set_context( $context )
- {
- $this->context = $context;
- }
-
- /**
- * set the priority
- *
- * @param string $priority
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function set_priority( $priority )
- {
- $this->priority = $priority;
- }
-
- /**
- * set the callback_args
- *
- * @param array $callback_args
- * @return void
- * @access public
- * @since WPMVCBase 0.1
- */
- public function set_callback_args( $callback_args )
- {
- $this->callback_args = $callback_args;
- }
-
- /**
- * get the metabox id
- *
- * @return string $id
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_id()
- {
- return $this->id;
- }
-
- /**
- * get the metabox title
- *
- * @return string $id
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_title()
- {
- return $this->title;
- }
-
- /**
- * get the metabox callback
- *
- * @return string $callback
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_callback()
- {
- return $this->callback;
- }
-
- /**
- * get the metabox post_type
- *
- * @return string $post_type
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_post_types()
- {
- return $this->post_types;
- }
-
- /**
- * get the metabox context
- *
- * @return string $context
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_context()
- {
- return $this->context;
- }
-
- /**
- * get the metabox priority
- *
- * @return string $priority
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_priority()
- {
- return $this->priority;
- }
-
- /**
- * get the metabox callback_args
- *
- * @param WP_Post $post
- * @return array $callback_args
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_callback_args( $post )
- {
- return apply_filters( $this->id, $this->callback_args, $post );
- }
-
- /**
- * The default metabox callback
- */
- public function default_callback()
- {
- printf(
- __( 'This is the default callback for the %s metabox. Please implement a callback function!', 'wpmvcb' ),
- $this->id
- );
- }
- }
-}
diff --git a/models/class-model-base.php b/models/class-model-base.php
index 4392fdc..009bfd3 100644
--- a/models/class-model-base.php
+++ b/models/class-model-base.php
@@ -1,360 +1,334 @@
array(),
- 'admin_css' => array(),
- 'scripts' => array(),
- 'admin_scripts' => array(),
- 'metaboxes' => array(),
- 'help_tabs' => array(),
- 'shortcodes' => array(),
- 'admin_notices' => array(),
- ) );
-
- $this->args = $args;
- $this->css = $args['css'];
- $this->admin_css = $args['admin_css'];
- $this->scripts = $args['scripts'];
- $this->admin_scripts = $args['admin_scripts'];
- $this->metaboxes = $args['metaboxes'];
- $this->help_tabs = $args['help_tabs'];
- $this->admin_notices = $args['admin_notices'];
+ protected $scripts = array();
- }
+ /**
+ * The model admin javascript files
+ *
+ * An array containing a collection of javascript objects used by the model on admin pages.
+ *
+ * @var array
+ * @access protected
+ * @since WPMVCBase 0.1
+ */
+ protected $admin_scripts = array();
- /**
- * Get the frontend CSS.
- *
- * @return array
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_css() {
+ /**
+ * Metaboxes required by this model.
+ *
+ * @var array Contains an array of WP_Base_Metabox objects
+ * @access protected
+ * @since WPMVCBase 0.1
+ * @see WPMVCBase\Models\Base_Model_Metabox
+ */
+ protected $metaboxes = array();
- return $this->css;
+ /**
+ * The model's help tabs.
+ *
+ * This is a collection of Base_Model_Help_Tab objects.
+ *
+ * @var array
+ * @access protected
+ * @since WPMVCBase 0.2
+ * @see Base_Model_Help_Tabs
+ */
+ protected $help_tabs = array();
- }
+ /**
+ * The model's shortcodes.
+ *
+ * @var array
+ * @access protected
+ * @since WPMVCBase 0.2
+ */
+ protected $shortcodes = array();
- /**
- * Get the admin CSS.
- *
- * @return array
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_admin_css() {
+ /**
+ * The model's admin notices.
+ *
+ * This is a collection of Base_Model_Admin_Notice objects.
+ *
+ * @var array
+ * @access protected
+ * @since WPMVCBase 0.2
+ * @see Base_Model_Admin_Notice
+ */
+ protected $admin_notices = array();
- return $this->admin_css;
+ /**
+ * The class constructor.
+ *
+ * @param string|array $args
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function __construct( $args ) {
+ $args = wp_parse_args( $args, array(
+ 'css' => array(),
+ 'admin_css' => array(),
+ 'scripts' => array(),
+ 'admin_scripts' => array(),
+ 'metaboxes' => array(),
+ 'help_tabs' => array(),
+ 'shortcodes' => array(),
+ 'admin_notices' => array(),
+ ) );
+
+ parent::__construct( $args );
+ }
- }
+ /**
+ * Get the frontend CSS.
+ *
+ * @return array
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function get_css() {
- /**
- * Get the front end javascripts.
- *
- * @return array
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_scripts() {
-
- return $this->scripts;
-
- }
+ return $this->css;
- /**
- * Get the admin javascripts.
- *
- * @return array
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_admin_scripts() {
+ }
- return $this->admin_scripts;
+ /**
+ * Get the admin CSS.
+ *
+ * @return array
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function get_admin_css() {
- }
+ return $this->admin_css;
- /**
- * Get the model's metaboxes.
- *
- * @return array
- * @access public
- * @since WPMVCBase 0.1
- * @see WP_Metabox
- */
- public function get_metaboxes() {
+ }
- return $this->metaboxes;
+ /**
+ * Get the front end javascripts.
+ *
+ * @return array
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function get_scripts() {
- }
+ return $this->scripts;
- /**
- * Get the model help screen tabs.
- *
- * @return Base_Model_Help_Tab[]
- * @access public
- * @since WPMVCBase 0.1
- * @see Base_Model_Help_Tab
- */
- public function get_help_tabs() {
+ }
- return $this->help_tabs;
+ /**
+ * Get the admin javascripts.
+ *
+ * @return array
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function get_admin_scripts() {
- }
-
- /**
- * Get the model's shortcodes.
- *
- * @return array
- * @access public
- * @since WPMVCBase 0.1
- */
- public function get_shortcodes() {
-
- return $this->shortcodes;
+ return $this->admin_scripts;
- }
+ }
- /**
- * Add a help tab object.
- *
- * @param string $handle The help tab handle.
- * @param object $help_tab The Base_Model_Help_Tab object.
- * @return bool|WP_Error TRUE on success, WP_Error on failure.
- * @access public
- * @since WPMVCBase 0.2
- * @see Base_Model_Help_Tab
- */
- public function add_help_tab( $handle, $help_tab ) {
-
- if ( $help_tab instanceOf Base_Model_Help_Tab ) {
- $this->help_tabs = array_merge( $this->help_tabs, array( $handle => $help_tab ) );
- return true;
- }
-
- //A valid help tab object is not included.
- return new WP_Error(
- 'invalid object type',
- sprintf( __( '%s::%s expects a Base_Model_Help_Tab object as the second parameter', 'wpmvcb' ), __CLASS__, __FUNCTION__ ),
- $help_tab
- );
+ /**
+ * Get the model's metaboxes.
+ *
+ * @return array
+ * @access public
+ * @since WPMVCBase 0.1
+ * @see WP_Metabox
+ */
+ public function get_metaboxes() {
+
+ return $this->metaboxes;
+
+ }
+
+ /**
+ * Get the model help screen tabs.
+ *
+ * @return Base_Model_Help_Tab[]
+ * @access public
+ * @since WPMVCBase 0.1
+ * @see Base_Model_Help_Tab
+ */
+ public function get_help_tabs() {
+
+ return $this->help_tabs;
+
+ }
+
+ /**
+ * Get the model's shortcodes.
+ *
+ * @return array
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function get_shortcodes() {
+
+ return $this->shortcodes;
+
+ }
+
+ /**
+ * Add a help tab object.
+ *
+ * @param string $handle The help tab handle.
+ * @param object $help_tab The Base_Model_Help_Tab object.
+ * @return bool|WP_Error TRUE on success, WP_Error on failure.
+ * @access public
+ * @since WPMVCBase 0.2
+ * @see Base_Model_Help_Tab
+ */
+ public function add_help_tab( $handle, $help_tab ) {
+ if ( $help_tab instanceOf Base_Model_Help_Tab ) {
+ $this->help_tabs = array_merge( $this->help_tabs, array( $handle => $help_tab ) );
+ return true;
}
-
- /**
- * Add a shortcode object.
- *
- * @param string $shortcode The shortcode name.
- * @param string $callback The shortcode callback handler.
- * @return void|WP_Error
- * @access public
- * @since WPMVCBase 0.1
- */
- public function add_shortcode( $shortcode, $callback ) {
-
- if ( is_callable( $callback ) ) {
- $this->shortcodes = array_merge( $this->shortcodes, array( $shortcode => $callback ) );
- return true;
- }
-
- return new WP_Error(
- 'not callable',
- sprintf( __( '%s::%s expects a valid callback.', 'wpmvcb' ), __CLASS__, __FUNCTION__ ),
- $callback
- );
+ //A valid help tab object is not included.
+ return new WP_Error(
+ 'invalid object type',
+ sprintf( __( '%s::%s expects a Base_Model_Help_Tab object as the second parameter', 'wpmvcb' ), __CLASS__, __FUNCTION__ ),
+ $help_tab
+ );
+
+ }
+
+ /**
+ * Add a shortcode object.
+ *
+ * @param string $shortcode The shortcode name.
+ * @param string $callback The shortcode callback handler.
+ * @return void|WP_Error
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function add_shortcode( $shortcode, $callback ) {
+
+ if ( is_callable( $callback ) ) {
+ $this->shortcodes = array_merge( $this->shortcodes, array( $shortcode => $callback ) );
+ return true;
}
-
- /**
- * WP save_post action authenticator.
- *
- * This method verifies an autosave is not in progress, the current user can edit the post being submitted,
- * and that a valid nonce is present.
- *
- * @param string $post_id The WP post id.
- * @param string $post_type The post type.
- * @param object $post_data The POSTed data.
- * @param string $nonce_name The name of the nonce.
- * @param string $nonce_action The nonce action.
- * @internal
- * @access public
- * @since WPMVCBase 0.1
- */
- public function authenticate_post( $post_id, $post_type, $post_data, $nonce_name, $nonce_action ) {
-
- // verify if this is an auto save routine.
- // If it is our form has not been submitted, so we don't want to do anything
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return;
- }
- // We need to check if the current user is authorised to do this action.
- if ( 'page' == $post_type ) {
- if ( ! current_user_can( 'edit_page', $post_id ) ) {
- return;
- }
- }
-
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- return;
- }
+ return new WP_Error(
+ 'not callable',
+ sprintf( __( '%s::%s expects a valid callback.', 'wpmvcb' ), __CLASS__, __FUNCTION__ ),
+ $callback
+ );
+
+ }
+
+ /**
+ * WP save_post action authenticator.
+ *
+ * This method verifies an autosave is not in progress, the current user can edit the post being submitted,
+ * and that a valid nonce is present.
+ *
+ * @param string $post_id The WP post id.
+ * @param string $post_type The post type.
+ * @param object $post_data The POSTed data.
+ * @param string $nonce_name The name of the nonce.
+ * @param string $nonce_action The nonce action.
+ * @internal
+ * @access public
+ * @since WPMVCBase 0.1
+ */
+ public function authenticate_post( $post_id, $post_type, $post_data, $nonce_name, $nonce_action ) {
+
+ // verify if this is an auto save routine.
+ // If it is our form has not been submitted, so we don't want to do anything
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+ return;
+ }
- // Third we need to check if the user intended to change this value.
- if ( ! isset( $post_data[ $nonce_name ] ) || ! wp_verify_nonce( $post_data[ $nonce_name ], $nonce_action ) ) {
+ // We need to check if the current user is authorised to do this action.
+ if ( 'page' == $post_type ) {
+ if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
+ }
- return true;
-
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
+ return;
}
-
- /**
- * Get the admin notices attached to this model.
- *
- * @return array|bool
- * @access public
- * @since WPMVCBase 0.2
- */
- public function get_admin_notices() {
-
- return $this->admin_notices;
+ // Third we need to check if the user intended to change this value.
+ if ( ! isset( $post_data[ $nonce_name ] ) || ! wp_verify_nonce( $post_data[ $nonce_name ], $nonce_action ) ) {
+ return;
}
+ return true;
+
+ }
+
+ /**
+ * Get the admin notices attached to this model.
+ *
+ * @return array|bool
+ * @access public
+ * @since WPMVCBase 0.2
+ */
+ public function get_admin_notices() {
+
+ return $this->admin_notices;
+
}
}
diff --git a/models/class-post-model-base.php b/models/class-post-model-base.php
index a9526b7..8b94c48 100644
--- a/models/class-post-model-base.php
+++ b/models/class-post-model-base.php
@@ -1,165 +1,184 @@
post = $post;
- }
+ /**
+ * @var \WP_Post|int $post
+ * @var array $args
+ */
+ public function __construct( $post, $args = array() ) {
- parent::__construct( $args );
+ if ( is_int( $post ) ) {
+ $post = get_post( $post );
+ }
+ if ( is_a( $post, 'WP_Post' ) ) {
+ $args['post'] = $post;
}
- /**
- * @return bool
- */
- public function has_post() {
+ parent::__construct( $args );
- $has_post = false;
+ }
- if( isset( $this->post ) && is_a( $this->post, 'WP_Post' ) ) {
- $has_post = true;
- }
+ /**
+ * @return bool
+ */
+ public function has_post() {
- return $has_post;
+ $has_post = false;
+ if ( isset( $this->_post ) ) {
+ $has_post = true;
}
- /**
- * @return WP_Post
- */
- public function get_post() {
+ return $has_post;
- return $this->post;
+ }
- }
+ /**
+ * @return \WP_Post
+ * @deprecated
+ */
+ public function get_post() {
- /**
- * @return bool
- */
- public function has_image() {
+ $this->deprecated( __METHOD__, 'post()' );
+ return $this->_post;
- $value = false;
+ }
- if ( $this->has_post() ) {
- $value = has_post_thumbnail( $this->post->ID );
- }
+ /**
+ * @return bool
+ */
+ public function has_image() {
+
+ $value = false;
- return $value;
+ if ( $this->has_post() ) {
+ $value = has_post_thumbnail( $this->_post->ID );
}
- /**
- * @param $size
- * @param array $attr
- * @return mixed|null|void
- */
- public function get_image( $size = 'full', $attr = array() ) {
+ return $value;
+ }
- $value = null;
+ /**
+ * @param string $size
+ * @param array $attr
+ * @return mixed|null|void
+ */
+ public function get_image( $size = 'full', $attr = array() ) {
- if( $this->has_image() ) {
- $value = get_the_post_thumbnail( $this->post->ID, $size, $attr );
- }
+ $value = null;
- return $value;
+ if( $this->has_image() ) {
+ $value = get_the_post_thumbnail( $this->_post->ID, $size, $attr );
}
- /**
- * @return int
- */
- public function get_image_id() {
-
- $value = 0;
+ return $value;
+ }
- if ( $this->has_post() ) {
- if ( $this->has_image() ) {
- $value = get_post_thumbnail_id( $this->post->ID );
- }
- }
+ /**
+ * @return int
+ */
+ public function get_image_id() {
- return $value;
+ $value = 0;
+ if ( $this->has_post() ) {
+ if ( $this->has_image() ) {
+ $value = get_post_thumbnail_id( $this->_post->ID );
+ }
}
- /**
- * @return int
- */
- public function get_id() {
+ return $value;
- $id = 0;
+ }
- if ( isset( $this->post ) && is_a( $this->post, 'WP_Post' ) ) {
- $id = $this->post->ID;
- }
+ public function get_permalink() {
- return $id;
+ $permalink = '';
+ if ( $this->has_post() ) {
+ $permalink = get_permalink( $this->_post->ID );
}
- /**
- * @return string
- */
- public function get_title() {
+ return $permalink;
+
+ }
+
+ /**
+ * @param string $method
+ * @param array $args
+ *
+ * @return null
+ */
+ public function __call( $method, $args ) {
- $title = '';
+ do {
- if ( isset( $this->post ) && is_a( $this->post, 'WP_Post' ) ) {
- $title = get_the_title( $this->post->ID );
+ if ( $this->has_post() && $this->_is_post_property( $method ) ) {
+ $value = $this->_post->{$method};
+ break;
}
- return $title;
+ $value = parent::__call( $method, $args );
+ } while ( false );
- }
+ return $value;
+ }
+
+ /**
+ * @param string $property
+ *
+ * @return bool
+ */
+ protected function _is_post_property( $property ) {
- public function get_permalink() {
+ do {
+ if ( property_exists( \WP_Post::class, $property ) ) {
+ $is_pp = true;
+ break;
+ }
- $permalink = '';
+ if ( in_array( $property, array( 'ancestors', 'post_category', 'tags_input', 'page_template' ) ) ) {
+ $is_pp = true;
+ break;
+ }
- if ( isset( $this->post ) && is_a( $this->post, 'WP_Post' ) ) {
- $permalink = get_permalink( $this->post->ID );
+ if ( metadata_exists( 'post', $this->_post->ID, $property ) ) {
+ $is_pp = true;
+ break;
}
- return $permalink;
+ $is_pp = false;
+ } while ( false );
- }
+ return $is_pp;
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
deleted file mode 100644
index a4df82b..0000000
--- a/phpunit.xml.dist
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
-
- ./tests/constraint
-
-
- ./tests/unit-tests/
-
-
- ./tests/integration-tests/
-
-
-
-
- ./
-
- ./build/
- ./tests/
- ./tests/unit-tests/
- ./tests/includes/
- ./wp-tests/
- ./vendor/
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 4a60b83..9cdb46a 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -20,17 +20,11 @@
require_once( WPMVCB_TEST_DIR . '/includes/vfs/vfsStreamWrapper.php' );
require_once 'framework/class-factory.php';
-require_once 'framework/class-factory-for-mock.php';
-require_once 'framework/class-factory-for-mock-thing.php';
-require_once 'framework/class-factory-for-mock-metabox.php';
-require_once 'framework/class-factory-for-mock-metabox-model.php';
-require_once 'framework/class-constraint-metabox-exists.php';
-require_once 'framework/class-constraint-script-registered.php';
require_once 'framework/testcase.php';
require_once WPMVCB_SRC_DIR . '/wpmvcb.php';
-$wpmvcb = new WPMVCB;
+$wpmvcb = new \WPMVCB\WPMVCB();
echo 'Welcome to the WP MVC Base Test Suite' . PHP_EOL;
echo 'Version 1.0' . PHP_EOL;
-echo 'Author: Daryl Lozupone ' . PHP_EOL;
+echo 'Author: ClubDeuce ' . PHP_EOL;
diff --git a/tests/constraint/test-constraint-metabox-exists.php b/tests/constraint/test-constraint-metabox-exists.php
deleted file mode 100644
index 70cbcba..0000000
--- a/tests/constraint/test-constraint-metabox-exists.php
+++ /dev/null
@@ -1,90 +0,0 @@
-_constraint = new \WPMVCB\Testing\PHPUnit_Framework_Constraint_MetaboxExists();
- }
-
- public function testNoMetabox()
- {
- $args = array();
- $this->assertFalse( $this->_constraint->matches( $args ) );
- }
-
- public function testWrongId()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
- add_meta_box( 'bar', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
-
- $this->assertFalse( $this->_constraint->matches( $args ) );
- remove_meta_box( 'bar', 'post', 'normal' );
- }
-
- public function testWrongTitle()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
- add_meta_box( 'foocpt', 'Bar Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
-
- $this->assertFalse( $this->_constraint->matches( $args ) );
- remove_meta_box( 'foocpt', 'post', 'normal' );
- }
-
- public function testWrongCallback()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
- add_meta_box( 'foocpt', 'Foo Meta', 'phpinfo', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
-
- $this->assertFalse( $this->_constraint->matches( $args ) );
- remove_meta_box( 'foocpt', 'post', 'normal' );
- }
-
- public function testWrongPostType()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'page', 'normal', 'default', array( 'foo' => 'bar' ) );
- add_meta_box( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
-
- $this->assertFalse( $this->_constraint->matches( $args ) );
- remove_meta_box( 'foocpt', 'post', 'normal' );
- }
-
- public function testWrongContext()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'post', 'side', 'default', array( 'foo' => 'bar' ) );
- add_meta_box( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
-
- $this->assertFalse( $this->_constraint->matches( $args ) );
- remove_meta_box( 'foocpt', 'post', 'normal' );
- }
-
- public function testWrongPriority()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'high', array( 'foo' => 'bar' ) );
- add_meta_box( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
-
- $this->assertFalse( $this->_constraint->matches( $args ) );
- remove_meta_box( 'foocpt', 'post', 'normal' );
- }
-
- public function testWrongCallbackArgs()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
- add_meta_box( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'bar' => 'baz' ) );
-
- $this->assertFalse( $this->_constraint->matches( $args ) );
- remove_meta_box( 'foocpt', 'post', 'normal' );
- }
-
- public function testMetaboxExists()
- {
- $args = array( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
- add_meta_box( 'foocpt', 'Foo Meta', 'time', 'post', 'normal', 'default', array( 'foo' => 'bar' ) );
-
- $this->assertTrue( $this->_constraint->matches( $args ) );
- remove_meta_box( 'foocpt', 'post', 'normal' );
- }
-}
diff --git a/tests/constraint/test-constraint-script-registered.php b/tests/constraint/test-constraint-script-registered.php
deleted file mode 100644
index 8ee0c74..0000000
--- a/tests/constraint/test-constraint-script-registered.php
+++ /dev/null
@@ -1,68 +0,0 @@
-_constraint = new \WPMVCB\Testing\PHPUnit_Framework_Constraint_ScriptRegistered();
-
- //register our test script
- wp_register_script( 'fooscript', 'http://example.com/fooscript.js', array( 'jquery' ), true, true );
- }
-
- public function tearDown()
- {
- wp_deregister_script( 'fooscript' );
- }
-
- public function testNoScript()
- {
- $script = array();
- $this->assertFalse( $this->_constraint->matches( $script ) );
- }
-
- public function testWrongHandle()
- {
- $script = array( 'baz', 'http://example.com/fooscript.js', array( 'jquery' ), true, true );
-
- $this->assertFalse( $this->_constraint->matches( $script ) );
- }
-
- public function testWrongSrc()
- {
- $script = array( 'fooscript', 'baz', array( 'jquery' ), true, true );
-
- $this->assertFalse( $this->_constraint->matches( $script ) );
- }
-
- public function testWrongDeps()
- {
- $script = array( 'fooscript', 'http://example.com/fooscript.js', array( 'baz' ), true, true );
-
- $this->assertFalse( $this->_constraint->matches( $script ) );
- }
-
- public function testWrongVer()
- {
- $script = array( 'fooscript', 'http://example.com/fooscript.js', array( 'jquery' ), false, true );
-
- $this->assertFalse( $this->_constraint->matches( $script ) );
- }
-
- public function testWrongInFooter()
- {
- $script = array( 'fooscript', 'http://example.com/fooscript.js', array( 'jquery' ), true, false );
-
- $this->assertFalse( $this->_constraint->matches( $script ) );
- }
-
- public function testScriptExists()
- {
- $script = array( 'fooscript', 'http://example.com/fooscript.js', array( 'jquery' ), true, true );
-
- $this->assertTrue( $this->_constraint->matches( $script ) );
- }
-}
diff --git a/tests/framework/class-constraint-metabox-exists.php b/tests/framework/class-constraint-metabox-exists.php
deleted file mode 100644
index f06ca7b..0000000
--- a/tests/framework/class-constraint-metabox-exists.php
+++ /dev/null
@@ -1,75 +0,0 @@
-
- *
- */
-
-class PHPUnit_Framework_Constraint_MetaboxExists extends \PHPUnit_Framework_Constraint
-{
- public function matches($args)
- {
- global $wp_meta_boxes;
-
- if( ! empty( $args ) ) {
- $metabox_id = $args[0];
- $title = $args[1];
- $callback = $args[2];
- $post_type = $args[3];
- $context = $args[4];
- $priority = $args[5];
- $callback_args = $args[6];
- }
-
- if ( ! isset( $wp_meta_boxes ) ) {
- return false;
- }
-
- if ( ! array_key_exists( $post_type, $wp_meta_boxes ) ) {
- return false;
- }
-
- if ( ! array_key_exists( $context, $wp_meta_boxes[ $post_type ] ) ) {
- return false;
- }
-
- if ( ! array_key_exists( $priority, $wp_meta_boxes[ $post_type ][ $context ] ) ) {
- return false;
- }
-
- if ( ! array_key_exists( $metabox_id, $wp_meta_boxes[ $post_type ][ $context ][ $priority ] ) ) {
- return false;
- }
-
- if ( ! in_array( $metabox_id, $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $metabox_id ] ) ) {
- return false;
- }
-
- if ( ! in_array( $title, $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $metabox_id ] ) ) {
- return false;
- }
-
- if ( ! in_array( $callback, $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $metabox_id ] ) ) {
- return false;
- }
-
- if ( ! in_array( $callback_args, $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $metabox_id ] ) ) {
- return false;
- }
-
- return true;
- }
-
- public function toString()
- {
- return 'metabox exists';
- }
-}
diff --git a/tests/framework/class-constraint-script-registered.php b/tests/framework/class-constraint-script-registered.php
deleted file mode 100644
index 16454d8..0000000
--- a/tests/framework/class-constraint-script-registered.php
+++ /dev/null
@@ -1,73 +0,0 @@
-
- *
- */
-
-class PHPUnit_Framework_Constraint_ScriptRegistered extends \PHPUnit_Framework_Constraint
-{
- /**
- * Evaluates the constraint for parameter $args. Returns TRUE if the
- * constraint is met, FALSE otherwise.
- *
- * @param array $script An array containing the elements to evaluate. This array MUST take the following form:
- *
- * array( handle, src, deps, ver, in_footer )
- *
- * @return bool
- */
- public function matches($script)
- {
- global $wp_scripts;
-
- if ( ! isset( $wp_scripts ) || empty( $script ) ) {
- return false;
- }
-
- if ( ! true === wp_script_is( $script[0], 'registered' ) ) {
- return false;
- }
-
- if ( $script[0] != $wp_scripts->registered[ $script[0] ]->handle ) {
- return false;
- }
-
- if ( $script[1] != $wp_scripts->registered[ $script[0] ]->src ) {
- return false;
- }
-
- if ( $script[2] != $wp_scripts->registered[ $script[0] ]->deps ) {
- return false;
- }
-
- if ( $script[3] != $wp_scripts->registered[ $script[0] ]->ver ) {
- return false;
- }
-
-
- if ( $script[4] != $wp_scripts->registered[ $script[0] ]->extra['group'] ) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Returns a string representation of the constraint.
- *
- * @return string
- */
- public function toString()
- {
- return 'script registered';
- }
-}
diff --git a/tests/framework/class-factory-for-mock-metabox-model.php b/tests/framework/class-factory-for-mock-metabox-model.php
deleted file mode 100644
index 883d360..0000000
--- a/tests/framework/class-factory-for-mock-metabox-model.php
+++ /dev/null
@@ -1,42 +0,0 @@
- 'mock-metabox-model',
- 'title' => 'Mock Metabox Title',
- 'post_types' => array( 'post' ),
- 'callback' => array( $this, 'callback' ),
- 'priority' => 'default',
- 'context' => 'normal',
- 'callback_args' => array( 'foo' => 'bar' ),
- ) );
-
- $mock = Mockery::mock( 'WPMVCB_Mock_Metabox_Model' );
- $mock->shouldReceive( 'get_id' )->andReturn( $args['id'] );
- $mock->shouldReceive( 'get_title')->andReturn( $args['title'] );
- $mock->shouldReceive( 'get_post_types' )->andReturn( $args['post_types'] );
- $mock->shouldReceive( 'get_callback' )->andReturn( $args['callback'] );
- $mock->shouldReceive( 'get_priority' )->andReturn( $args['priority'] );
- $mock->shouldReceive( 'get_context' )->andReturn( $args['context'] );
- $mock->shouldReceive( 'get_callback_args' )->andReturn( $args['callback_args'] );
-
- return $mock;
- }
-}
diff --git a/tests/framework/class-factory-for-mock-metabox.php b/tests/framework/class-factory-for-mock-metabox.php
deleted file mode 100644
index 747e142..0000000
--- a/tests/framework/class-factory-for-mock-metabox.php
+++ /dev/null
@@ -1,30 +0,0 @@
-factory = $factory;
- $this->model = new WPMVCB_Tests_Factory_For_Mock_Metabox_Model( $factory );
- //$this->view = new WPMVCB_Tests_Factory_For_Mock_Metabox_View( $factory );
- }
-
- public function create( array $args = array() )
- {
- $model = new WPMVCB_Tests_Factory_For_Mock_Metabox_Model( $this->factory );
- $args = wp_parse_args( $args, array(
- 'model' => $model->create(),
- 'view' => null,
- ) );
-
- $mock = Mockery::mock( 'WPMVCB_Mock_Metabox' );
- $mock->model = $args['model'];
- $mock->view = $args['view'];
-
- return $mock;
- }
-}
diff --git a/tests/framework/class-factory-for-mock-thing.php b/tests/framework/class-factory-for-mock-thing.php
deleted file mode 100644
index d784269..0000000
--- a/tests/framework/class-factory-for-mock-thing.php
+++ /dev/null
@@ -1,31 +0,0 @@
-factory = $factory;
- }
-
- /**
- * Create and return a mock object
- *
- * @param array $args
- * @return mixed
- * @abstract
- */
- public abstract function create( array $args = array() );
-}
diff --git a/tests/framework/class-factory-for-mock.php b/tests/framework/class-factory-for-mock.php
deleted file mode 100644
index 38a2539..0000000
--- a/tests/framework/class-factory-for-mock.php
+++ /dev/null
@@ -1,21 +0,0 @@
-factory = $factory;
- $this->metabox = new WPMVCB_Tests_Factory_For_Mock_Metabox( $factory );
- }
-}
diff --git a/tests/framework/class-factory.php b/tests/framework/class-factory.php
index 68de73b..fd087c8 100644
--- a/tests/framework/class-factory.php
+++ b/tests/framework/class-factory.php
@@ -1,8 +1,11 @@
mock = new WPMVCB_Tests_Factory_For_Mock( $this );
}
}
diff --git a/tests/framework/testcase.php b/tests/framework/testcase.php
index 2a17b7e..47010d1 100644
--- a/tests/framework/testcase.php
+++ b/tests/framework/testcase.php
@@ -1,90 +1,52 @@
factory = new Factory();
+ }
+
+ public function getReflectionPropertyValue( $class, $property )
+ {
+ $reflection = new \ReflectionProperty( $class, $property );
+ $reflection->setAccessible( true );
+ return $reflection->getValue( $class );
+ }
+
+ public function setReflectionPropertyValue( $class, $property, $value )
+ {
+ $reflection = new \ReflectionProperty( $class, $property );
+ $reflection->setAccessible( true );
+ return $reflection->setValue( $class, $value );
+ }
+
+ public function reflectionMethodInvoke( $class, $method )
{
- public function setUp()
- {
- parent::setUp();
- $this->factory = new WPMVCB_Tests_Factory();
- }
-
- public function getReflectionPropertyValue( $class, $property )
- {
- $reflection = new \ReflectionProperty( $class, $property );
- $reflection->setAccessible( true );
- return $reflection->getValue( $class );
- }
-
- public function setReflectionPropertyValue( $class, $property, $value )
- {
- $reflection = new \ReflectionProperty( $class, $property );
- $reflection->setAccessible( true );
- return $reflection->setValue( $class, $value );
- }
-
- public function reflectionMethodInvoke( $class, $method )
- {
- $reflection = new \ReflectionMethod( $class, $method );
- $reflection->setAccessible( true );
- $reflection->invoke( $class );
- }
-
- public function reflectionMethodInvokeArgs( $class, $method, $args )
- {
- $reflection = new \ReflectionMethod( $class, $method );
- $reflection->setAccessible( true );
- $reflection->invoke( $class, $args );
- }
+ $reflection = new \ReflectionClass($class);
+ $method = $reflection->getMethod($method);
+ $method->setAccessible( true );
+ return $method->invoke($class);
+ }
- /**
- * Assert a metabox is registered with WordPress and associated properties are correctly set.
- *
- * @param array $args Contains: metabox id, title, callback, post type, context, priority, callback args
- * @param string $message The error message displayed on failure.
- * @return bool
- * @since 0.3
- * @link http://codex.wordpress.org/Function_Reference/add_meta_box
- */
- public static function assertMetaboxExists( $args, $message = '' )
- {
- self::assertThat( $args, self::metaboxExists(), $message );
- }
-
- /**
- * Returns a PHPUnit_Framework_Constraint_MetaboxExists matcher object.
- *
- * @return object PHPUnit_Framework_Constraint_MetaboxExists
- * @since 0.3
- */
- public static function metaboxExists()
- {
- return new \WPMVCB\Testing\PHPUnit_Framework_Constraint_MetaboxExists();
- }
-
- /**
- * Assert a javascript is registered with WordPress and associated properties are correctly set.
- *
- * @param array $sacript Contains: handle, src, deps, ver, in_footer
- * @param string $message The error message displayed on failure.
- * @return bool
- * @since 0.3
- * @link http://codex.wordpress.org/Function_Reference/wp_register_script
- */
- public static function assertScriptRegistered( $script, $message = '' )
- {
- self::assertThat( $script, self::scriptRegistered(), $message );
- }
-
- /**
- * Returns a PHPUnit_Framework_Constraint_ScriptRegistered matcher object.
- *
- * @return object PHPUnit_Framework_Constraint_ScriptRegistered
- * @since 0.3
- */
- public static function scriptRegistered()
- {
- return new \WPMVCB\Testing\PHPUnit_Framework_Constraint_ScriptRegistered();
- }
+ /**
+ * @param string|object $class
+ * @param string $method
+ * @param array $args
+ *
+ * @return mixed
+ */
+ public function reflectionMethodInvokeArgs($class, $method, $args = array())
+ {
+ $reflection = new \ReflectionClass($class);
+ $method = $reflection->getMethod($method);
+ $method->setAccessible(true);
+ return $method->invokeArgs($class, $args);
}
}
diff --git a/tests/integration-tests/test-custom-post-type.php b/tests/integration-tests/test-custom-post-type.php
deleted file mode 100644
index 6810cd3..0000000
--- a/tests/integration-tests/test-custom-post-type.php
+++ /dev/null
@@ -1,127 +0,0 @@
-metaboxes = array(
- 'book_metabox' => new \WPMVCB_Metabox_Model_Base(
- 'book_metabox',
- __( 'Book Metabox', $txtdomain ),
- null,
- array( $this->slug ),
- 'normal',
- 'default',
- array(
- 'view' => $this->app_path . 'views/metabox-book-metabox.php',
- )
- )
- );
- }
-
- protected function init_help_tabs()
- {
- //implemented but does nothing
- }
-
- public function save_post()
- {
- //implemented, but does nothing
- }
- }
-
- /**
- * The WordPress integration test controller for Custom Post Types.
- *
- * @since WPMVCBase 0.1
- * @internal
- */
- class testCustomPostType extends WPMVCB_Test_Case
- {
- public function setUp()
- {
- parent::setUp();
-
- //create the cpt model
- $this->model = new testStubCptModel(
- 'book-cpt',
- 'Book',
- 'Books',
- '/home/foo/plugin.php',
- '/home/foo',
- '/home/foo/app',
- '/home/foo/base',
- 'http://example.com/foo',
- 'footxtdomain' );
-
- //create a new controller
- $this->controller = new \WPMVCB_Cpt_Base( $this->model );
- }
-
- public function tearDown()
- {
- unset( $this->model );
- unset( $this->controller );
- }
-
- /**
- * @covers Base_Controller_Cpt::add_model
- */
- public function testMethodAddModel()
- {
- $this->controller->add_model( $this->model );
- $this->assertFalse( false === has_action( 'save_post', array( &$this->model, 'save_post' ) ) );
- }
-
- /**
- * @covers Base_Model::get_metaboxes
- *
- * Currently, this test does not work. It needs to be refactored.
- */
- public function testMethodGetMetaboxes()
- {
- $this->markTestIncomplete();
-
- $expected = array(
- 'book_metabox' => new \WPMVCB_Metabox_Model_Base(
- 'book_metabox',
- 'Book Metabox',
- null,
- array( 'book-cpt' ),
- 'normal',
- 'default',
- array(
- 'view' => '/home/foo/app/views/metabox-book-metabox.php',
- )
- )
- );
-
- $this->assertEquals( $expected, $this->model->get_metaboxes( 23, 'footxtdomain' ) );
- }
-
- /**
- * @covers Base_Model::get_help_tabs
- */
- public function testMethodGetHelpTabs()
- {
- $this->model->get_help_tabs();
- $this->markTestIncomplete( 'Not yet implemented' );
- }
- }
-}
diff --git a/tests/integration-tests/testPostBase.php b/tests/integration-tests/testPostBase.php
new file mode 100644
index 0000000..22b44c9
--- /dev/null
+++ b/tests/integration-tests/testPostBase.php
@@ -0,0 +1,71 @@
+_post = $this->factory()->post->create_and_get();
+ $this->_item = new Post_Base( $this->_post );
+ }
+
+ /**
+ * @covers ::__construct
+ * @covers ::model
+ * @covers ::view
+ */
+ public function testPostBaseConstructor() {
+ $this->assertInstanceOf(Post_Model_Base::class, $this->_item->model());
+ $this->assertInstanceOf(Post_View_Base::class, $this->_item->view());
+ }
+
+ /**
+ * @covers ::__construct
+ * @covers \WPMVCB\Post_Model_Base::__construct
+ */
+ public function testConstructWithInt() {
+ $post = new Post_Base($this->_post->ID);
+
+ $this->assertEquals($this->_post, $post->model()->post());
+ }
+
+ /**
+ * @covers ::__call
+ */
+ public function testPostProperties() {
+ $post = $this->_post;
+ $item = $this->_item;
+
+ $this->assertEquals($post->ID, $item->ID());
+ $this->assertEquals($post->post_title, $item->post_title());
+ $this->assertEquals($post->post_content, $item->post_content());
+ $this->assertEquals($post->post_content_filtered, $item->post_content_filtered());
+ $this->assertEquals($post->post_category, $item->post_category());
+ $this->assertEquals($post->post_name, $item->post_name());
+ }
+
+}
\ No newline at end of file
diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist
new file mode 100644
index 0000000..472b7a8
--- /dev/null
+++ b/tests/phpunit.xml.dist
@@ -0,0 +1,33 @@
+
+
+
+ ./unit-tests/
+
+
+ ./integration-tests/
+
+
+
+
+ ../controllers
+ ../includes
+ ../models
+ ../views
+ ../wpmvcb.php
+
+
+
+
+
+
+
+
+
diff --git a/tests/unit-tests/test-metabox-base.php b/tests/unit-tests/test-metabox-base.php
deleted file mode 100644
index cd47cd2..0000000
--- a/tests/unit-tests/test-metabox-base.php
+++ /dev/null
@@ -1,94 +0,0 @@
-model = $this->factory->mock->metabox->model->create( array( 'post_types' => array( 'page' ) ) );
- $this->view = new \stdClass();
- $this->sut = new WPMVCB_Metabox( array(
- 'model' => $this->model,
- 'view' => $this->view,
- ) );
- }
-
- /**
- * @covers ::__construct
- */
- public function testConstructorSetsModel()
- {
- $this->assertEquals( $this->model, $this->getReflectionPropertyValue( $this->sut, 'model' ) );
- }
-
- /**
- * @covers ::__construct
- */
- public function testConstructorSetsView()
- {
- $this->assertEquals( $this->view, $this->getReflectionPropertyValue( $this->sut, 'view' ) );
- }
-
- /**
- * @covers ::__construct
- */
- public function testConstructorAddsActions()
- {
- $this->assertGreaterThan( 0, has_action( 'add_meta_boxes_page', array( $this->sut, 'add' ) ) );
- }
-
- /**
- * @covers ::add
- */
- public function testMethodAdd()
- {
- $this->markTestIncomplete();
-
- $post = $this->factory->post->create_and_get();
-
- $this->sut->add( $post );
-
- $this->assertMetaboxExists(
- array(
- $this->model->get_id(),
- $this->model->get_title(),
- $this->model->get_callback(),
- 'page',
- $this->model->get_priority(),
- $this->model->get_context(),
- $this->model->get_callback_args( $post )
- )
- );
- }
-}
diff --git a/tests/unit-tests/test-metabox-view-default.php b/tests/unit-tests/test-metabox-view-default.php
deleted file mode 100644
index 3b58f02..0000000
--- a/tests/unit-tests/test-metabox-view-default.php
+++ /dev/null
@@ -1,44 +0,0 @@
-sut = new WPMVCB_Metabox_Default_View();
- }
-
- /**
- * @covers ::render
- */
- public function testRender()
- {
- $post = $this->factory->post->create_and_get();
- $metabox = new \stdClass();
-
- ob_start();
- $this->sut->render( $post, $metabox );
- $result = ob_get_clean();
-
- $this->assertInternalType( 'string', $result );
- $this->assertNotEmpty( $result );
- }
-}
diff --git a/tests/unit-tests/testBase.php b/tests/unit-tests/testBase.php
new file mode 100644
index 0000000..41530b2
--- /dev/null
+++ b/tests/unit-tests/testBase.php
@@ -0,0 +1,43 @@
+_sut = $this->getMockBuilder(Base::class)
+ ->setConstructorArgs(array(array('foo' => 'bar')))
+ ->getMockForAbstractClass();
+
+ parent::setUp();
+ }
+
+ /**
+ * @covers ::__construct
+ * @covers ::__call
+ */
+ public function testCall() {
+ $this->assertEquals('bar', $this->_sut->foo());
+ }
+
+ /**
+ * @covers ::__call
+ */
+ public function testCallIsNull() {
+ $this->assertNull($this->_sut->bar());
+ }
+}
\ No newline at end of file
diff --git a/tests/unit-tests/testBaseModelAdminNotice.php b/tests/unit-tests/testBaseModelAdminNotice.php
deleted file mode 100644
index f54484d..0000000
--- a/tests/unit-tests/testBaseModelAdminNotice.php
+++ /dev/null
@@ -1,101 +0,0 @@
-admin_notice = new \WPMVCB_Admin_Notice_Model_Base( array(
- 'type' => 'updated',
- 'message' => 'foo message',
- 'screens' => array( 'post' ),
- ) );
-
- }
-
- public function tearDown() {
-
- unset( $this->admin_notice );
-
- }
-
- public function testPropertyExistsType() {
-
- $this->assertClassHasAttribute( 'type', 'WPMVCB_Admin_Notice_Model_Base' );
-
- }
-
- public function testPropertyExistsMessage() {
-
- $this->assertClassHasAttribute( 'message', 'WPMVCB_Admin_Notice_Model_Base' );
-
- }
-
- public function testPropertyExistsScreens() {
-
- $this->assertClassHasAttribute( 'screens', 'WPMVCB_Admin_Notice_Model_Base' );
-
- }
-
- /**
- * @covers ::get_type
- */
- public function testMethodGetType() {
-
- $this->assertTrue( method_exists( 'WPMVCB_Admin_Notice_Model_Base', 'get_type' ), 'Method get_type does not exist' );
- $this->assertEquals( 'updated', $this->admin_notice->get_type() );
-
- }
-
- /**
- * @covers ::get_message
- */
- public function testMethodGetMessage() {
-
- $this->assertTrue( method_exists( 'WPMVCB_Admin_Notice_Model_Base', 'get_message' ), 'Method get_message does not exist' );
- $this->assertEquals( 'foo message', $this->admin_notice->get_message() );
-
- }
-
- /**
- * @covers ::get_screens
- */
- public function testMethodGetScreens() {
-
- $this->assertTrue( method_exists( 'WPMVCB_Admin_Notice_Model_Base', 'get_screens' ), 'Method get_screens does not exist' );
- $this->assertEquals( array( 'post' ), $this->admin_notice->get_screens() );
-
- }
-
- /**
- * @covers ::get_screens
- */
- public function testMethodGetScreensEmptyScreens() {
-
- $this->assertTrue( method_exists( 'WPMVCB_Admin_Notice_Model_Base', 'get_screens' ), 'Method get_screens does not exist' );
-
- $notice = new \WPMVCB_Admin_Notice_Model_Base();
- $this->assertEmpty( $notice->get_screens() );
-
- }
-
- }
-
-}
diff --git a/tests/unit-tests/testBaseModelTaxonomy.php b/tests/unit-tests/testBaseModelTaxonomy.php
deleted file mode 100644
index 08c9859..0000000
--- a/tests/unit-tests/testBaseModelTaxonomy.php
+++ /dev/null
@@ -1,81 +0,0 @@
-model = new stubTaxonomy('foo','bar','baz','foobar','foobaz');
- }
-
- public function tearDown()
- {
- unset($this->model);
- }
-
- /**
- * @covers Base_Model_Taxonomy::get_slug
- */
- public function testMethodGetSlug()
- {
- $this->assertTrue(method_exists($this->model, 'get_slug'), 'Method get_slug() does not exist');
-
- $this->setReflectionPropertyValue($this->model, 'slug', 'foo slug');
- $this->assertEquals('foo slug', $this->model->get_slug());
- }
-
- /**
- * @covers Base_Model_Taxonomy::get_object_types
- */
- public function testMethodGetObjectTypes()
- {
- $this->assertTrue(method_exists($this->model, 'get_object_types'), 'Method get_object_types() does not exist');
-
- $this->setReflectionPropertyValue($this->model, 'object_types', 'foo types');
- $this->assertEquals('foo types', $this->model->get_object_types());
- }
-
- /**
- * @covers Base_Model_Taxonomy::get_args
- */
- public function testMethodGetArgs()
- {
- $this->assertTrue(method_exists($this->model, 'get_args'), 'Method get_args() does not exist');
-
- $this->setReflectionPropertyValue($this->model, 'args', 'foo args');
- $this->assertEquals('foo args', $this->model->get_args());
- }
-
- }
-
- class stubTaxonomy extends \Base_Model_Taxonomy
- {
- public function init()
- {
- $this->singular = 'foo single';
- $this->plural = 'foo plural';
- $this->slug = 'foo slug';
- }
- }
-}
-
\ No newline at end of file
diff --git a/tests/unit-tests/testPostModelBase.php b/tests/unit-tests/testPostModelBase.php
new file mode 100644
index 0000000..c5ae58f
--- /dev/null
+++ b/tests/unit-tests/testPostModelBase.php
@@ -0,0 +1,141 @@
+_post = $this->factory()->post->create_and_get();
+
+ update_post_meta($this->_post->ID, 'bar', 'baz');
+
+ $this->_model = new Post_Model_Base($this->_post, array('foo' => 'bar'));
+
+ parent::setUp();
+ }
+
+ /**
+ * @covers ::__construct
+ * @covers ::__call
+ */
+ public function testCallNoPostIsNull() {
+ $model = new Post_Model_Base(null);
+ $this->assertNull($model->ID());
+ }
+
+ /**
+ * @covers ::__call
+ * @covers ::_is_post_property
+ * @covers \WPMVCB\Model_Base::__call
+ */
+ public function testCallForPostModelBaseProperty() {
+ $this->assertEquals('bar', $this->_model->foo());
+ }
+
+ /**
+ * @covers ::__call
+ * @covers ::_is_post_property
+ * @covers \WPMVCB\Model_Base::__call
+ */
+ public function testCallForPostProperties() {
+ $post = $this->_post;
+ $model = $this->_model;
+
+ $this->assertEquals($post->ID, $model->ID(), 'The post ID does not match');
+ $this->assertEquals($post->ancestors, $model->ancestors(), 'The post ancestors does not match');
+ $this->assertEquals($post->post_author, $model->post_author(), 'The post author does not match');
+ $this->assertEquals($post->post_category, $model->post_category(), 'The post category does not match');
+ $this->assertEquals($post->post_content_filtered, $model->post_content_filtered(), 'The content filtered does not match');
+ $this->assertEquals($post->post_content, $model->post_content(), 'The post content does not match');
+ $this->assertEquals($post->post_date, $model->post_date(), 'The post date does not match');
+ $this->assertEquals($post->post_date_gmt, $model->post_date_gmt(), 'The post date gmt does not match');
+ $this->assertEquals($post->post_name, $model->post_name(), 'The post name does not match');
+ }
+
+ /**
+ * @covers ::__call
+ * @covers ::_is_post_property
+ */
+ public function testCallForPostMeta() {
+ $this->assertEquals('baz', $this->_model->bar());
+ }
+
+ /**
+ * @covers ::__construct
+ * @covers ::has_post
+ */
+ public function testHasPostFalse() {
+ $model = new Post_Model_Base(null);
+ $this->assertFalse($model->has_post());
+ }
+
+ /**
+ * @covers ::__construct
+ * @covers ::has_post
+ */
+ public function testHasPost() {
+ $this->assertTrue($this->_model->has_post());
+ }
+
+ /**
+ * @covers ::__call
+ * @covers \WPMVCB\Base::__construct
+ * @covers \WPMVCB\Base::__call
+ */
+ public function testPost() {
+ $this->assertEquals($this->_post, $this->_model->post());
+ }
+
+ /**
+ * @covers ::get_post
+ * @covers \WPMVCB\Base::deprecated
+ *
+ * @expectedException \PHPUnit_Framework_Error_Warning
+ */
+ public function testGetPost() {
+ $this->assertEquals($this->_post, $this->_model->get_post());
+ }
+
+ /**
+ * @covers ::has_image
+ */
+ public function testHasImageFalse() {
+ $this->assertFalse($this->_model->has_image());
+ }
+
+ /**
+ * @covers ::get_permalink
+ */
+ public function testGetPermalink() {
+ $this->assertEquals(get_the_permalink($this->_post->ID), $this->_model->get_permalink());
+ }
+
+ /**
+ * @covers ::get_image_id
+ */
+ public function testGetImageId() {
+ update_post_meta($this->_post->ID, '_thumbnail_id', 22);
+ $this->assertEquals(22, $this->_model->get_image_id());
+ }
+}
diff --git a/tests/unit-tests/testPostTypeBase.php b/tests/unit-tests/testPostTypeBase.php
new file mode 100644
index 0000000..994e0e0
--- /dev/null
+++ b/tests/unit-tests/testPostTypeBase.php
@@ -0,0 +1,22 @@
+factory()->post->create_and_get();
+
+ $this->assertNull(Post_Type_Base::get_instance($post->ID));
+ }
+
+}
\ No newline at end of file
diff --git a/tests/unit-tests/testTaxonomyBase.php b/tests/unit-tests/testTaxonomyBase.php
new file mode 100644
index 0000000..584bded
--- /dev/null
+++ b/tests/unit-tests/testTaxonomyBase.php
@@ -0,0 +1,48 @@
+assertInternalType('array', $types);
+ $this->assertEquals(2, count($types));
+ $this->assertContains('post', $types);
+ $this->assertContains('page', $types);
+ }
+
+ /**
+ * @covers ::register_taxonomy_args
+ * @covers \WPMVCB\Base::__callStatic
+ */
+ public function testTaxonomyArgs() {
+ Taxonomy_Base::register_taxonomy_args(array('foo' => 'bar'));
+
+ $args = Taxonomy_Base::taxonomy_args();
+ }
+
+ /**
+ * @covers ::on_load
+ */
+ public function testOnLoad() {
+ Taxonomy_Base::on_load();
+ $this->assertGreaterThan(0, has_action('init', array(Taxonomy_Base::class, 'init')));
+ }
+}
\ No newline at end of file
diff --git a/tests/unit-tests/test_base_controller.php b/tests/unit-tests/test_base_controller.php
deleted file mode 100644
index 82d77a4..0000000
--- a/tests/unit-tests/test_base_controller.php
+++ /dev/null
@@ -1,416 +0,0 @@
-_mock_path = trailingslashit( vfsStream::url( 'test_dir' ) );
- $this->_filesystem = vfsStreamWrapper::getRoot();
-
- $this->_controller = new Stub_Controller();
- }
-
- public function tearDown()
- {
- wp_deregister_script( 'fooscript' );
- unset( $this->_mock_path );
- unset( $this->_filesystem );
- unset( $this->_controller );
- }
-
- /**
- * @covers ::__construct
- */
- public function testActionExistsWpEnqueueScripts()
- {
- $this->assertFalse(
- false === has_action( 'wp_enqueue_scripts', array( &$this->_controller, 'wp_enqueue_scripts' ) ),
- 'wp_enqueue_scripts not hooked'
- );
- }
-
- /**
- * @covers ::__construct
- */
- public function testActionExistsAddMetaBoxes()
- {
- $this->assertFalse(
- false === has_action( 'add_meta_boxes', array( &$this->_controller, 'add_meta_boxes' ) ),
- 'wp_enqueue_scripts not hooked'
- );
- }
-
- /**
- * @covers ::__construct
- */
- public function testActionExistsAdminEnqueueScripts()
- {
- $this->assertFalse(
- false === has_action( 'admin_enqueue_scripts', array( &$this->_controller, 'admin_enqueue_scripts' ) ),
- 'add_meta_boxes not hooked'
- );
- }
-
- public function testMethodExistsAddShortcodes()
- {
- $this->assertTrue( method_exists( $this->_controller, 'add_shortcodes' ) );
- }
-
- /**
- * @covers ::add_shortcodes
- * @uses ::__construct
- * @depends testMethodExistsAddShortcodes
- */
- public function testMethodAddShortcodes()
- {
- $this->_controller->add_shortcodes( array( 'foo' => array( &$this, 'tearDown' ) ) );
- $this->assertTrue( shortcode_exists( 'foo' ) );
- remove_shortcode( 'foo' );
- }
-
- /**
- * @covers ::add_shortcodes
- * @uses ::__construct
- * @depends testMethodExistsAddShortcodes
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMethodAddShortcodesNonArray()
- {
- $this->_controller->add_shortcodes( 'foo' );
- }
-
- // public function testMethodExistsRenderMetabox()
- // {
- // $this->assertTrue( method_exists( $this->_controller, 'render_metabox' ) );
- // }
-
- // /**
- // * @depends testMethodExistsRenderMetabox
- // * @covers ::render_metabox
- // * @uses ::__construct
- // */
- // public function testRenderMetaboxNoViewSpecified()
- // {
- // $metabox = array(
- // 'id' => 'test-metabox',
- // 'args' => array()
- // );
-
- // //set up a post object
- // $factory = new \WP_UnitTest_Factory;
-
- // $post_id = $factory->post->create_object(
- // array(
- // 'post_title' => 'Test Render Metabox',
- // 'post_type' => 'post',
- // 'post_status' => 'publish'
- // )
- // );
-
- // $this->expectOutputString( 'No view specified in the callback arguments for metabox id test-metabox' );
- // $this->_controller->render_metabox( get_post( $post_id ), $metabox );
- // }
-
- // /**
- // * @depends testMethodExistsRenderMetabox
- // * @covers ::render_metabox
- // * @uses ::__construct
- // */
- // public function testRenderMetaboxViewNonexistent()
- // {
- // $metabox = array(
- // 'id' => 'test-metabox',
- // 'args' => array(
- // 'view' => 'foo.php'
- // )
- // );
-
- // //set up a post object
- // $factory = new \WP_UnitTest_Factory;
-
- // $post_id = $factory->post->create_object(
- // array(
- // 'post_title' => 'Test Render Metabox',
- // 'post_type' => 'post',
- // 'post_status' => 'publish'
- // )
- // );
-
- // $this->expectOutputString( 'The view file foo.php for metabox id test-metabox does not exist' );
- // $this->_controller->render_metabox( get_post( $post_id ), $metabox );
- // }
-
- // /**
- // * @depends testMethodExistsRenderMetabox
- // * @covers ::render_metabox
- // * @uses ::__construct
- // */
- // public function testMethodRenderMetabox()
- // {
- // //create our mock view directory
- // mkdir( $this->_mock_path . 'app/views', 0755, true );
- // $this->assertTrue( $this->_filesystem->hasChild( 'app/views' ) );
-
- // //create our mock View file
- // $handle = fopen( $this->_mock_path . 'app/views/foo.php', 'w' );
- // fwrite( $handle, 'This is foo.' );
- // fclose( $handle );
- // $this->assertFileExists( $this->_mock_path . 'app/views/foo.php' );
-
- // //set up a metabx
- // $metabox = array(
- // 'id' => 'test-metabox',
- // 'args' => array(
- // 'view' => $this->_mock_path . 'app/views/foo.php'
- // )
- // );
-
- // //set up a post object
- // $factory = new \WP_UnitTest_Factory;
-
- // $post_id = $factory->post->create_object(
- // array(
- // 'post_title' => 'Test Render Metabox',
- // 'post_type' => 'post',
- // 'post_status' => 'publish'
- // )
- // );
-
- // $this->expectOutputString( 'This is foo.' );
-
- // $this->_controller->render_metabox( get_post( $post_id ), $metabox, 'foo', 'bar', 'baz' );
- // }
-
- /**
- * @covers ::enqueue_scripts
- * @uses ::__construct
- */
- public function testMethodEnqueueScripts()
- {
- $this->assertTrue( method_exists( $this->_controller, 'enqueue_scripts' ), 'enqueue_scripts() does not exist' );
-
- //create a stub Base_Model_JS_Object
- $script = $this->getMockBuilder( '\Base_Model_JS_Object' )
- ->disableOriginalConstructor()
- ->setMethods( array( 'get_handle', 'get_src', 'get_deps', 'get_ver', 'get_in_footer' ) )
- ->getMock();
-
- $script->expects( $this->any() )
- ->method( 'get_handle' )
- ->will( $this->returnValue( 'fooscript' ) );
-
- $script->expects( $this->any() )
- ->method( 'get_src' )
- ->will( $this->returnValue('http://example.com/foo.js' ) );
-
- $script->expects( $this->any() )
- ->method( 'get_deps' )
- ->will( $this->returnValue( array( 'jquery' ) ) );
-
- $script->expects( $this->any() )
- ->method( 'get_ver' )
- ->will( $this->returnValue( true ) );
-
- $script->expects( $this->any() )
- ->method( 'get_in_footer' )
- ->will( $this->returnValue( true ) );
-
- $this->_controller->enqueue_scripts( array( 'fooscript' => $script ) );
-
- //make sure script is registered
- $this->assertScriptRegistered(
- array(
- 'fooscript',
- 'http://example.com/foo.js',
- array( 'jquery' ),
- true,
- true
- )
- );
-
- //and enqueued
- $this->assertTrue( wp_script_is( 'fooscript', 'enqueued' ), 'script not enuqueued' );
- }
-
- /**
- * In this test, we pass an non-array to the method.
- *
- * @covers ::enqueue_scripts
- * @uses ::__construct
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMethodEnqueueScriptsNonArray()
- {
- $this->_controller->enqueue_scripts( 'foo' );
- }
-
- /**
- * In this test, we pass an array that does not contain Base_Model_JS_Objects.
- *
- * @covers ::enqueue_scripts
- * @uses ::__construct
- */
- public function testMethodEnqueueScriptsInvalidScriptObject()
- {
- $script = new \StdClass();
-
- $this->assertEquals(
- new \WP_Error(
- 'invalid object type',
- 'fooscript is not a Base_Model_JS_Object',
- $script
- ),
- $this->_controller->enqueue_scripts( array( 'fooscript' => $script ) )
- );
- }
-
- /**
- * @covers ::__call
- */
- public function testMethodCallonModel() {
-
- $stub = new Stub_Controller(array('model' => new Stub_Model));
-
- $this->assertEquals('bar', $stub->foo());
- }
-
- /**
- * @covers ::__call
- */
- public function testMethodCallOnView() {
-
- $stub = new Stub_Controller( array('view' => new Stub_View));
-
- $this->assertEquals('bar', $stub->foo());
-
- }
-
- /**
- * @covers ::__call
- */
- public function testMethodCallError() {
-
- $result = @$this->_controller->foo();
- $this->assertInstanceOf('WP_Error', $result);
- $this->assertNotEmpty($result->get_error_message());
-
- }
-
- /**
- * @covers ::__get
- */
- public function testMethodGetOnModel() {
-
- $stub = new Stub_Controller(array('model' => new Stub_Model));
-
- $this->assertEquals('bar', $stub->foo);
- }
-
- /**
- * @covers ::__get
- */
- public function testMethodGetOnView() {
-
- $stub = new Stub_Controller(array('view' => new Stub_View));
-
- $this->assertEquals('bar', $stub->foo);
-
- }
-
- /**
- * @covers ::__get
- */
- public function testMethodGetOnModelError() {
-
- $result = @$this->_controller->foo;
- $this->assertInstanceOf('WP_Error', $result);
- $this->assertNotEmpty($result->get_error_message());
-
- }
- }
-
- /**
- * Class Stub_Controller
- *
- * @package WPMVCB\Testing
- * @internal
- */
- class Stub_Controller extends WPMVC_Controller_Base
- {
- }
-
- /**
- * Class Stub_Model
- *
- * @package WPMVCB\Testing
- * @internal
- */
- class Stub_Model {
-
- public $foo = 'bar';
-
- public function foo() {
-
- return $this->foo;
-
- }
-
- }
-
- /**
- * Class Stub_View
- *
- * @package WPMVCB\Testing
- * @internal
- */
- class Stub_View {
-
- public $foo = 'bar';
-
- public function foo() {
-
- return $this->foo;
-
- }
-
- }
-
-}
diff --git a/tests/unit-tests/test_base_controller_cpt.php b/tests/unit-tests/test_base_controller_cpt.php
deleted file mode 100644
index e598c06..0000000
--- a/tests/unit-tests/test_base_controller_cpt.php
+++ /dev/null
@@ -1,114 +0,0 @@
-_controller = new WPMVCB_Cpt_Base();
-
- }
-
- public function tearDown() {
-
- unset( $this->_controller );
-
- }
-
- private function _createStubCptModel() {
-
- // Create stub for cpt_model
- $cpt_model = $this->getMockBuilder( '\Base_Model_CPT' )
- ->disableOriginalConstructor()
- ->setMethods(
- array(
- 'get_slug',
- 'get_args',
- 'get_post_updated_messages',
- 'get_metaboxes',
- 'get_singular',
- 'get_plural',
- 'get_scripts',
- 'get_admin_scripts',
- 'save_post'
- )
- )
- ->getMockForAbstractClass();
-
- return $cpt_model;
-
- }
-
-
- /**
- * @covers ::post_updated_messages
- */
- public function testMethodPostUpdatedMessages() {
-
- $this->assertTrue( method_exists( $this->_controller, 'post_updated_messages' ) );
-
- register_post_type( 'foocptslug', array( 'labels' => array( 'singular_name' => 'Book' ) ) );
-
- global $post;
-
- $post = $this->factory->post->create_and_get( array( 'post_type' => 'foocptslug' ) );
-
- $messages = $this->_controller->post_updated_messages( array() );
-
- $expected = array(
- 0 => null, // Unused. Messages start at index 1.
- 1 => sprintf( __('Book updated. View book', 'wpmvcb'), esc_url( get_permalink( $post->ID) ) ),
- 2 => __('Custom field updated.', 'wpmvcb'),
- 3 => __('Custom field deleted.', 'wpmvcb'),
- 4 => __('Book updated.', 'wpmvcb'),
- /* translators: %s: date and time of the revision */
- 5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision from %s', 'wpmvcb'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
- 6 => sprintf( __('Book published. View Book', 'wpmvcb'), esc_url( get_permalink($post->ID) ) ),
- 7 => __('Book saved.', 'wpmvcb'),
- 8 => sprintf( __('Book submitted. Preview book', 'wpmvcb'), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID) ) ) ),
- 9 => sprintf( __('Book scheduled for: %1$s. Preview book', 'wpmvcb'),
- // translators: Publish box date format, see http://php.net/date
- date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post->ID ) ) ),
- 10 => sprintf( __('Book draft updated. Preview book', 'wpmvcb'), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID) ) ) )
- );
-
- $this->assertArrayHasKey( 'foocptslug', $messages, __( 'Messages not present in array', 'wpmvcb' ) );
- $this->assertEquals( $expected, $messages['foocptslug'] );
-
- }
-
- /**
- * @covers ::on_load
- */
- public function testActionPostUpdatedMessagesExists()
- {
- $this->assertFalse( false === has_filter( 'post_updated_messages', array( 'WPMVCB_Cpt_Base', 'post_updated_messages' ) ) );
- }
-
- }
-
-}
diff --git a/tests/unit-tests/test_base_controller_plugin.php b/tests/unit-tests/test_base_controller_plugin.php
deleted file mode 100644
index fa8b063..0000000
--- a/tests/unit-tests/test_base_controller_plugin.php
+++ /dev/null
@@ -1,226 +0,0 @@
-model = Mockery::mock( 'Base_Model_Plugin' );
- $this->model->shouldReceive( 'get_help_tabs' )->andReturn(array(
- 'foo' => Mockery::mock( 'Base_Model_Help_Tab' )->shouldReceive( 'get_screens' )->andReturn( 'foo' ),
- 'bar' => Mockery::mock( 'Base_Model_Help_Tab' )->shouldReceive( 'get_screens' )->andReturn( 'foo' ),
- ) );
-
- //set up our controller
- $this->controller = new Stub_Plugin_Controller( array( 'model' => $this->model ) );
-
- }
-
- public function tearDown() {
-
- wp_deregister_script( 'fooscript' );
- unset( $this->controller );
-
- }
-
- public function testActionAdminNoticesExists() {
-
- $this->assertFalse( false === has_action( 'admin_notices', array( $this->controller, 'admin_notice' ) ) );
-
- }
-
- public function testActionPluginsLoadedExists() {
-
- $this->assertFalse(false === has_action( 'plugins_loaded', array( $this->controller, 'load_text_domain' ) ) );
-
- }
-
- public function testActionAddMetaBoxesExists() {
-
- $this->assertFalse(false === has_action( 'add_meta_boxes', array( $this->controller, 'add_meta_boxes' ) ) );
-
- }
-
- public function testActionAdminEnqueueScriptsExists() {
-
- $this->assertFalse(false === has_action( 'admin_enqueue_scripts', array( $this->controller, 'admin_enqueue_scripts' ) ) );
-
- }
-
- public function testActionWpEnqueueScriptsExists() {
-
- $this->assertFalse(false === has_action( 'wp_enqueue_scripts', array( $this->controller, 'wp_enqueue_scripts' ) ) );
-
- }
-
- /**
- * covers Base_Controller_Plugin::wp_enqueue_scripts
- */
- public function testMethodWpEnqueueScripts() {
-
- $this->assertTrue(method_exists( $this->controller, 'wp_enqueue_scripts' ) );
-
- $script = $this->getMockBuilder( '\Base_Model_JS_Object' )
- ->disableOriginalConstructor()
- ->setMethods(array( 'get_handle', 'get_src', 'get_deps', 'get_ver', 'get_in_footer' ) )
- ->getMock();
-
- $script->expects( $this->any() )
- ->method( 'get_handle' )
- ->will( $this->returnValue( 'fooscript' ) );
-
- $script->expects( $this->any() )
- ->method( 'get_src' )
- ->will( $this->returnValue( 'http://example.com/foo.js' ) );
-
- $script->expects( $this->any() )
- ->method( 'get_deps' )
- ->will( $this->returnValue( array( 'jquery' ) ) );
-
- $script->expects( $this->any() )
- ->method( 'get_ver' )
- ->will( $this->returnValue( true ) );
-
- $script->expects( $this->any() )
- ->method( 'get_in_footer' )
- ->will( $this->returnValue( true ) );
-
- $model = $this->getMockBuilder( '\Base_Model_Plugin' )
- ->disableOriginalConstructor()
- ->setMethods(array( 'get_scripts' ) )
- ->getMockForAbstractClass();
-
- $model->expects( $this->any() )
- ->method( 'get_scripts' )
- ->will( $this->returnValue( array( $script ) ) );
-
- //add the model to the controller
- $this->setReflectionPropertyValue( $this->controller, 'model', $model );
-
- //call the SUT
- $this->controller->wp_enqueue_scripts();
-
- //make sure script is registered
- $this->assertScriptRegistered(
- array(
- 'fooscript',
- 'http://example.com/foo.js',
- array( 'jquery' ),
- true,
- true
- )
- );
-
- //and enqueued
- $this->assertTrue( wp_script_is( 'fooscript', 'enqueued' ), 'script not enqueued' );
-
- }
-
- /**
- * covers Base_Controller_Plugin::admin_enqueue_scripts
- */
- public function testMethodAdminEnqueueScripts()
- {
- $this->assertTrue(method_exists( $this->controller, 'admin_enqueue_scripts' ) );
-
- $script = $this->getMockBuilder( '\Base_Model_JS_Object' )
- ->disableOriginalConstructor()
- ->setMethods( array( 'get_handle', 'get_src', 'get_deps', 'get_version', 'get_in_footer' ) )
- ->getMockForAbstractClass();
-
- $script->expects( $this->any() )
- ->method( 'get_handle' )
- ->will( $this->returnValue( 'fooadminscript' ) );
-
- $script->expects( $this->any() )
- ->method( 'get_src' )
- ->will( $this->returnValue( 'http://example.com/fooadmin.js' ) );
-
- $script->expects( $this->any() )
- ->method( 'get_deps' )
- ->will( $this->returnValue( array( 'jquery' ) ) );
-
- $script->expects( $this->any() )
- ->method( 'get_version' )
- ->will( $this->returnValue( true ) );
-
- $script->expects( $this->any() )
- ->method( 'get_in_footer' )
- ->will( $this->returnValue( true ) );
-
- $model = $this->getMockBuilder( '\Base_Model_Plugin' )
- ->disableOriginalConstructor()
- ->setMethods(array( 'get_admin_scripts', 'get_textdomain', 'get_uri' ) )
- ->getMockForAbstractClass();
-
- $model->expects( $this->any() )
- ->method( 'get_admin_scripts' )
- ->will( $this->returnValue(array( $script) ) );
-
- $model->expects( $this->any() )
- ->method( 'get_textdomain' )
- ->will( $this->returnValue( 'footxtdomain' ) );
-
- $this->setReflectionPropertyValue( $this->controller, 'model', $model);
-
- $this->controller->admin_enqueue_scripts( 'foohook' );
-
- $this->assertTrue(wp_script_is( 'fooadminscript', 'registered' ) );
-
- global $wp_scripts;
-
- $this->assertArrayHasKey( 'fooadminscript', $wp_scripts->registered);
- $this->assertEquals( $wp_scripts->registered['fooadminscript']->handle, 'fooadminscript' );
- $this->assertEquals( $wp_scripts->registered['fooadminscript']->src, 'http://example.com/fooadmin.js' );
- $this->assertEquals( $wp_scripts->registered['fooadminscript']->deps, array( 'jquery' ) );
- $this->assertEquals( $wp_scripts->registered['fooadminscript']->ver, true);
- $this->assertEquals( $wp_scripts->registered['fooadminscript']->extra, array( 'group' => 1) );
-
- }
- }
-
- /**
- * Class Stub_Plugin_Controller
- *
- * @package WPMVCB\Testing
- */
- class Stub_Plugin_Controller extends Base_Controller_Plugin {
-
- public function __construct( array $args = array() )
- {
- $args = wp_parse_args( $args, array(
- 'model' => Mockery::mock( 'Base_Model_Plugin' ),
- ) );
-
- parent::__construct( $args );
- }
-
- }
-
-}
diff --git a/tests/unit-tests/test_base_controller_settings.php b/tests/unit-tests/test_base_controller_settings.php
deleted file mode 100644
index 431e6e3..0000000
--- a/tests/unit-tests/test_base_controller_settings.php
+++ /dev/null
@@ -1,772 +0,0 @@
-model = $this
- ->getMockBuilder( '\WPMVCB_Settings_Model_Base' )
- ->disableOriginalConstructor()
- ->setMethods(
- array(
- 'get_settings_sections',
- 'get_settings_fields',
- 'get_options',
- 'get_pages'
- )
- )
- ->getMockForAbstractClass();
-
- $this->controller = new WPMVCB_Settings_Base( $this->model );
-
- }
-
- private function mockFilesystem() {
-
- //set up our virtual filesystem
- \org\bovigo\vfs\vfsStreamWrapper::register();
- \org\bovigo\vfs\vfsStreamWrapper::setRoot( new \org\bovigo\vfs\vfsStreamDirectory( 'test_dir' ) );
- $this->mock_path = trailingslashit( \org\bovigo\vfs\vfsStream::url( 'test_dir' ) );
- $this->filesystem = \org\bovigo\vfs\vfsStreamWrapper::getRoot();
-
- }
-
- public function testAttibuteExistsModel() {
-
- $this->assertClassHasAttribute( 'model', 'WPMVCB_Settings_Base' );
-
- }
-
- public function testMethodConstructSetModel() {
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertSame( $this->model, $this->getReflectionPropertyValue( $controller, 'model' ) );
- $this->tearDown( $controller );
-
- }
-
- public function testActionExistsAdminInitAddSettingsSections() {
-
- $this->model
- ->expects( $this->any() )
- ->method( 'get_settings_sections' )
- ->will( $this->returnValue( array() ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertFalse( false === has_action( 'admin_init', array( $controller, 'add_settings_sections' ) ) );
- $this->tearDown( $controller );
-
- }
-
- public function testActionExistsAdminInitAddSettingsFields() {
-
- $this->model
- ->expects( $this->any() )
- ->method( 'get_settings_fields' )
- ->will( $this->returnValue( array() ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertFalse( false === has_action( 'admin_init', array( $controller, 'add_settings_fields' ) ) );
- $this->tearDown( $controller );
-
- }
-
- public function testActionExistsAdminInitRegisterOptions() {
-
- $this->model
- ->expects( $this->any() )
- ->method( 'get_options' )
- ->will( $this->returnValue( array() ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertFalse( false === has_action( 'admin_init', array( $controller, 'register_options' ) ) );
- $this->tearDown( $controller );
-
- }
-
- public function testActionExistsAdminMenuAddMenuPages() {
-
- $this->model
- ->expects( $this->any() )
- ->method( 'get_pages' )
- ->will( $this->returnValue( array() ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertFalse( false === has_action( 'admin_menu', array( $controller, 'add_menu_pages' ) ) );
- $this->tearDown( $controller );
-
- }
-
- /**
- * Test method register_options().
- *
- * This test is subject to breaking as it uses WP internals. Ideally, a better solution should be found.
- * @covers ::register_options
- */
- public function testMethodRegisterOptions() {
-
- global $new_whitelist_options;
-
- $this->model
- ->expects( $this->any() )
- ->method( 'get_options' )
- ->will( $this->returnValue( array( 'foo' => array( 'option_group' => 'bar', 'option_name' => 'baz' ) ) ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertTrue( method_exists( $controller, 'register_options' ) );
- $controller->register_options();
-
- $this->assertArrayHasKey( 'bar', $new_whitelist_options );
- $this->assertSame( array( 'baz' ), $new_whitelist_options['bar'] );
- $this->tearDown( $controller );
-
- }
-
- /**
- * @covers ::add_settings_sections
- */
- public function testMethodAddSettingsSections() {
-
- global $wp_settings_sections;
-
- $this->assertTrue( method_exists( $this->controller, 'add_settings_sections' ) );
-
- //set up a settings section
- $section = array(
- 'foosection' => array(
- 'title' => 'Foo Section Title',
- 'callback' => null,
- 'page' => 'foopage',
- 'content' => 'Foo content'
- )
- );
-
- //set up the stub settings model
- $this->model
- ->expects( $this->any() )
- ->method( 'get_settings_sections' )
- ->will( $this->returnValue( $section ) );
-
- //create a new controller
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $controller->add_settings_sections();
-
- $this->assertArrayHasKey( 'foopage', $wp_settings_sections );
- $this->assertArrayHasKey( 'foosection', $wp_settings_sections['foopage'] );
- $this->assertSame( 'foosection', $wp_settings_sections['foopage']['foosection']['id'] );
- $this->assertSame( 'Foo Section Title', $wp_settings_sections['foopage']['foosection']['title'] );
- $this->assertSame(
- array( $controller, 'render_settings_section' ),
- $wp_settings_sections['foopage']['foosection']['callback']
- );
-
- $this->tearDown( $controller );
-
- }
-
- /**
- * @uses $wp_settings_fields
- * @covers ::add_settings_fields
- */
- public function testMethodAddSettingsFields() {
-
- global $wp_settings_fields;
-
- $this->assertTrue( method_exists( $this->controller, 'add_settings_fields' ) );
-
- $fields = array(
- 'foofield' => array(
- 'title' => 'Foo Field',
- 'callback' => null,
- 'page' => 'foopage',
- 'section' => 'foosection',
- 'args' => array( 'bar', 'baz' )
- )
- );
-
- $this->model
- ->expects( $this->any() )
- ->method( 'get_settings_fields' )
- ->will( $this->returnValue( $fields ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $controller->add_settings_fields();
-
- $this->assertArrayHasKey( 'foopage', $wp_settings_fields );
- $this->assertArrayHasKey( 'foosection', $wp_settings_fields['foopage'] );
- $this->assertArrayHasKey( 'foofield', $wp_settings_fields['foopage']['foosection'] );
- $this->assertSame( 'foofield', $wp_settings_fields['foopage']['foosection']['foofield']['id'] );
- $this->assertSame( 'Foo Field', $wp_settings_fields['foopage']['foosection']['foofield']['title'] );
- $this->assertSame(
- array( $controller, 'render_settings_field' ),
- $wp_settings_fields['foopage']['foosection']['foofield']['callback']
- );
- $this->assertSame(
- array( 'bar', 'baz' ),
- $wp_settings_fields['foopage']['foosection']['foofield']['args']
- );
-
- }
-
- /**
- * @covers ::add_menu_pages
- */
- public function testMethodAddMenuPagesMenu() {
-
- $this->markTestIncomplete( 'Not yet implemented' );
- $this->assertTrue( method_exists( $this->controller, 'add_menu_pages' ) );
-
- //set up a page object stub
- require_once WPMVCB_SRC_DIR . '/models/class-menu-page-model-base.php';
-
- $page = new \WPMVCB_Menu_Page_Model_Base();
- $this->setReflectionPropertyValue( $page, 'page_title', 'foo_title' );
- $this->setReflectionPropertyValue( $page, 'menu_title', 'Foo Title' );
- $this->setReflectionPropertyValue( $page, 'capability', 'manage_options' );
- $this->setReflectionPropertyValue( $page, 'menu_slug', 'foo-slug' );
-
- //set up the model
- $this->model
- ->expects( $this->any() )
- ->method( 'get_pages' )
- ->will( $this->returnValue( array( 0 => $page ) ) );
-
- //add the page to the model
- $this->setReflectionPropertyValue( $this->model, 'pages', array( 'foo-page' => $page ) );
-
- wp_set_current_user( 0 );
-
- //create the settings controller
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertTrue( $controller->add_menu_pages() );
-
- //get a reflection of the model pages property
- $model = $this->getReflectionPropertyValue( $controller, 'model' );
- $pages = $this->getReflectionPropertyValue( $model, 'pages' );
-
- $this->assertArrayHasKey( 'foo-page', $pages );
- $this->assertEquals( 'toplevel_page_foo-slug', $this->getReflectionPropertyValue( $pages['foo-page'], 'hook_suffix' ) );
- $this->tearDown( $controller );
-
- }
-
- /**
- * @covers ::add_menu_pages
- */
- public function testMethodAddMenuPagesMenuError() {
-
- $this->assertTrue( method_exists( $this->controller, 'add_menu_pages' ) );
-
- //set up a page object stub
- require_once WPMVCB_SRC_DIR . '/models/class-menu-page-model-base.php';
-
- $page = new \WPMVCB_Menu_Page_Model_Base();
- $this->setReflectionPropertyValue( $page, 'parent_slug', 'general' );
- $this->setReflectionPropertyValue( $page, 'page_title', 'foo_title' );
- $this->setReflectionPropertyValue( $page, 'menu_title', 'Foo Title' );
- $this->setReflectionPropertyValue( $page, 'capability', 'foo_capability' );
- $this->setReflectionPropertyValue( $page, 'menu_slug', 'foo-slug' );
-
- //set up the model
- $this->model
- ->expects( $this->any() )
- ->method( 'get_pages' )
- ->will( $this->returnValue( array( 0 => $page ) ) );
-
- //add the page to the model
- $this->setReflectionPropertyValue( $this->model, 'pages', array( 'foo-page' => $page ) );
-
- wp_set_current_user( 0 );
-
- //create the settings controller
- $controller = new \WPMVCB_Settings_Base( $this->model );
-
- $this->assertEquals(
- new \WP_Error(
- 'failure',
- 'Unable to add submenu page: 0.',
- $page
- ),
- $controller->add_menu_pages()
- );
-
- $this->tearDown( $controller );
-
- }
-
- public function testMethodExistsRenderOptionsPage() {
-
- $this->assertTrue( method_exists( $this->controller, 'render_options_page' ) );
-
- }
-
- /**
- * Ensure the default options page view exists and is used on non-existent view.
- *
- * @depends testMethodExistsRenderOptionsPage
- * @covers ::render_options_page
- */
- public function testMethodRenderOptionsPageNoView() {
-
- set_current_screen( 'foopage' );
- $pages = array( 'foopage' => array( 'menu_slug' => 'foo-options-page', 'page_title' => 'Foo Options Page', 'view' => 'fooview.php' ) );
-
- $this->model
- ->expects( $this->any() )
- ->method( 'get_pages' )
- ->will( $this->returnValue( $pages ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
- $this->assertFileExists( WPMVCB_SRC_DIR . '/views/base_options_page.php' );
-
- $page = $pages['foopage'];
- $this->txtdomain = 'footxtdomain';
-
- ob_start();
- include WPMVCB_SRC_DIR . '/views/base_options_page.php';
- $expected = ob_get_clean();
-
- ob_start();
- $controller->render_options_page();
- $output = ob_get_clean();
-
- //$this->assertSame( $expected, $output );
- $this->assertSame( $expected, $output );
-
- }
-
- /**
- * @depends testMethodExistsRenderOptionsPage
- * @covers ::render_options_page
- * @requires set_current_screen
- */
- public function testMethodRenderOptionsPageViewExists() {
-
- //set up mock filesystem
- $this->mockFilesystem();
-
- //create a mock view file
- $handle = fopen( $this->mock_path . '/view.php', 'w' );
- fwrite($handle, 'foobar');
- fclose( $handle );
- $this->assertTrue( $this->filesystem->hasChild( 'view.php' ) );
-
- //set the WP_Screen object
- set_current_screen( 'foopage' );
-
- //set up a page object
- $pages = array(
- 'foopage' => array(
- 'view' => $this->mock_path . '/view.php'
- )
- );
-
- //set up the settings model stub
- $this->model
- ->expects( $this->any() )
- ->method( 'get_pages' )
- ->will( $this->returnValue( $pages ) );
-
- $controller = new \WPMVCB_Settings_Base( $this->model );
-
- //get the actual output
- ob_start();
- $controller->render_options_page();
- $output = ob_get_clean();
-
- //assert they are the same
- $this->assertSame( 'foobar', $output );
-
- }
-
- public function testMethodExistsRenderSettingsSection() {
-
- $this->assertTrue( method_exists( $this->controller, 'render_settings_section' ) );
-
- }
-
- /**
- * @covers ::render_settings_section
- * @depends testMethodExistsRenderSettingsSection
- */
- public function testMethodRenderSettingsSectionViewNonExistent() {
-
- //set up a settings section
- $section = array(
- 'title' => 'Foo Section Title',
- 'callback' => null,
- 'page' => 'foopage',
- 'content' => 'Foo content'
- );
-
- //set up the stub settings model
- $this->model
- ->expects( $this->any() )
- ->method( 'get_settings_sections' )
- ->will( $this->returnValue( $section ) );
-
- //create a new controller
- $controller = new \WPMVCB_Settings_Base( $this->model );
-
- ob_start();
- $controller->render_settings_section( array( 'id' => 'foosection' ) );
- $output = ob_get_clean();
-
- $this->assertSame( 'Foo content', $output );
-
- }
-
- /**
- * @covers ::render_settings_section
- * @depends testMethodExistsRenderSettingsSection
- */
- public function testMethodRenderSettingsSectionViewExists() {
-
- //set up our virtual filesystem
- \org\bovigo\vfs\vfsStreamWrapper::register();
- \org\bovigo\vfs\vfsStreamWrapper::setRoot( new \org\bovigo\vfs\vfsStreamDirectory( 'test_dir' ) );
- $this->mock_path = trailingslashit( \org\bovigo\vfs\vfsStream::url( 'test_dir' ) );
- $this->filesystem = \org\bovigo\vfs\vfsStreamWrapper::getRoot();
-
- //set up a view file
- $this->mockFilesystem();
- $handle = fopen( $this->mock_path . '/view.php', 'w' );
- fwrite($handle, 'foobar');
- fclose( $handle );
- $this->assertTrue( $this->filesystem->hasChild( 'view.php' ) );
-
- //set up a settings section
- $section = array(
- 'title' => 'Foo Section Title',
- 'callback' => null,
- 'page' => 'foopage',
- 'content' => 'Foo content',
- 'view' => $this->mock_path . '/view.php'
- );
-
- //set up the stub settings model
- $this->model
- ->expects( $this->any() )
- ->method( 'get_settings_sections' )
- ->will( $this->returnValue( $section ) );
-
- //create a new controller
- $controller = new \WPMVCB_Settings_Base( $this->model );
-
- //get the expected output
- ob_start();
- include $this->mock_path . '/view.php';
- $expected = ob_get_clean();
-
- ob_start();
- $controller->render_settings_section( array( 'id' => 'foosection' ) );
- $output = ob_get_clean();
-
- $this->assertSame( $expected, $output );
- unset( $this->mock_path );
- unset( $this->filesystem );
- $this->tearDown( $controller );
-
- }
-
- public function testMethodExistsRenderSettingsField() {
-
- $this->assertTrue( method_exists( $this->controller, 'render_settings_field' ) );
-
- }
-
- /**
- * Test render_settings_field response when call lacks required parameters type, id, and/or name
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- * @expectedException PHPUnit_Framework_Error
- * @expectedErrorMessage The settings field type, id and name must be set
- */
- public function testMethodFailRenderSettingsFieldNoType() {
-
- $this->controller->render_settings_field( array( 'type' => null, 'id' => 'bar', 'name' => 'baz' ) );
-
- }
-
- /**
- * Test render_settings_field response when call lacks required parameters type, id, and/or name
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- * @expectedException PHPUnit_Framework_Error
- * @expectedErrorMessage The settings field type, id and name must be set
- */
- public function testMethodFailRenderSettingsFieldNoId() {
-
- $this->controller->render_settings_field( array( 'type' => 'foo', 'id' => null, 'name' => 'baz' ) );
-
- }
-
- /**
- * Test render_settings_field response when call lacks required parameters type, id, and/or name
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- * @expectedException PHPUnit_Framework_Error
- * @expectedErrorMessage The settings field type, id and name must be set
- */
- public function testMethodFailRenderSettingsFieldNoName() {
-
- $this->controller->render_settings_field( array( 'type' => 'foo', 'id' => 'bar', 'name' => null ) );
-
- }
-
- /**
- * Test render_settings_field response when rendering select field with no options
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- * @expectedException PHPUnit_Framework_Error
- * @expectedErrorMessage The settings field type, id and name must be set
- */
- public function testMethodRenderSettingsFieldFailNoOptions() {
-
- $field = array(
- 'type' => 'select',
- 'id' => 'my-super-cool-select',
- 'name' => 'my_super_cool_select',
- 'value' => 'my-super-cool-value',
- );
-
- $this->controller->render_settings_field( $field );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodRenderInputText() {
-
- $field = array(
- 'type' => 'text',
- 'id' => 'my-super-cool-field',
- 'name' => 'my_super_cool_field',
- 'value' => 'foo',
- 'placeholder' => 'Enter some value',
- 'after' => 'bar'
- );
-
- $expected = 'bar';
-
- $this->expectOutputString( $expected );
- $this->controller->render_settings_field( $field );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodReturnInputText() {
-
- $this->mockFilesystem();
- $handle = fopen( $this->mock_path . '/view.php', 'w' );
- fwrite($handle, 'foobar');
- fclose( $handle );
- $this->assertTrue( $this->filesystem->hasChild( 'view.php' ) );
-
- $field = array(
- 'type' => 'text',
- 'id' => 'my-super-cool-field',
- 'name' => 'my_super_cool_field',
- 'value' => 'foo',
- 'placeholder' => 'Enter some value',
- 'after' => $this->mock_path . '/view.php'
- );
-
- $expected = 'foobar';
-
- $this->assertSame( $expected, $this->controller->render_settings_field( $field, 'noecho' ) );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodRenderInputCheckbox() {
-
- $field = array(
- 'type' => 'checkbox',
- 'id' => 'my-super-cool-checkbox',
- 'name' => 'my_super_cool_checkbox',
- 'value' => '0',
- );
-
- $expected = '';
-
- $this->expectOutputString( $expected );
- $this->controller->render_settings_field( $field );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodReturnInputCheckbox() {
-
- $field = array(
- 'type' => 'checkbox',
- 'id' => 'my-super-cool-checkbox',
- 'name' => 'my_super_cool_checkbox',
- 'value' => '0'
- );
-
- $expected = '';
-
- $this->assertSame( $expected, $this->controller->render_settings_field( $field, 'noecho' ) );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodRenderInputCheckboxChecked() {
-
- $field = array(
- 'type' => 'checkbox',
- 'id' => 'my-super-cool-checkbox',
- 'name' => 'my_super_cool_checkbox',
- 'value' => '1',
- );
-
- $expected = '';
-
- $this->expectOutputString( $expected );
- $this->controller->render_settings_field( $field );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodReturnInputCheckboxChecked() {
-
- $field = array(
- 'type' => 'checkbox',
- 'id' => 'my-super-cool-checkbox',
- 'name' => 'my_super_cool_checkbox',
- 'value' => '1',
- );
-
- $expected = '';
-
- $this->assertSame( $expected, $this->controller->render_settings_field( $field, 'noecho' ) );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodRenderInputSelect() {
-
- $field = array(
- 'type' => 'select',
- 'id' => 'my-super-cool-select',
- 'name' => 'my_super_cool_select',
- 'value' => 'my-super-cool-value',
- 'options' => array(
- 'my_super_cool_option' => 'My Super Cool Option'
- )
- );
-
- $expected = '';
-
- $this->expectOutputString( $expected );
- $this->controller->render_settings_field( $field );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodReturnInputSelect() {
- $field = array(
- 'type' => 'select',
- 'id' => 'my-super-cool-select',
- 'name' => 'my_super_cool_select',
- 'value' => 'my-super-cool-value',
- 'options' => array(
- 'my_super_cool_option' => 'My Super Cool Option'
- )
- );
-
- $expected = '';
-
- $this->assertSame( $expected, $this->controller->render_settings_field( $field, 'noecho' ) );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodRenderTextarea() {
-
- $field = array(
- 'type' => 'textarea',
- 'id' => 'my-super-cool-textarea',
- 'name' => 'my_super_cool_textarea',
- 'value' => 'My textarea content',
- 'placeholder' => __( 'foo placeholder', 'wpmvcb' ),
- );
- $expected = '';
- $this->expectOutputString( $expected );
- $this->controller->render_settings_field( $field, 'echo' );
-
- }
-
- /**
- * @depends testMethodExistsRenderSettingsField
- * @covers ::render_settings_field
- */
- public function testMethodReturnTextarea() {
-
- $field = array(
- 'type' => 'textarea',
- 'id' => 'my-super-cool-textarea',
- 'name' => 'my_super_cool_textarea',
- 'value' => 'My textarea content',
- 'placeholder' => __( 'foo placeholder', 'wpmvcb' ),
- );
- $expected = '';
- $this->assertSame( $expected, $this->controller->render_settings_field( $field, 'noecho' ) );
-
- }
-
- }
-
-}
diff --git a/tests/unit-tests/test_base_helpers.php b/tests/unit-tests/test_base_helpers.php
deleted file mode 100644
index 25235da..0000000
--- a/tests/unit-tests/test_base_helpers.php
+++ /dev/null
@@ -1,163 +0,0 @@
-_base_dir_path = \org\bovigo\vfs\vfsStream::url( 'test_dir' );
- $this->_filesystem = \org\bovigo\vfs\vfsStreamWrapper::getRoot();
- }
-
- public function testVfsDirectoryExists()
- {
- $this->assertTrue( is_dir( $this->_base_dir_path ) );
- }
-
- public function testCreateDirectoryDirNonexistent()
- {
- \Helper_Functions::create_directory( $this->_base_dir_path . '/foo/bar' );
- $this->assertTrue( $this->_filesystem->hasChild( 'foo/bar' ) );
- }
-
- public function testCreateDirectoryDirExistent()
- {
- \Helper_Functions::create_directory( $this->_base_dir_path );
- $this->assertTrue( $this->_filesystem->hasChild( 'index.php' ) );
- }
-
- public function testGetLocalDirectoryContents()
- {
- \Helper_Functions::create_directory( $this->_base_dir_path . '/foo/bar' );
-
- $this->assertEquals(
- array(
- 0 => array (
- 'filename' => 'index.php',
- 'filetype' => '',
- 'mimetype' => ''
- )
- ),
- \Helper_Functions::get_local_directory_contents( $this->_base_dir_path . '/foo/bar' )
- );
- }
-
- public function testGetLocalDirectoryContentsDirNonexistent()
- {
- $this->assertEquals( null, \Helper_Functions::get_local_directory_contents( $this->_base_dir_path . '/bar' ) );
- }
-
- public function testRemoveLocalDirectory()
- {
- $this->markTestIncomplete( 'This cannot be implemented using vfsStream due to being incompatible with SplFileInfo::getRealPath(). See https://github.com/mikey179/vfsStream/wiki/Known-Issues.');
- }
-
- public function testRemoveLocalDirectoryDirParamSlash()
- {
- $this->assertFalse( \Helper_Functions::remove_local_directory( '/' ) );
- }
-
- public function testRemoveLocalDirectoryDirParamEmpty()
- {
- $this->assertFalse( \Helper_Functions::remove_local_directory( '' ) );
- }
-
- public function testRemoveLocalDirectoryDirNonexistent()
- {
- $this->assertFalse( \Helper_Functions::remove_local_directory( $this->_base_dir_path . '/bar' ) );
- }
-
- public function testDeleteLocalFileExceptionMessage()
- {
- @\Helper_Functions::delete_local_file( $this->_base_dir_path . '/index.php' );
- $error = error_get_last();
-
- $this->assertEquals( 'DEPRECATED: The function delete_local_file is deprecated. Please use PHP unlink instead.', $error['message'] );
- }
-
- public function testDeleteLocalFile()
- {
- $handle = fopen( $this->_base_dir_path .'/index.php', 'w' );
- fwrite( $handle, '' );
- fclose( $handle );
-
- @\Helper_Functions::delete_local_file( $this->_base_dir_path . '/index.php' );
- $this->assertFalse( file_exists( $this->_base_dir_path . '/index.php' ) );
- }
-
- public function testSanitizeTextFieldArray()
- {
- $array = array(
- 'foo' => '~!@#$%^&*()_+`1234567890-=:;"<>?,./[]\{}|',
- 'bar' => 'cool'
- );
- $this->assertEquals(
- array(
- 'foo' => '~!@#$%^&*()_+`1234567890-=:;"?,./[]\{}|',
- 'bar' => 'cool'
- ),
- \Helper_Functions::sanitize_text_field_array( $array )
- );
- }
-
- /**
- * Test the deprecated() error message
- *
- * @since 0.1
- */
- public function testDeprecatedExceptionMessage()
- {
- //the @ symbol supresses the expected error
- @\Helper_Functions::deprecated( 'foo', 'bar', 'my-super-cool-text-domain' );
-
- $error = error_get_last();
- $this->assertEquals( 'DEPRECATED: The function foo is deprecated. Please use bar instead.', $error['message'] );
- }
-
- /*
-public function testEnqueueScripts()
- {
- require_once( WPMVCB_SRC_DIR . '/models/class-base-model-js-object.php' );
- $scripts = array(
- new \Base_Model_JS_Object( 'foo', 'http://example.com/foo.js', null, false, false )
- );
-
- global $wp_scripts;
-
- \Helper_Functions::enqueue_scripts( $scripts );
- do_action( 'wp_enqueue_scripts' );
- $this->assertArrayHasKey( 'foo', $wp_scripts->registered );
- }
-
- public function testEnqueueStyles()
- {
- $styles = array(
- array(
- 'handle'=> 'bar',
- 'src' => 'http://example.com/bar.css',
- 'deps' => null,
- 'ver' => false,
- 'media' => 'all'
- ),
- array( 'handle' => 'thickbox' )
- );
-
- global $wp_styles;
- \Helper_Functions::enqueue_styles( $styles );
- do_action( 'wp_enqueue_scripts' );
- $this->assertArrayHasKey( 'bar', $wp_styles->registered );
- }
-*/
- }
-}
diff --git a/tests/unit-tests/test_base_helpers_render_fields.php b/tests/unit-tests/test_base_helpers_render_fields.php
deleted file mode 100644
index 8fb75c8..0000000
--- a/tests/unit-tests/test_base_helpers_render_fields.php
+++ /dev/null
@@ -1,139 +0,0 @@
-_mock_path = trailingslashit( \org\bovigo\vfs\vfsStream::url( 'test_dir' ) );
- $this->_filesystem = \org\bovigo\vfs\vfsStreamWrapper::getRoot();
- }
-
- public function testMethodRenderInputExists()
- {
- $this->assertTrue( method_exists( '\Base_Helpers_Render_Fields', 'render_input_text' ), 'Method does not exist' );
- }
-
- /**
- * @depends testMethodRenderInputExists
- */
- public function testMethodRenderInputText()
- {
- $expected = 'bar';
-
- $this->assertEquals(
- $expected,
- \Base_Helpers_Render_Fields::render_input_text( 'my-input', 'my_input', 'foo', 'Enter some value', 'bar' )
- );
- }
-
- /**
- * @depends testMethodRenderInputExists
- */
- public function testMethodRenderInputTextFileAfter()
- {
- $handle = fopen( $this->_mock_path . '/view.php', 'w' );
- fwrite( $handle, 'foo = bar' );
- fclose( $handle );
-
- $this->assertTrue( $this->_filesystem->hasChild( 'view.php' ) );
-
- $expected = 'foo = bar';
-
- $this->assertEquals(
- $expected,
- \Base_Helpers_Render_Fields::render_input_text( 'my-input', 'my_input', 'foo', 'Enter some value', $this->_mock_path . '/view.php' )
- );
- }
-
- public function testMethodRenderInputCheckboxExists()
- {
- $this->assertTrue( method_exists( '\Base_Helpers_Render_Fields', 'render_input_checkbox' ) );
- }
-
- /**
- * @depends testMethodRenderInputCheckboxExists
- */
- public function testMethodRenderInputCheckbox()
- {
- $expected = '';
-
- $this->assertEquals( $expected, \Base_Helpers_Render_Fields::render_input_checkbox( 'my-checkbox', 'my_checkbox', 0 ) );
- }
-
- /**
- * @depends testMethodRenderInputCheckboxExists
- */
- public function testMethodRenderInputCheckboxChecked()
- {
- $expected = '';
-
- $this->assertEquals( $expected, \Base_Helpers_Render_Fields::render_input_checkbox( 'my-checkbox', 'my_checkbox', 1 ) );
- }
-
- public function testMethodRenderInputSelectExists()
- {
- $this->assertTrue( method_exists( '\Base_Helpers_Render_Fields', 'render_input_select' ) );
- }
-
- /**
- * @depends testMethodRenderInputSelectExists
- */
- public function testMethodRenderInputSelect()
- {
- $expected = '';
-
- $this->assertEquals(
- $expected,
- \Base_Helpers_Render_Fields::render_input_select(
- 'my-select',
- 'my_select',
- array( 'my_option' => 'My Option' ),
- null
- )
- );
- }
-
- /**
- * @depends testMethodRenderInputSelectExists
- */
- public function testMethodRenderInputSelectSelected()
- {
- $expected = '';
-
- $this->assertEquals(
- $expected,
- \Base_Helpers_Render_Fields::render_input_select(
- 'my-select',
- 'my_select',
- array( 'my_option' => 'My Option' ),
- 'my_option'
- )
- );
- }
-
- public function testMethodRenderTextarea()
- {
- $field = array(
- 'type' => 'textarea',
- 'id' => 'my-textarea',
- 'name' => 'my_textarea',
- 'value' => 'My textarea content'
- );
- $this->assertTrue( method_exists( '\Base_Helpers_Render_Fields', 'render_input_textarea' ) );
- $expected = '';
-
- $this->assertEquals(
- $expected,
- \Base_Helpers_Render_Fields::render_input_textarea( 'my-textarea', 'my_textarea', 'My textarea content' )
- );
- }
- }
-}
diff --git a/tests/unit-tests/test_base_model.php b/tests/unit-tests/test_base_model.php
deleted file mode 100644
index 9695539..0000000
--- a/tests/unit-tests/test_base_model.php
+++ /dev/null
@@ -1,512 +0,0 @@
-model = new Stub_Base_Model( $args );
-
- }
-
- public function tearDown() {
-
- unset( $this->model );
-
- }
-
- /**
- * @covers ::get_css
- */
- public function testMethodGetCss() {
-
- $this->assertClassHasAttribute( 'css', 'WPMVCB_Model_Base' );
- $this->assertTrue( method_exists( $this->model, 'get_css' ) );
- $this->setReflectionPropertyValue( $this->model, 'css', array( 'foo_css' => array( 'handle' => 'bar_css' ) ) );
-
- $this->assertEquals(
- array( 'foo_css' => array( 'handle' => 'bar_css' ) ),
- $this->model->get_css( 'http://my-super-cool-site' )
- );
-
- }
-
- /**
- * @covers ::get_css
- */
- public function testMethodGetCssEmpty() {
-
- $this->assertTrue( method_exists( $this->model, 'get_css' ) );
- $this->assertEmpty( $this->model->get_css() );
-
- }
-
- /**
- * @covers ::get_admin_css
- */
- public function testMethodGetAdminCss() {
-
- $this->assertClassHasAttribute( 'admin_css', 'WPMVCB_Model_Base' );
- $this->assertTrue( method_exists( $this->model, 'get_admin_css' ) );
- $this->setReflectionPropertyValue( $this->model, 'admin_css', array( 'foo_admin_css' => array( 'handle' => 'bar_admin_css' ) ) );
- $this->assertEquals(
- array( 'foo_admin_css' => array( 'handle' => 'bar_admin_css' ) ),
- $this->model->get_admin_css( 'http://my-super-cool-site' )
- );
- }
-
- /**
- * @covers ::get_admin_css
- */
- public function testMethodGetAdminCssEmpty() {
-
- $this->assertTrue( method_exists( $this->model, 'get_admin_css' ) );
- $this->assertEmpty( $this->model->get_admin_css() );
-
- }
-
- /**
- * @covers ::get_scripts
- */
- public function testMethodGetScripts() {
-
- $this->assertClassHasAttribute( 'scripts', 'WPMVCB_Model_Base' );
- $this->assertTrue( method_exists( $this->model, 'get_scripts' ) );
- //global $post;
-
- $this->setReflectionPropertyValue( $this->model, 'scripts', array ( 'foo_scripts' => 'bar_scripts' ) );
- $this->assertEquals(
- array ( 'foo_scripts' => 'bar_scripts' ),
- $this->model->get_scripts()
- );
-
- }
-
- /**
- * @covers ::get_scripts
- */
- public function testMethodGetScriptsEmpty() {
-
- $this->assertTrue( method_exists( $this->model, 'get_scripts' ) );
- $this->assertEmpty( $this->model->get_scripts() );
-
- }
-
- /**
- * @covers ::get_admin_scripts
- */
- public function testMethodGetAdminScripts() {
-
- $this->assertClassHasAttribute( 'admin_scripts', 'WPMVCB_Model_Base' );
- $this->assertTrue( method_exists( $this->model, 'get_admin_scripts' ) );
-
- //global $post;
- $this->setReflectionPropertyValue( $this->model, 'admin_scripts', array( 'foo_admin_scripts' => 'bar_admin_scripts' ) );
- $this->assertEquals(
- array( 'foo_admin_scripts' => 'bar_admin_scripts' ),
- $this->model->get_admin_scripts()
- );
-
- }
-
- /**
- * @covers ::get_admin_scripts
- */
- public function testMethodGetAdminScriptsEmpty() {
-
- $this->assertTrue( method_exists( $this->model, 'get_admin_scripts' ) );
- $this->assertEmpty( $this->model->get_admin_scripts() );
-
- }
-
- /**
- * @covers ::get_metaboxes
- */
- public function testMethodGetMetaboxes() {
-
- $this->assertClassHasAttribute( 'metaboxes', 'WPMVCB_Model_Base' );
- $this->assertTrue( method_exists( $this->model, 'get_metaboxes' ) );
-
- $stub = $this->getMockBuilder( 'WPMVCB_Model_Base_Metabox' )
- ->disableOriginalConstructor()
- ->getMock();
- $this->setReflectionPropertyValue( $this->model, 'metaboxes', array( 'foo' => $stub ) );
-
- $this->assertEquals( array( 'foo' => $stub ), $this->model->get_metaboxes( 'bar', 'baz') );
-
- }
-
- /**
- * @covers ::get_metaboxes
- */
- public function testMethodGetmetaboxesEmpty() {
-
- $this->assertTrue( method_exists( $this->model, 'get_metaboxes' ) );
- $this->assertEmpty( $this->model->get_metaboxes() );
-
- }
-
- /**
- * @covers ::add_help_tab
- */
- public function testMethodAddHelpTab() {
-
- $this->assertClassHasAttribute( 'help_tabs', 'WPMVCB_Model_Base' );
- $this->assertTrue( method_exists( $this->model, 'add_help_tab' ) );
- //set up our mock help tab object
- $stub = $this->getMockBuilder( 'Base_Model_Help_Tab' )
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->model->add_help_tab( 'foo', $stub );
-
- $this->assertEquals(
- array( 'foo' => $stub ),
- $this->getReflectionPropertyValue( $this->model, 'help_tabs' ),
- 'Help tab not properly set'
- );
-
- }
-
- /**
- * Pass an object not of type WPMVCB_Model_Base_Help_Tab. Verify WP_Error object is returned
- * and that error object data equals the passed in tab object
- *
- * @covers ::add_help_tab
- */
- public function testMethodAddHelpTabFail() {
-
- $this->assertTrue( method_exists( $this->model, 'add_help_tab' ) );
-
- $tab = new \StdClass;
-
- $result = $this->model->add_help_tab( 'foo', $tab );
-
- $this->assertInstanceOf( 'WP_Error', $result );
- $this->assertEquals( $tab, $result->get_error_data() );
-
- }
-
- /**
- * @covers ::get_help_tabs
- */
- public function testMethodGetHelpTabs() {
-
- $this->assertTrue( method_exists( $this->model, 'get_help_tabs' ) );
-
- $this->setReflectionPropertyValue( $this->model, 'help_tabs', array( 'foo' => 1 , 'bar' => 2 ) );
-
- $this->assertEquals(
- array( 'foo' => 1, 'bar' => 2 ),
- $this->model->get_help_tabs()
- );
-
- }
-
- /**
- * @covers ::get_help_tabs
- */
- public function testMethodGetHelpTabsEmpty() {
-
- $this->assertTrue( method_exists( $this->model, 'get_help_tabs' ) );
- $this->assertEmpty( $this->model->get_help_tabs() );
-
- }
-
- /**
- * @covers ::add_shortcode
- */
- public function testMethodAddShortcode() {
-
- $this->assertClassHasAttribute( 'shortcodes', 'WPMVCB_Model_Base' );
- $this->assertTrue( method_exists( $this->model, 'add_shortcode' ) );
-
- $this->assertTrue( $this->model->add_shortcode( 'foo', array( &$this, 'testMethodGetHelpTabs' ) ) );
-
- }
-
- /**
- * @covers ::add_shortcode
- */
- public function testMethodAddShortcodeFail() {
-
- $this->assertTrue( method_exists( $this->model, 'add_shortcode' ) );
-
- $result = $this->model->add_shortcode( 'fooshortcode', 'foocallback' );
-
- $this->assertInstanceOf( 'WP_Error', $result );
- $this->assertEquals( 'foocallback', $result->get_error_data() );
-
- }
-
- /**
- * @covers ::get_shortcodes
- */
- public function testMethodGetShortcodes() {
-
- $this->assertTrue( method_exists( $this->model, 'get_shortcodes' ) );
- $this->setReflectionPropertyValue(
- $this->model,
- 'shortcodes',
- array('fooshortcode' => array( &$this, 'testMethodAddShortcode' ) )
- );
-
- $this->assertEquals( array( 'fooshortcode' => array( &$this, 'testMethodAddShortcode' ) ), $this->model->get_shortcodes() );
-
- }
-
- /**
- * @covers ::get_shortcodes
- */
- public function testMethodGetShortcodesEmpty() {
-
- $this->assertTrue( method_exists( $this->model, 'get_shortcodes' ) );
- $this->assertEmpty( $this->model->get_shortcodes() );
-
- }
-
- /**
- * @covers ::authenticate_post
- */
- public function testMethodAuthenticatePostForPost() {
-
- $this->assertTrue( method_exists( $this->model, 'authenticate_post' ) );
- $factory = new \WP_UnitTest_Factory;
-
- $post_id = $factory->post->create_object(
- array(
- 'post_title' => 'Test Post',
- 'post_type' => 'post',
- 'post_status' => 'publish'
- )
- );
-
- wp_set_current_user( 1 );
-
- $this->assertTrue(
- $this->model->authenticate_post(
- $post_id,
- 'post',
- array( 'foo_name' => wp_create_nonce( 'foo_action' ) ),
- 'foo_name',
- 'foo_action'
- )
- );
-
- }
-
- /**
- * @covers ::authenticate_post
- */
- public function testMethodAuthenticatePostForPage() {
-
- $this->assertTrue( method_exists( $this->model, 'authenticate_post' ) );
- $factory = new \WP_UnitTest_Factory;
-
- $post_id = $factory->post->create_object(
- array(
- 'post_title' => 'Test Post',
- 'post_type' => 'page',
- 'post_status' => 'publish'
- )
- );
-
- wp_set_current_user( 1 );
-
- $this->assertTrue(
- $this->model->authenticate_post(
- $post_id,
- 'page',
- array( 'foo_name' => wp_create_nonce( 'foo_action' ) ),
- 'foo_name',
- 'foo_action'
- )
- );
-
- }
-
- /**
- * @covers ::authenticate_post
- */
- public function testMethodAuthenticatePostUserCannotEditPage() {
-
- $this->assertTrue( method_exists( $this->model, 'authenticate_post' ) );
- $factory = new \WP_UnitTest_Factory;
-
- $post_id = $factory->post->create_object(
- array(
- 'post_title' => 'Test Post',
- 'post_type' => 'page',
- 'post_status' => 'publish'
- )
- );
-
- wp_set_current_user( 0 );
-
- $this->assertEmpty(
- $this->model->authenticate_post(
- $post_id,
- 'page',
- array( 'foo_name' => wp_create_nonce( 'foo_action' ) ),
- 'foo_name',
- 'foo_action'
- )
- );
-
- }
-
- /**
- * @covers ::authenticate_post
- */
- public function testMethodAuthenticatePostUserCannotEditPost() {
-
- $this->assertTrue( method_exists( $this->model, 'authenticate_post' ) );
- $factory = new \WP_UnitTest_Factory;
-
- $post_id = $factory->post->create_object(
- array(
- 'post_title' => 'Test Post',
- 'post_type' => 'post',
- 'post_status' => 'publish'
- )
- );
-
- wp_set_current_user( 0 );
-
- $this->assertEmpty(
- $this->model->authenticate_post(
- $post_id,
- 'post',
- array( 'foo_name' => wp_create_nonce( 'foo_action' ) ),
- 'foo_name',
- 'foo_action'
- )
- );
-
- }
-
- /**
- * @covers ::authenticate_post
- */
- public function testMethodAuthenticatePostNoNonce() {
-
- $this->assertTrue( method_exists( $this->model, 'authenticate_post' ) );
-
- $post_id = $this->factory->post->create(
- array(
- 'post_title' => 'Test Post',
- 'post_type' => 'page',
- 'post_status' => 'publish'
- )
- );
-
- wp_set_current_user( 1 );
-
- $this->assertEmpty(
- $this->model->authenticate_post(
- $post_id,
- 'page',
- array(),
- 'foo_name',
- 'foo_action'
- )
- );
-
- }
-
- /**
- * @covers ::authenticate_post
- */
- public function testMethodAuthenticatePostDoingAutosave() {
-
- $this->assertTrue( method_exists( $this->model, 'authenticate_post' ) );
-
- $post_id = $this->factory->post->create(
- array(
- 'post_title' => 'Test Post',
- 'post_type' => 'page',
- 'post_status' => 'publish'
- )
- );
-
- define( 'DOING_AUTOSAVE', true );
-
- $this->assertEmpty(
- $this->model->authenticate_post(
- $post_id,
- 'page',
- array( 'foo_name' => wp_create_nonce( 'foo_action' ) ),
- 'foo_name',
- 'foo_action'
- )
- );
-
- }
-
- /**
- * @covers ::get_admin_notices
- */
- public function testMethodGetAdminNotices() {
-
- $this->setReflectionPropertyValue( $this->model, 'admin_notices', array( 'foo', 'bar' ) );
-
- $this->assertTrue( method_exists( 'WPMVCB_Model_Base', 'get_admin_notices' ) );
- $this->assertEquals( array( 'foo', 'bar' ), $this->model->get_admin_notices() );
-
- }
-
- /**
- * @covers ::get_admin_notices
- */
- public function testMethodGetAdminNoticesEmpty() {
-
- $this->assertTrue( method_exists( 'WPMVCB_Model_Base', 'get_admin_notices' ), 'Method get_admin_notices does not exist' );
- $this->assertEmpty( $this->model->get_admin_notices() );
-
- }
-
- }
-
- class Stub_Base_Model extends WPMVCB_Model_Base {
-
- protected function init() {
-
- //implemented, but does nothing
-
- }
-
- }
-
-}
diff --git a/tests/unit-tests/test_base_model_help_tab.php b/tests/unit-tests/test_base_model_help_tab.php
deleted file mode 100644
index 23e3fdf..0000000
--- a/tests/unit-tests/test_base_model_help_tab.php
+++ /dev/null
@@ -1,85 +0,0 @@
-tab = new \Base_Model_Help_Tab(
- 'test-tab',
- 'My Test Tab',
- array( 'load-post-new.php' ),
- array( 'post' ),
- 'Here is some test tab content'
- );
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testPagesNotArray()
- {
- $tab = new \Base_Model_Help_Tab( 'Empty Tab', 'empty-tab', 'foo.php' );
- }
-
- public function testAttributeIdExists()
- {
- $this->assertClassHasAttribute( 'id', 'Base_Model_Help_Tab' );
- }
-
- public function testAttributeTitleExists()
- {
- $this->assertClassHasAttribute( 'title', 'Base_Model_Help_Tab' );
- }
-
- public function testAttributeScreensExists()
- {
- $this->assertClassHasAttribute( 'screens', 'Base_Model_Help_Tab' );
- }
-
- public function testAttributePostTypesExists()
- {
- $this->assertClassHasAttribute( 'post_types', 'Base_Model_Help_Tab' );
- }
-
- public function testAttributeContentExists()
- {
- $this->assertClassHasAttribute( 'content', 'Base_Model_Help_Tab' );
- }
-
- public function testMethodGetId()
- {
- $this->assertTrue( method_exists( 'Base_Model_Help_Tab', 'get_id' ) );
- $this->assertEquals( 'test-tab', $this->tab->get_id() );
- }
-
- public function testMethodGetTitle()
- {
- $this->assertTrue( method_exists( 'Base_Model_Help_Tab', 'get_title' ) );
- $this->assertEquals( 'My Test Tab', $this->tab->get_title() );
- }
-
- public function testMethodGetScreens()
- {
- $this->assertTrue( method_exists( 'Base_Model_Help_Tab', 'get_screens' ) );
- $this->assertEquals( array( 'load-post-new.php' ), $this->tab->get_screens() );
- }
-
- public function testMethodGetPostTypes()
- {
- $this->assertTrue( method_exists( 'Base_Model_Help_Tab', 'get_post_types' ) );
- $this->assertEquals( array( 'post' ), $this->tab->get_post_types() );
- }
-
- public function testMethodGetContent()
- {
- $this->assertTrue( method_exists( 'Base_Model_Help_Tab', 'get_content' ) );
- $this->assertEquals( 'Here is some test tab content', $this->tab->get_content() );
- }
- }
-}
\ No newline at end of file
diff --git a/tests/unit-tests/test_base_model_js_object.php b/tests/unit-tests/test_base_model_js_object.php
deleted file mode 100644
index a4f7f55..0000000
--- a/tests/unit-tests/test_base_model_js_object.php
+++ /dev/null
@@ -1,336 +0,0 @@
-script = new Base_Model_JS_Object(
- 'my-super-cool-script',
- 'http://my-super-cool-site.com/wp-content/plugins/js/my-super-cool-script.js',
- array(
- 'deps' => array( 'jquery', 'my-super-cool-framework' ),
- 'version' => true,
- 'in_footer' => true,
- 'localization_var' => 'mySuperCoolL10n',
- 'localization_args' => array( 'foo' => 'bar' ),
- )
- );
- }
-
- public function tearDown()
- {
- wp_deregister_script( 'my-super-cool-script' );
- unset( $this->script );
- }
-
- /**
- * @covers Base_Model_JS_Object::__construct
- */
- public function testPropertyHandle()
- {
- $this->assertClassHasAttribute( 'handle', '\Base_Model_JS_Object' );
- $this->assertSame( 'my-super-cool-script', $this->getReflectionPropertyValue( $this->script, 'handle' ) );
- }
-
- /**
- * @covers Base_Model_JS_Object::__construct
- */
- public function testPropertySrc()
- {
- $this->assertClassHasAttribute( 'src', '\Base_Model_JS_Object' );
- $this->assertSame(
- 'http://my-super-cool-site.com/wp-content/plugins/js/my-super-cool-script.js',
- $this->getReflectionPropertyValue( $this->script, 'src' )
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::__construct
- */
- public function testPropertyDeps()
- {
- $this->assertClassHasAttribute( 'deps', '\Base_Model_JS_Object' );
- $this->assertSame(
- array( 'jquery', 'my-super-cool-framework' ),
- $this->getReflectionPropertyValue( $this->script, 'deps' )
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::__construct
- */
- public function testPropertyVer()
- {
- $this->assertClassHasAttribute( 'version', '\Base_Model_JS_Object' );
- $this->assertSame(
- true,
- $this->getReflectionPropertyValue( $this->script, 'version' )
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::__construct
- */
- public function testPropertyInFooter()
- {
- $this->assertClassHasAttribute( 'in_footer', '\Base_Model_JS_Object' );
- $this->assertSame(
- true,
- $this->getReflectionPropertyValue( $this->script, 'in_footer' )
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::__construct
- */
- public function testPropertyLocalizationVar()
- {
- $this->assertClassHasAttribute( 'localization_var', '\Base_Model_JS_Object' );
- $this->assertSame(
- 'mySuperCoolL10n',
- $this->getReflectionPropertyValue( $this->script, 'localization_var' )
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::__construct
- */
- public function testPropertyLocalizationArgs()
- {
- $this->assertClassHasAttribute( 'localization_args', '\Base_Model_JS_Object' );
- $this->assertSame(
- array( 'foo' => 'bar' ),
- $this->getReflectionPropertyValue( $this->script, 'localization_args' )
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::register
- */
- public function testMethodRegister()
- {
- global $wp_scripts;
-
- $this->assertTrue( method_exists( 'Base_Model_JS_Object', 'register' ), 'Method register does not exist' );
- $this->script->register();
- $this->assertTrue( wp_script_is( 'my-super-cool-script', 'registered' ) );
- $this->assertEquals(
- 'my-super-cool-script',
- $wp_scripts->registered['my-super-cool-script']->handle,
- 'Handle incorrectly registered'
- );
- $this->assertEquals(
- 'http://my-super-cool-site.com/wp-content/plugins/js/my-super-cool-script.js',
- $wp_scripts->registered['my-super-cool-script']->src,
- 'Source incorrectly registered'
- );
- $this->assertEquals(
- array( 'jquery', 'my-super-cool-framework' ),
- $wp_scripts->registered['my-super-cool-script']->deps,
- 'Dependencies incorrectly registered'
- );
- $this->assertEquals(
- true,
- $wp_scripts->registered['my-super-cool-script']->ver,
- 'Version incorrectly registered'
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::enqueue
- */
- public function testMethodEnqueue()
- {
- $this->assertTrue( method_exists( 'Base_Model_JS_Object', 'enqueue' ) );
- $this->script->enqueue();
- $this->assertTrue( wp_script_is( 'my-super-cool-script', 'enqueued' ) );
- }
-
- /**
- * @covers Base_Model_JS_Object::localize
- */
- public function testMethodLocalize()
- {
- global $wp_scripts;
-
- $this->assertTrue( method_exists( 'Base_Model_JS_Object', 'localize' ) );
-
- wp_register_script(
- 'my-super-cool-script',
- 'http://my-super-cool-site.com/wp-content/plugins/js/my-super-cool-script.js',
- array( 'jquery', 'my-super-cool-framework' ),
- true,
- true
- );
-
- $this->script->localize();
-
- $script = $wp_scripts->query( 'my-super-cool-script' );
- $this->assertEquals( 'var mySuperCoolL10n = {"foo":"bar"};', $script->extra['data'] );
- }
-
- /**
- * @covers Base_Model_JS_Object::localize
- */
- public function testLocalizeEmpty()
- {
- $this->assertTrue( method_exists( 'Base_Model_JS_Object', 'localize' ) );
-
- $baz = new \Base_Model_JS_Object( 'baz', 'http://example.com/baz.js' );
-
- wp_register_script( 'baz', 'http://example.com/baz.js', null, false, false );
- $this->assertFalse( $baz->localize() );
- }
-
- /**
- * @covers Base_Model_JS_Object::dequeue
- */
- public function test_dequeue()
- {
- $this->assertTrue( method_exists( 'Base_Model_JS_Object', 'dequeue' ), 'Method dequeue does not exist' );
- wp_enqueue_script(
- 'my-super-cool-script',
- 'http://my-super-cool-site.com/wp-content/plugins/js/my-super-cool-script.js',
- array( 'jquery', 'my-super-cool-framework' ),
- true,
- true
- );
-
- $this->assertTrue( wp_script_is( 'my-super-cool-script', 'enqueued', 'Script not dequeued' ) );
- $this->script->dequeue();
- $this->assertFalse( wp_script_is( 'my-super-cool-script', 'enqueued', 'Script not dequeued' ) );
- }
-
- /**
- * @covers Base_Model_JS_Object::deregister
- */
- public function test_deregister()
- {
- $this->assertTrue( method_exists( 'Base_Model_JS_Object', 'deregister' ), 'Method deregister does not exist' );
- wp_register_script(
- 'my-super-cool-script',
- 'http://my-super-cool-site.com/wp-content/plugins/js/my-super-cool-script.js',
- array( 'jquery', 'my-super-cool-framework' ),
- true,
- true
- );
- $this->assertTrue( wp_script_is( 'my-super-cool-script', 'registered' ), 'Script not registered' );
- $this->script->deregister();
- $this->assertFalse( wp_script_is( 'my-super-cool-script', 'registered' ), 'Script not deregistered' );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_handle
- */
- public function testMethodGetHandle()
- {
- $this->assertTrue( method_exists( $this->script, 'get_handle' ) );
- $this->assertEquals( 'my-super-cool-script', $this->script->get_handle() );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_src
- */
- public function testMethodGetSrc()
- {
- $this->assertTrue( method_exists( $this->script, 'get_src' ) );
- $this->assertEquals(
- 'http://my-super-cool-site.com/wp-content/plugins/js/my-super-cool-script.js',
- $this->script->get_src()
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_deps
- */
- public function testMethodGetDeps()
- {
- $this->assertTrue( method_exists( $this->script, 'get_deps' ) );
- $this->assertEquals( array( 'jquery', 'my-super-cool-framework' ), $this->script->get_deps()
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_version
- */
- public function testMethodGetVersion()
- {
- $this->assertTrue( method_exists( $this->script, 'get_version' ) );
- $this->assertEquals( true, $this->script->get_version()
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_in_footer
- */
- public function testMethodGetInFooter()
- {
- $this->assertTrue( method_exists( $this->script, 'get_in_footer' ) );
- $this->assertEquals( true, $this->script->get_in_footer()
- );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_localization_var
- */
- public function testMethodGetLocalizationVar()
- {
- $this->assertTrue( method_exists( $this->script, 'get_localization_var' ) );
- $this->assertEquals( 'mySuperCoolL10n', $this->script->get_localization_var() );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_localization_var
- */
- public function testMethodGetLocalizationVarEmpty()
- {
- $this->assertTrue( method_exists( $this->script, 'get_localization_var' ) );
-
- //ensure the property is empty
- $this->setReflectionPropertyValue( $this->script, 'localization_var', null );
-
- $this->assertFalse( $this->script->get_localization_var() );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_localization_args
- */
- public function testMethodGetLocalizationArgs()
- {
- $this->assertTrue( method_exists( $this->script, 'get_localization_args' ) );
- $this->assertEquals( array( 'foo' => 'bar' ), $this->script->get_localization_args() );
- }
-
- /**
- * @covers Base_Model_JS_Object::get_localization_args
- */
- public function testMethodGetLocalizationArgsEmpty()
- {
- $this->assertTrue( method_exists( $this->script, 'get_localization_args' ) );
-
- //ensure the property is empty
- $this->setReflectionPropertyValue( $this->script, 'localization_args', null );
-
- $this->assertFalse( $this->script->get_localization_args() );
- }
- }
-}
-?>
\ No newline at end of file
diff --git a/tests/unit-tests/test_base_model_metabox.php b/tests/unit-tests/test_base_model_metabox.php
deleted file mode 100644
index fc0dbcb..0000000
--- a/tests/unit-tests/test_base_model_metabox.php
+++ /dev/null
@@ -1,266 +0,0 @@
-metabox = new WPMVCB_Metabox_Model_Base( array(
- 'id' => 'my-super-cool-metabox',
- 'title' => 'My Super Cool Metabox',
- 'callback' => 'my_super_cool_callback',
- 'post_types' => array( 'my_super_cool_posttype' ),
- 'context' => 'normal',
- 'priority' => 'default',
- 'callback_args' => array( 'foo' => 'bar' )
- ) );
- }
-
- /**
- * @depends testMethodAdd
- * @covers ::remove
- */
- // public function testMethodRemove()
- // {
- // global $wp_meta_boxes;
-
- // $this->assertTrue( method_exists( $this->metabox, 'remove' ), 'Method does not exist' );
-
- // $this->metabox->add();
- // $this->assertMetaboxExists(
- // array(
- // 'my-super-cool-metabox',
- // 'My Super Cool Metabox',
- // 'my_super_cool_callback',
- // 'my_super_cool_posttype',
- // 'normal',
- // 'default',
- // array( 'foo' => 'bar' )
- // )
- // );
-
- // $this->metabox->remove();
-
- // $this->assertFalse( is_array( $wp_meta_boxes['my_super_cool_posttype']['normal']['default']['my-super-cool-metabox'] ), 'Metabox not removed' );
- // }
-
- /**
- * @covers ::get_id
- */
- public function testMethodGetId()
- {
- $this->assertTrue( method_exists( $this->metabox, 'get_id' ), 'Method does not exist' );
- $this->assertEquals( 'my-super-cool-metabox', $this->metabox->get_id(), 'ID Incorrect' );
- }
-
- /**
- * @covers ::get_title
- */
- public function testMethodGetTitle()
- {
- $this->assertTrue( method_exists( $this->metabox, 'get_title' ), 'Method does not exist' );
- $this->assertEquals( 'My Super Cool Metabox', $this->metabox->get_title(), 'Title Incorrect' );
- }
-
- /**
- * @covers ::get_callback
- */
- public function testMethodGetCallback()
- {
- $this->assertTrue( method_exists( $this->metabox, 'get_callback' ), 'Method does not exist' );
- $this->assertEquals( 'my_super_cool_callback', $this->metabox->get_callback() );
- }
-
- /**
- * @covers ::get_post_types
- */
- public function testMethodGetPostTypes()
- {
- $this->assertTrue( method_exists( $this->metabox, 'get_post_types' ), 'Method does not exist' );
- $this->assertEquals( array( 'my_super_cool_posttype' ), $this->metabox->get_post_types() );
- }
-
- /**
- * @covers ::get_context
- */
- public function testMethodGetContext()
- {
- $this->assertTrue( method_exists( $this->metabox, 'get_context' ), 'Method does not exist' );
- $this->assertEquals( 'normal', $this->metabox->get_context() );
- }
-
- /**
- * @covers ::get_priority
- */
- public function testMethodGetPriority()
- {
- $this->assertTrue( method_exists( $this->metabox, 'get_priority' ), 'Method does not exist' );
- $this->assertEquals( 'default', $this->metabox->get_priority() );
- }
-
- /**
- * @covers ::get_callback_args
- */
- public function testMethodGetCallbackArgs()
- {
- $post = $this->factory->post->create();
-
- $this->assertTrue( method_exists( $this->metabox, 'get_callback_args' ), 'Method does not exist' );
- $this->assertEquals( array( 'foo' => 'bar' ), $this->metabox->get_callback_args( $post ) );
- }
-
- /**
- * @depends testMethodGetId
- * @covers ::set_id
- */
- public function testMethodSetId()
- {
- $this->assertTrue( method_exists( $this->metabox, 'set_id' ), 'Method does not exist' );
- $this->metabox->set_id( 'flibbertygibbet' );
- $this->assertEquals( 'flibbertygibbet', $this->metabox->get_id() );
- }
-
- /**
- * @depends testMethodGetTitle
- * @covers ::set_title
- */
- public function testMethodSetTitle()
- {
- $this->assertTrue( method_exists( $this->metabox, 'set_title' ), 'Method does not exist' );
- $this->metabox->set_title( 'flibbertygibbet' );
- $this->assertEquals( 'flibbertygibbet', $this->metabox->get_title() );
- }
-
- /**
- * @depends testMethodGetCallback
- * @covers ::set_callback
- */
- public function testMethodSetCallback()
- {
- $this->assertTrue( method_exists( $this->metabox, 'set_callback' ), 'Method does not exist' );
- $this->metabox->set_callback( 'flibbertygibbet' );
- $this->assertEquals( 'flibbertygibbet', $this->metabox->get_callback() );
- }
-
- /**
- * @depends testMethodGetPostTypes
- * @covers ::set_post_type
- */
- public function testMethodSetPostTypes()
- {
- $this->assertTrue( method_exists( $this->metabox, 'set_post_type' ), 'Method does not exist' );
- $this->metabox->set_post_type( array( 'flibbertygibbet' ) );
- $this->assertEquals( array( 'flibbertygibbet' ), $this->metabox->get_post_types() );
- }
-
- /**
- * @depends testMethodGetContext
- * @covers ::set_context
- */
- public function testMethodSetContext()
- {
- $this->assertTrue( method_exists( $this->metabox, 'set_context' ), 'Method does not exist' );
- $this->metabox->set_context( 'side' );
- $this->assertEquals( 'side', $this->metabox->get_context() );
- }
-
- /**
- * @depends testMethodGetPriority
- * @covers ::set_priority
- */
- public function testMethodSetPriority()
- {
- $this->assertTrue( method_exists( $this->metabox, 'set_priority' ), 'Method does not exist' );
- $this->metabox->set_priority( 'low' );
- $this->assertEquals( 'low', $this->metabox->get_priority() );
- }
-
- /**
- * @depends testMethodGetCallbackArgs
- * @covers ::set_callback_args
- */
- public function testMethodSetCallbackArgs()
- {
- $post = $this->factory->post->create();
-
- $this->assertTrue( method_exists( $this->metabox, 'set_callback_args' ), 'Method does not exist' );
- $this->metabox->set_callback_args( array( 'flibbertygibbet' => 'mtzlplck' ) );
- $this->assertEquals( array( 'flibbertygibbet' => 'mtzlplck' ), $this->metabox->get_callback_args( $post ) );
- }
-
- /**
- * @covers ::default_callback()
- */
- public function testDefaultCallback()
- {
- ob_start();
- $this->metabox->default_callback();
- $result = ob_get_clean();
-
- $this->assertInternalType( 'string', $result );
- }
-
- /**
- * Test faulty metabox context assignment.
- *
- * This function tests the metabox object's setting the context to 'normal' when
- * passed a value other than 'normal', 'advanced', or 'side'.
- *
- * @depends testMethodGetContext
- * @covers ::__construct
- * @since 0.1
- */
- public function testInvalidContext()
- {
- $metabox = new WPMVCB_Metabox_Model_Base( array(
- 'id' => 'my-super-cool-metabox',
- 'title' => 'My Super Cool Metabox',
- 'callback' => 'my_super_cool_callback',
- 'post_types' => array( 'my_super_cool_posttype' ),
- 'context' => 'flibbertygibbet',
- 'priority' => 'default',
- 'callback_args' => array( 'foo' => 'bar' )
- ) );
-
- $this->assertEquals( 'normal', $metabox->get_context() );
- }
-
- /**
- * Test faulty metabox priority assignment.
- *
- * This function tests the metabox object's setting the priority to 'default' when
- * passed a value other than 'high', 'core', 'default', or 'low'.
- *
- * @depends testMethodGetPriority
- * @covers ::__construct
- * @since 0.1
- */
- public function testInvalidPriority()
- {
- $metabox = new WPMVCB_Metabox_Model_Base( array(
- 'id' => 'my-super-cool-metabox',
- 'title' => 'My Super Cool Metabox',
- 'callback' => 'my_super_cool_callback',
- 'post_types' => array( 'my_super_cool_posttype' ),
- 'context' => 'normal',
- 'priority' => 'flibbertygibbet',
- 'callback_args' => array( 'foo' => 'bar' )
- ) );
-
- $this->assertEquals( 'default', $metabox->get_priority() );
- }
- }
-}
diff --git a/tests/unit-tests/test_base_model_options_page.php b/tests/unit-tests/test_base_model_options_page.php
deleted file mode 100644
index 3c889ca..0000000
--- a/tests/unit-tests/test_base_model_options_page.php
+++ /dev/null
@@ -1,569 +0,0 @@
-options_page = new WPMVCB_Menu_Page_Model_Base();
- }
-
- public function testPropertyParentSlugExists()
- {
- $this->assertClassHasAttribute( 'parent_slug', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyPageTitleExists()
- {
- $this->assertClassHasAttribute( 'page_title', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyMenuTitleExists()
- {
- $this->assertClassHasAttribute( 'menu_title', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyCapabilityExists()
- {
- $this->assertClassHasAttribute( 'capability', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyMenuSlugExists()
- {
- $this->assertClassHasAttribute( 'menu_slug', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyCallbackExists()
- {
- $this->assertClassHasAttribute( 'callback', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyIconUrlExists()
- {
- $this->assertClassHasAttribute( 'icon_url', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyPositionExists()
- {
- $this->assertClassHasAttribute( 'position', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyAdminScriptsExists()
- {
- $this->assertClassHasAttribute( 'admin_scripts', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyAdminCssExists()
- {
- $this->assertClassHasAttribute( 'admin_css', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyHelpTabsExists()
- {
- $this->assertClassHasAttribute( 'help_tabs', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyViewExists()
- {
- $this->assertClassHasAttribute( 'view', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testPropertyHookSuffixExists()
- {
- $this->assertClassHasAttribute( 'hook_suffix', '\WPMVCB_Menu_Page_Model_Base' );
- }
-
- public function testMethodSetParentSlugExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_parent_slug' ) );
- }
-
- /**
- * @depends testMethodSetParentSlugExists
- */
- public function testMethodSetParentSlug()
- {
- $this->options_page->set_parent_slug( 'settings' );
-
- $this->assertEquals( 'settings', $this->getReflectionPropertyValue( $this->options_page, 'parent_slug' ) );
- }
-
- public function testMethodGetParentSlugExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Menu_Page_Model_Base', 'get_parent_slug' ) );
- }
-
- /**
- * @depends testMethodSetParentSlugExists
- * @depends testMethodGetParentSlugExists
- * @depends testMethodSetParentSlug
- */
- public function testMethodGetParentSlug()
- {
- $this->assertNull( $this->options_page->get_parent_slug() );
-
- $this->options_page->set_parent_slug( 'settings' );
- $this->assertEquals( 'settings', $this->options_page->get_parent_slug() );
- }
-
- public function testMethodSetPageTitleExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_page_title' ) );
- }
-
- /**
- * @depends testMethodSetPageTitleExists
- */
- public function testMethodSetPageTitle()
- {
- $this->options_page->set_page_title( 'My Page Title' );
-
- $this->assertEquals( 'My Page Title', $this->getReflectionPropertyValue( $this->options_page, 'page_title' ) );
- }
-
- public function testMethodGetPageTitleExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Menu_Page_Model_Base', 'get_page_title' ) );
- }
-
- /**
- * @depends testMethodSetPageTitleExists
- * @depends testMethodGetPageTitleExists
- * @depends testMethodSetPageTitle
- */
- public function testMethodGetPageTitle()
- {
- $this->assertNull( $this->options_page->get_page_title() );
-
- $this->options_page->set_page_title( 'My Page Title' );
- $this->assertEquals( 'My Page Title', $this->options_page->get_page_title() );
- }
-
- public function testMethodSetMenuTitleExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_menu_title' ) );
- }
-
- /**
- * @depends testMethodSetMenuTitleExists
- */
- public function testMethodSetMenuTitle()
- {
- $this->options_page->set_menu_title( 'My Menu Page' );
- $this->assertEquals( 'My Menu Page', $this->getReflectionPropertyValue( $this->options_page, 'menu_title' ) );
- }
-
- public function testMethodGetMenuTitleExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_menu_title' ) );
- }
-
- /**
- * @depends testMethodSetMenuTitleExists
- * @depends testMethodGetMenuTitleExists
- * @depends testMethodSetMenuTitle
- */
- public function testMethodGetMenuTitle()
- {
- $this->assertNull( $this->options_page->get_menu_title() );
-
- $this->options_page->set_menu_title( 'My Menu Page' );
- $this->assertEquals( 'My Menu Page', $this->options_page->get_menu_title() );
- }
-
- public function testMethodSetCapabilityExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_capability' ) );
- }
-
- /**
- * @depends testMethodSetCapabilityExists
- */
- public function testMethodSetCapability()
- {
- $this->options_page->set_capability( 'manage_posts' );
- $this->assertEquals( 'manage_posts', $this->getReflectionPropertyValue( $this->options_page, 'capability' ) );
- }
-
- public function testMethodGetCapabilityExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_capability' ) );
- }
-
- /**
- * @depends testMethodSetCapabilityExists
- * @depends testMethodGetCapabilityExists
- * @depends testMethodSetCapability
- */
- public function testMethodGetCapability()
- {
- $this->assertNull( $this->options_page->get_capability() );
-
- $this->options_page->set_capability( 'manage_posts' );
- $this->assertEquals( 'manage_posts', $this->options_page->get_capability() );
- }
-
- public function testMethodSetMenuSlugExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_menu_slug' ) );
- }
-
- /**
- * @depends testMethodSetMenuSlugExists
- */
- public function testMethodSetMenuSlug()
- {
- $this->options_page->set_menu_slug( 'my_menu_slug' );
- $this->assertEquals( 'my_menu_slug', $this->getReflectionPropertyValue( $this->options_page, 'menu_slug' ) );
- }
-
- public function testMethodGetMenuSlugExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_menu_slug' ) );
- }
-
- /**
- * @depends testMethodSetMenuSlugExists
- * @depends testMethodGetMenuSlugExists
- * @depends testMethodSetMenuSlug
- */
- public function testMethodGetMenuSlug()
- {
- $this->assertNull( $this->options_page->get_menu_slug() );
-
- $this->options_page->set_menu_slug( 'my_menu_slug' );
- $this->assertEquals( 'my_menu_slug', $this->options_page->get_menu_slug() );
- }
-
- public function testMethodSetCallbackExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_callback' ) );
- }
-
- /**
- * @depends testMethodSetCallbackExists
- */
- public function testMethodSetCallback()
- {
- $this->options_page->set_callback( 'my_callback' );
- $this->assertEquals( 'my_callback', $this->getReflectionPropertyValue( $this->options_page, 'callback' ) );
- }
-
- public function testMethodGetCallbackExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_callback' ) );
- }
-
- /**
- * @depends testMethodSetCallbackExists
- * @depends testMethodGetCallbackExists
- * @depends testMethodSetCallback
- */
- public function testMethodGetCallback()
- {
- $this->assertNull( $this->options_page->get_callback() );
-
- $this->options_page->set_callback( 'my_callback' );
- $this->assertEquals( 'my_callback', $this->options_page->get_callback() );
- }
-
- public function testMethodSetIconUrlExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_icon_url' ) );
- }
-
- /**
- * @depends testMethodSetIconUrlExists
- */
- public function testMethodSetIconUrl()
- {
- $this->options_page->set_icon_url( 'my_icon_url' );
- $this->assertEquals( 'my_icon_url', $this->getReflectionPropertyValue( $this->options_page, 'icon_url' ) );
- }
-
- public function testMethodGetIconUrlExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_icon_url' ) );
- }
-
- /**
- * @depends testMethodSetIconUrlExists
- * @depends testMethodGetIconUrlExists
- * @depends testMethodSetIconUrl
- */
- public function testMethodGetIconUrl()
- {
- $this->assertNull( $this->options_page->get_icon_url() );
-
- $this->options_page->set_icon_url( 'my_icon_url' );
- $this->assertEquals( 'my_icon_url', $this->options_page->get_icon_url() );
- }
-
- public function testMethodSetPositionExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_position' ) );
- }
-
- /**
- * @depends testMethodSetPositionExists
- */
- public function testMethodSetPosition()
- {
- $this->options_page->set_position( 'my_position' );
- $this->assertEquals( 'my_position', $this->getReflectionPropertyValue( $this->options_page, 'position' ) );
- }
-
- public function testMethodGetPositionExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_position' ) );
- }
-
- /**
- * @depends testMethodSetPositionExists
- * @depends testMethodGetPositionExists
- * @depends testMethodSetPosition
- */
- public function testMethodGetPosition()
- {
- $this->assertNull( $this->options_page->get_position() );
-
- $this->options_page->set_position( 'my_position' );
- $this->assertEquals( 'my_position', $this->options_page->get_position() );
- }
-
- public function testMethodSetAdminScriptsExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_admin_scripts' ) );
- }
-
- /**
- * @depends testMethodSetAdminScriptsExists
- */
- public function testMethodSetAdminScripts()
- {
- $this->options_page->set_admin_scripts( 'my_admin_scripts' );
- $this->assertEquals( 'my_admin_scripts', $this->getReflectionPropertyValue( $this->options_page, 'admin_scripts' ) );
- }
-
- public function testMethodGetAdminScriptsExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_admin_scripts' ) );
- }
-
- /**
- * @depends testMethodSetAdminScriptsExists
- * @depends testMethodGetAdminScriptsExists
- * @depends testMethodSetAdminScripts
- */
- public function testMethodGetAdminScripts()
- {
- $this->assertNull( $this->options_page->get_admin_scripts() );
-
- $this->options_page->set_admin_scripts( 'my_admin_scripts' );
- $this->assertEquals( 'my_admin_scripts', $this->options_page->get_admin_scripts() );
- }
-
- public function testMethodSetAdminCssExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_admin_css' ) );
- }
-
- /**
- * @depends testMethodSetAdminCssExists
- */
- public function testMethodSetAdminCss()
- {
- $this->options_page->set_admin_css( 'my_admin_css' );
- $this->assertEquals( 'my_admin_css', $this->getReflectionPropertyValue( $this->options_page, 'admin_css' ) );
- }
-
- public function testMethodGetAdminCssExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_admin_css' ) );
- }
-
- /**
- * @depends testMethodSetAdminCssExists
- * @depends testMethodGetAdminCssExists
- * @depends testMethodSetAdminCss
- */
- public function testMethodGetAdminCss()
- {
- $this->assertNull( $this->options_page->get_admin_css() );
-
- $this->options_page->set_admin_css( 'my_admin_css' );
- $this->assertEquals( 'my_admin_css', $this->options_page->get_admin_css() );
- }
-
- public function testMethodSetHelpTabsExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_help_tabs' ) );
- }
-
- /**
- * @depends testMethodSetHelpTabsExists
- */
- public function testMethodSetHelpTabs()
- {
- $this->options_page->set_help_tabs( 'my_help_tabs' );
- $this->assertEquals( 'my_help_tabs', $this->getReflectionPropertyValue( $this->options_page, 'help_tabs' ) );
- }
-
- public function testMethodGetHelpTabsExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_help_tabs' ) );
- }
-
- /**
- * @depends testMethodSetHelpTabsExists
- * @depends testMethodGetHelpTabsExists
- * @depends testMethodSetHelpTabs
- */
- public function testMethodGetHelpTabs()
- {
- $this->assertNull( $this->options_page->get_help_tabs() );
-
- $this->options_page->set_help_tabs( 'my_help_tabs' );
- $this->assertEquals( 'my_help_tabs', $this->options_page->get_help_tabs() );
- }
-
- public function testMethodSetViewExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'set_view' ) );
- }
-
- /**
- * @depends testMethodSetViewExists
- */
- public function testMethodSetView()
- {
- $this->options_page->set_view( 'my_view' );
- $this->assertEquals( 'my_view', $this->getReflectionPropertyValue( $this->options_page, 'view' ) );
- }
-
- public function testMethodGetViewExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_view' ) );
- }
-
- /**
- * @depends testMethodSetViewExists
- * @depends testMethodGetViewExists
- * @depends testMethodSetView
- */
- public function testMethodGetView()
- {
- $this->assertNull( $this->options_page->get_view() );
-
- $this->options_page->set_view( 'my_view' );
- $this->assertEquals( 'my_view', $this->options_page->get_view() );
- }
-
- public function testMethodGetHookSuffixExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'get_hook_suffix' ) );
- }
-
- /**
- * @depends testMethodGetHookSuffixExists
- */
- public function testMethodGetHookSuffix()
- {
- $this->assertNull( $this->options_page->get_hook_suffix() );
-
- $this->setReflectionPropertyValue( $this->options_page, 'hook_suffix', 'my_hook_suffix' );
- $this->assertEquals( 'my_hook_suffix', $this->options_page->get_hook_suffix() );
- }
-
- public function testMethodAddExists()
- {
- $this->assertTrue( method_exists( $this->options_page, 'add' ) );
- }
-
- /**
- * Test the addition of a top level menu page with a set position.
- *
- * @depends testMethodSetParentSlugExists
- * @depends testMethodSetPageTitleExists
- * @depends testMethodSetMenuTitleExists
- * @depends testMethodSetCapabilityExists
- * @depends testMethodSetMenuSlugExists
- * @depends testMethodSetCallbackExists
- * @depends testMethodSetIconUrlExists
- * @depends testMethodSetPositionExists
- * @depends testMethodAddExists
- */
- public function testMethodAddTopLevelPage()
- {
- $page = new \WPMVCB_Menu_Page_Model_Base;
- $page->set_page_title( 'My Page Title' );
- $page->set_menu_title( 'My Menu Title' );
- $page->set_capability( 'manage_options' );
- $page->set_menu_slug( 'my-menu-slug');
- $page->set_callback( 'my_callback' );
- $page->set_icon_url( 'http://foo.com/my_icon.jpg' );
- $page->set_position( '3.14159' );
-
- //verify we had a successful addition
- $this->assertFalse( false === $page->add() );
-
- //verify the position
- global $menu;
-
- if ( isset( $menu ) ) {
- $this->assertArrayHasKey( '3.14159', $menu );
- } else {
- $this->markTestIncomplete( 'The global $menu is not set.' );
- }
- }
-
- /**
- * Test the addition of a sub menu page with appropriate user capability.
- *
- * @covers WPMVCB_Menu_Page_Model_Base::add
- * @depends testMethodSetParentSlugExists
- * @depends testMethodSetPageTitleExists
- * @depends testMethodSetMenuTitleExists
- * @depends testMethodSetCapabilityExists
- * @depends testMethodSetMenuSlugExists
- * @depends testMethodSetCallbackExists
- * @depends testMethodAddExists
- */
- public function testMethodAddSubmenuPage()
- {
- //set the current user to admin
- wp_set_current_user( 1 );
-
- $page = new \WPMVCB_Menu_Page_Model_Base;
- $page->set_parent_slug( 'options-general.php' );
- $page->set_page_title( 'My Page Title' );
- $page->set_menu_title( 'My Menu Title' );
- $page->set_capability( 'manage_options' );
- $page->set_menu_slug( 'my-menu-slug');
- $page->set_callback( 'my_callback' );
-
- //verify we had a successful addition
- $this->assertFalse( false === $page->add() );
- }
- }
-}
diff --git a/tests/unit-tests/test_base_model_plugin.php b/tests/unit-tests/test_base_model_plugin.php
deleted file mode 100644
index a616fa0..0000000
--- a/tests/unit-tests/test_base_model_plugin.php
+++ /dev/null
@@ -1,159 +0,0 @@
-model = $this->getMockBuilder( '\Base_Model_Plugin' )
- ->setConstructorArgs( $args )
- ->getMockForAbstractClass();
- }
-
- public function tearDown()
- {
- unset( $this->model );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsSlug()
- {
- $this->assertClassHasAttribute( 'slug', '\Base_Model_Plugin' );
- $this->assertEquals( 'foo', $this->getReflectionPropertyValue( $this->model, 'slug' ) );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsVersion()
- {
- $this->assertClassHasAttribute( 'version', '\Base_Model_Plugin' );
- $this->assertEquals( '1.0.1', $this->getReflectionPropertyValue( $this->model, 'version' ) );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsPath()
- {
- $this->assertClassHasAttribute( 'path', '\Base_Model_Plugin' );
- $this->assertEquals( dirname( __FILE__ ) . '/' , $this->getReflectionPropertyValue( $this->model, 'path' ) );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsAppPath()
- {
- $this->assertClassHasAttribute( 'app_path', '\Base_Model_Plugin' );
- $this->assertEquals( dirname( __FILE__ ) . '/app/', $this->getReflectionPropertyValue( $this->model, 'app_path' ) );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsBasePath()
- {
- $this->assertClassHasAttribute( 'base_path', '\Base_Model_Plugin' );
- $this->assertEquals( dirname( __FILE__ ) . '/base/' , $this->getReflectionPropertyValue( $this->model, 'base_path' ) );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsMainPluginFile()
- {
- $this->assertClassHasAttribute( 'main_plugin_file', '\Base_Model_Plugin' );
- $this->assertEquals( __FILE__, $this->getReflectionPropertyValue( $this->model, 'main_plugin_file' ) );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsUri()
- {
- $this->assertClassHasAttribute( 'uri', '\Base_Model_Plugin' );
- $this->assertEquals( 'http://example.com/', $this->getReflectionPropertyValue( $this->model, 'uri' ) );
- }
-
- /**
- * @covers Base_Model_Plugin::__construct
- */
- public function testAttributeExistsTxtdomain()
- {
- $this->assertClassHasAttribute( 'txtdomain', '\Base_Model_Plugin' );
- $this->assertEquals( 'bar', $this->getReflectionPropertyValue( $this->model, 'txtdomain' ) );
- }
-
- public function testAttributeExistsHelpTabs()
- {
- $this->assertClassHasAttribute( 'help_tabs', '\Base_Model_Plugin' );
- }
-
- public function testAttributeExistsCss()
- {
- $this->assertClassHasAttribute( 'css', '\Base_Model_Plugin' );
- }
-
- public function testAttributeExistsAdminCss()
- {
- $this->assertClassHasAttribute( 'admin_css', '\Base_Model_Plugin' );
- }
-
- public function testAttributeExistsScripts()
- {
- $this->assertClassHasAttribute( 'scripts', '\Base_Model_Plugin' );
- }
-
- public function testAttributeExistsAdminScripts()
- {
- $this->assertClassHasAttribute( 'admin_scripts', '\Base_Model_Plugin' );
- }
-
- public function testAttributeExistsMetaboxes()
- {
- $this->assertClassHasAttribute( 'metaboxes', '\Base_Model_Plugin' );
- }
-
- /**
- * @covers Base_Model_Plugin::get_slug
- */
- public function testMethodGetSlug()
- {
- $this->assertTrue( method_exists( $this->model, 'get_slug' ) );
- $this->assertEquals( 'foo', $this->model->get_slug() );
- }
-
- /**
- * @covers Base_Model_Plugin::get_version
- */
- public function testMethodGetVersion()
- {
- $this->assertTrue( method_exists( $this->model, 'get_version' ) );
- $this->assertEquals( '1.0.1', $this->model->get_version() );
- }
- }
-}
diff --git a/tests/unit-tests/test_base_model_settings.php b/tests/unit-tests/test_base_model_settings.php
deleted file mode 100644
index 0cc5051..0000000
--- a/tests/unit-tests/test_base_model_settings.php
+++ /dev/null
@@ -1,565 +0,0 @@
-_settings_model = new Stub_Settings_Model( 'http://example.com', 'foopath', 'footxtdomain');
- parent::setUp();
- }
-
- public function testPropertyOptionsExists()
- {
- $this->assertClassHasAttribute( 'options', '\Base_Model_Settings' );
- }
-
- public function testPropertyPagesExists()
- {
- $this->assertClassHasAttribute( 'pages', '\Base_Model_Settings' );
- }
-
- public function testPropertySettingsSectionsExists()
- {
- $this->assertClassHasAttribute( 'settings_sections', '\Base_Model_Settings' );
- }
-
- public function testPropertySettingsFieldsExists()
- {
- $this->assertClassHasAttribute( 'settings_fields', '\Base_Model_Settings' );
- }
-
- public function testPropertySettingsExists()
- {
- $this->assertClassHasAttribute( 'settings', '\Base_Model_Settings' );
- }
-
- public function testMethodInitSettings()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'init_settings' ), 'Method does not exist' );
-
- $this->setReflectionPropertyValue( $this->_settings_model, 'options', array( 'foo', 'bar', 'baz' ) );
- $this->reflectionMethodInvoke( $this->_settings_model, 'init_settings' );
- $this->markTestIncomplete( 'Missing assertions' );
- }
-
- public function testMethodGetOptions()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'get_options' ), 'Method does not exist' );
-
- $this->setReflectionPropertyValue( $this->_settings_model, 'options', array( 'foo', 'bar', 'baz' ) );
-
- $this->assertEquals( array( 'foo', 'bar', 'baz' ), $this->_settings_model->get_options() );
- }
-
- public function testMethodGetPages()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'get_pages' ), 'Method does not exist' );
-
- $this->setReflectionPropertyValue( $this->_settings_model, 'pages', array( 'foo', 'bar', 'baz' )
- );
-
- $this->assertEquals( array( 'foo', 'bar', 'baz' ), $this->_settings_model->get_pages() );
- }
-
- public function testMethodGetSettingsSectionsExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'get_settings_sections' ), 'Method does not exist' );
- }
-
- /**
- * @depends testMethodGetSettingsSectionsExists
- */
- public function testMethodGetSettingsSectionsAll()
- {
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'settings_sections',
- array(
- 'foo' => 'bar',
- 'baz'
- )
- );
-
- //get all sections
- $this->assertEquals(
- array( 'foo' => 'bar', 'baz' ),
- $this->_settings_model->get_settings_sections() ,
- 'Get all sections failed'
- );
- }
-
- /**
- * @depends testMethodGetSettingsSectionsExists
- */
- public function testMethodGetSettingsSectionsKeyExisting()
- {
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'settings_sections',
- array(
- 'foo' => 'bar',
- 'bar'
- )
- );
-
- $this->assertEquals(
- 'bar',
- $this->_settings_model->get_settings_sections( 'foo' ),
- 'Get one section failed'
- );
- }
-
- /**
- * @depends testMethodGetSettingsSectionsExists
- */
- public function testMethodGetSettingsSectionsKeyNonexistent()
- {
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'settings_sections',
- array(
- 'foo' => 'bar',
- 'bar'
- )
- );
-
- $this->assertFalse(
- $this->_settings_model->get_settings_sections( 'baz' ),
- 'Get nonexistent section failed'
- );
- }
-
-
- public function testMethodGetSettingsFields()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'get_settings_fields' ), 'Method does not exist' );
-
- $this->setReflectionPropertyValue( $this->_settings_model, 'settings_fields', array( 'foo', 'bar', 'baz' )
- );
-
- $this->assertEquals( array( 'foo', 'bar', 'baz' ), $this->_settings_model->get_settings_fields() );
- }
-
- public function testEditPageExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'edit_page' ) );
- }
-
- /**
- * @depends testEditPageExists
- */
- public function testMethodEditPage()
- {
- $this->setReflectionPropertyValue( $this->_settings_model, 'pages', array( 'foo' => array() ) );
- $this->assertTrue( $this->_settings_model->edit_page( 'foo', array( 'bar' => 'baz' ) ) );
- $this->assertEquals(
- array( 'foo' => array( 'bar' => 'baz') ),
- $this->getReflectionPropertyValue( $this->_settings_model, 'pages' )
- );
- }
-
- /**
- * @depends testEditPageExists
- */
- public function testMethodEditPageFail()
- {
- $this->assertFalse( $this->_settings_model->edit_page( 'foo', array( 'bar' => 'baz' ) ) );
- }
-
- public function testMethodEditSettingsSectionExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'edit_settings_section' ) );
- }
-
- /**
- * @depends testMethodEditSettingsSectionExists
- */
- public function testMethodEditSettingsSection()
- {
- $this->setReflectionPropertyValue( $this->_settings_model, 'settings_sections', array( 'foo' => array() ) );
- $this->assertTrue( $this->_settings_model->edit_settings_section( 'foo', array( 'bar' => 'baz' ) ) );
- $this->assertEquals(
- array( 'foo' => array( 'bar' => 'baz') ),
- $this->getReflectionPropertyValue( $this->_settings_model, 'settings_sections' )
- );
- }
-
- /**
- * @depends testMethodEditSettingsSectionExists
- */
- public function testMethodEditSettingsSectionFail()
- {
- $this->assertFalse( $this->_settings_model->edit_settings_section( 'foo', array( 'bar' => 'baz' ) ) );
- }
-
- public function testMethodGetSettingsExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'get_settings' ), 'Method does not exist' );
- }
-
- /**
- * Test the Base_Model_Settings class' ability to handle multiple options stored as key/value pairs.
- *
- * @depends testMethodGetSettingsExists
- * @since 0.1
- */
- public function testMethodGetSettingsSingleAll()
- {
- //add the options to wpdb
- \add_option( 'fooname', '1' );
- \add_option( 'barname', '2' );
- \add_option( 'bazname', '3' );
-
- //set up the settings_model options property
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'options',
- array(
- 'foo' => array( 'option_name' => 'fooname' ),
- 'bar' => array( 'option_name' => 'barname' ),
- 'baz' => array( 'option_name' => 'bazname' )
- )
- );
-
- //initialize the settings_model options
- $this->reflectionMethodInvoke( $this->_settings_model, 'init_settings' );
-
- $this->assertEquals( array( 'fooname' => '1', 'barname' => '2', 'bazname' => '3' ), $this->_settings_model->get_settings() );
- }
-
- /**
- * @depends testMethodGetSettingsSingleAll
- */
- public function testMethodGetSettingsSingleKeyExists()
- {
- //add the options to wpdb
- \add_option( 'fooname', '1' );
- \add_option( 'barname', '2' );
- \add_option( 'bazname', '3' );
-
- //set up the settings_model options property
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'options',
- array(
- 'foo' => array( 'option_name' => 'fooname' ),
- 'bar' => array( 'option_name' => 'barname' ),
- 'baz' => array( 'option_name' => 'bazname' )
- )
- );
-
- //initialize the settings_model options
- $this->reflectionMethodInvoke( $this->_settings_model, 'init_settings' );
-
- $this->assertEquals( '1', $this->_settings_model->get_settings( 'fooname' ) );
- }
-
- /**
- * @depends testMethodGetSettingsExists
- */
- public function testMethodGetSettingsSingleOptionElementError()
- {
- //add the options to wpdb
- \add_option( 'fooname', '1' );
- \add_option( 'barname', '2' );
- \add_option( 'bazname', '3' );
-
- //set up the settings_model options property
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'options',
- array(
- 'foo' => array( 'option_name' => 'fooname' ),
- 'bar' => array( 'option_name' => 'barname' ),
- 'baz' => array( 'option_name' => 'bazname' )
- )
- );
-
- //initialize the settings_model options
- $this->reflectionMethodInvoke( $this->_settings_model, 'init_settings' );
- $this->assertFalse( $this->_settings_model->get_settings( 'barname', 'huzzah' ) );
-
- }
-
- /**
- * This test emulates a multiple option group stored as serialized arrays setup.
- *
- * @depends testMethodGetSettingsExists
- */
- public function testMethodGetSettingsArrayAll()
- {
- //set the options in the wpdb
- \add_option( 'fooname', array( 'foobar', 'foobaz' ) );
- \add_option( 'barname', array( 'barbar', 'barbaz' ) );
-
- //set up the settings_model options property
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'options',
- array(
- 'foo' => array( 'option_name' => 'fooname' ),
- 'bar' => array( 'option_name' => 'barname' ),
- 'baz' => array( 'option_name' => 'bazname' )
- )
- );
-
- //initialize the settings_model options
- $this->reflectionMethodInvoke( $this->_settings_model, 'init_settings' );
-
- $this->assertEquals(
- array( 'fooname' => array( 'foobar', 'foobaz'), 'barname' => array( 'barbar', 'barbaz' ), 'bazname' => false ),
- $this->_settings_model->get_settings()
- );
- }
-
- /**
- * @depends testMethodGetSettingsExists
- */
- public function testMethodGetSettingsOptionGroupKeyExists()
- {
- $this->setReflectionPropertyValue( $this->_settings_model, 'settings', array( 'foo' => array( 'bar', 'baz' ) ) );
- $this->assertEquals( array( 'bar', 'baz'), $this->_settings_model->get_settings( 'foo' ) );
- }
-
- /**
- * @depends testMethodGetSettingsExists
- */
- public function testMethodGetSettingsOptionGroupKeyNonexistent()
- {
- $this->setReflectionPropertyValue( $this->_settings_model, 'settings', array( 'foo' => array( 'bar', 'baz' ) ) );
- $this->assertFalse( $this->_settings_model->get_settings( 'baz' ) );
- }
-
- /**
- * Test for an existing option group key and an existing option key.
- *
- * This test asserts the Base_Model_Settings class' ability to process options stored as a serialized array.
- *
- * @depends testMethodGetSettingsOptionGroupKeyExists
- */
- public function testMethodGetSettingsOptionGroupKeyExistsOptionKeyExists()
- {
- $this->setReflectionPropertyValue( $this->_settings_model, 'settings', array( 'foo' => array( 'bar' => 'baz' ) ) );
- $this->assertEquals( 'baz', $this->_settings_model->get_settings( 'foo', 'bar' ) );
- }
-
- /**
- * Test default value for non-existent option in an options array.
- *
- * @depends testMethodGetSettingsOptionGroupKeyExistsOptionKeyExists
- */
- public function testMethodGetSettingsOptionGroupKeyExistsOptionKeyNonexistentDefault()
- {
- //set up a settings field with a default value
- $this->setReflectionPropertyValue(
- $this->_settings_model,
- 'settings_fields',
- array( 'bar' => array( 'default' => 'baz' ) )
- );
-
- //set up a settings structure
- $this->setReflectionPropertyValue(
- $this->_settings_model, 'settings',
- array( 'foo' => array( 'baz' ) )
- );
-
- $this->assertEquals( 'baz', $this->_settings_model->get_settings( 'foo', 'bar' ) );
- }
-
- /**
- * Test no default value for non-existent option.
- *
- * @depends testMethodGetSettingsOptionGroupKeyExistsOptionKeyExists
- */
- public function testMethodGetSettingsOptionGroupKeyExistsOptionKeyNonexistentNoDefault()
- {
- $this->setReflectionPropertyValue( $this->_settings_model, 'settings', array( 'foo' => array( 'bar', 'baz' ) ) );
- $this->assertFalse( $this->_settings_model->get_settings( 'foo', 'yazoo' ) );
- }
-
- /**
- * @depends testMethodGetSettingsExists
- */
- public function testMethodGetSettingsKeyNonexistent()
- {
- $this->setReflectionPropertyValue( $this->_settings_model, 'settings', array( 'foo' => array( 'bar', 'baz' ) ) );
- $this->assertFalse( $this->_settings_model->get_settings( 'yazoo' ) );
- }
-
- public function testMethodAddOptionExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'add_option' ) );
- }
-
- /**
- * @depends testMethodAddOptionExists
- */
- public function testMethodAddOption()
- {
- $expected = array( 'foo' => array( 'option_group' => 'bar', 'option_name' => 'baz' ) );
-
- $this->assertTrue( $this->_settings_model->add_option( $expected ) );
- $this->assertEquals( $expected, $this->getReflectionPropertyValue( $this->_settings_model, 'options' ) );
- }
-
- /**
- * @depends testMethodAddOptionExists
- */
- public function testMethodAddOptionPassNonarray()
- {
- $this->assertFalse( $this->_settings_model->add_option( 'foo' ) );
- }
-
- /**
- * @depends testMethodAddOptionExists
- */
- public function testMethodAddOptionPassNonarrayErrorMessage()
- {
- $this->_settings_model->add_option( 'foo' );
- $error = error_get_last();
- $this->assertEquals(
- sprintf(
- __( 'Method add_option expects an array. The passed in parameter is of type: %s', 'wpmvcb' ),
- gettype( 'foo' )
- ),
- $error['message']
- );
- }
-
- public function testMethodAddSettingsSectionExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'add_settings_section' ) );
- }
-
- /**
- * @depends testMethodAddSettingsSectionExists
- */
- public function testMethodAddSettingsSection()
- {
- $expected = array(
- 'foo-section' => array(
- 'title' => 'foo',
- 'callback' => 'foo-callback',
- 'page' => 'foo-page',
- 'content' => 'Content foo'
- )
- );
-
- $this->assertTrue( $this->_settings_model->add_settings_section( $expected ) );
- $this->assertEquals( $expected, $this->getReflectionPropertyValue( $this->_settings_model, 'settings_sections' ) );
- }
-
- /**
- * @depends testMethodAddSettingsSectionExists
- */
- public function testMethodAddSettingsSectionPassNonarray()
- {
- $this->assertFalse( $this->_settings_model->add_settings_section( 'foo' ) );
- }
-
- /**
- * @depends testMethodAddSettingsSectionExists
- */
- public function testAddSettingsSectionPassNonarrayErrorMessage()
- {
- $this->_settings_model->add_option( 'foo' );
- $error = error_get_last();
- $this->assertEquals(
- sprintf(
- __( 'Method add_option expects an array. The passed in parameter is of type: %s', 'wpmvcb' ),
- gettype( 'foo' )
- ),
- $error['message']
- );
- }
-
- public function testMethodAddSettingsFieldExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'add_settings_field' ) );
- }
-
- /**
- * @depends testMethodAddSettingsFieldExists
- */
- public function testMethodAddSettingsField()
- {
- $expected = array(
- 'foo-field' => array(
- 'title' => 'foo',
- 'callback' => 'foo-callback',
- 'page' => 'foo-page',
- 'content' => 'Content foo'
- )
- );
-
- $this->assertTrue( $this->_settings_model->add_settings_field( $expected ) );
- $this->assertEquals( $expected, $this->getReflectionPropertyValue( $this->_settings_model, 'settings_fields' ) );
- }
-
- /**
- * @depends testMethodAddSettingsFieldExists
- */
- public function testMethodAddSettingsFieldPassNonarray()
- {
- $this->assertFalse( $this->_settings_model->add_settings_field( 'foo' ) );
- }
-
- /**
- * @depends testMethodAddSettingsFieldExists
- */
- public function testMethodAddSettingsFieldPassNonarrayErrorMessage()
- {
- $this->_settings_model->add_settings_field( 'foo' );
- $error = error_get_last();
- $this->assertEquals(
- sprintf(
- __( 'Method add_settings_field expects an array. The passed in parameter is of type: %s', 'wpmvcb' ),
- gettype( 'foo' )
- ),
- $error['message']
- );
- }
-
- public function testMethodSanitizeInputExists()
- {
- $this->assertTrue( method_exists( '\WPMVCB_Settings_Model_Base', 'sanitize_input' ) );
- }
-
- /**
- * @depends testMethodSanitizeInputExists
- */
- public function testMethodSanitizeInputString()
- {
- $input = sanitize_text_field(
- "`1234567890--=~!@#$%^&*()_+qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:\"zxcvbnm,./ZXCVBNM<>?"
- );
-
- $this->assertEquals( $input, $this->_settings_model->sanitize_input( $input ) );
- }
-
- /**
- * @depends testMethodSanitizeInputExists
- */
- public function testMethodSanitizeInputArray()
- {
- $input['foo'] = sanitize_text_field(
- "`1234567890--=~!@#$%^&*()_+qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:\"zxcvbnm,./ZXCVBNM<>?"
- );
-
- $this->assertEquals( $input, $this->_settings_model->sanitize_input( $input ) );
- }
- }
-}
-?>
\ No newline at end of file
diff --git a/tests/unit-tests/test_class_base_model_cpt.php b/tests/unit-tests/test_class_base_model_cpt.php
deleted file mode 100644
index f32868c..0000000
--- a/tests/unit-tests/test_class_base_model_cpt.php
+++ /dev/null
@@ -1,240 +0,0 @@
-_factory = new \WP_UnitTest_Factory;
- $this->cpt = $this->getMockBuilder( '\Base_Model_CPT' )
- ->setConstructorArgs( $args )
- ->getMockForAbstractClass();
-
- $this->_post = get_post(
- $this->_factory->post->create_object(
- array(
- 'post_type' => 'fooslug',
- 'post_title' => 'Test CPT'
- )
- )
- );
- }
-
- protected function init_args()
- {
- $this->cpt->set_args (
- array(
- 'description' => __( 'Books', 'my-super-cool-text-domain' ),
- 'labels' => $labels,
- 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
- 'hierarchical' => false,
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'show_in_nav_menus' => true,
- 'show_in_admin_bar' => true,
- 'menu_icon' => null,
- 'can_export' => true,
- 'has_archive' => true,
- 'exclude_from_search' => false,
- 'publicly_queryable' => true,
- 'rewrite' => array( 'slug' => 'books' ),
- //this is supported in 3.6
- 'statuses' => array(
- 'draft' => array(
- 'label' => _x( 'New', 'book', 'my-super-cool-text-domain' ),
- 'public' => true,
- 'exclude_from_search' => false,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'label_count' => _n_noop( 'New (%s)', 'New (%s)', 'my-super-cool-text-domain' )
- )
- )
- )
- );
- }
-
- /**
- * @covers Base_Model_CPT::__construct
- */
- public function testPropertySlug()
- {
- $this->assertClassHasAttribute( 'slug', '\Base_Model_CPT' );
- $this->assertSame( 'fooslug', $this->getReflectionPropertyValue( $this->cpt, 'slug' ) );
- }
-
- /**
- * @covers Base_Model_CPT::__construct
- */
- public function testPropertySingular()
- {
- $this->assertClassHasAttribute( 'singular', '\Base_Model_CPT' );
- $this->assertSame( 'Book', $this->getReflectionPropertyValue( $this->cpt, 'singular' ) );
- }
-
- /**
- * @covers Base_Model_CPT::__construct
- */
- public function testPropertyPlural()
- {
- $this->assertClassHasAttribute( 'plural', '\Base_Model_CPT' );
- $this->assertSame( 'Books', $this->getReflectionPropertyValue( $this->cpt, 'plural' ) );
- }
-
- /**
- * @covers Base_Model_CPT::init_labels
- */
- public function testInitLabels()
- {
- $expected = array(
- 'name' => 'Books',
- 'singular_name' => 'Book',
- 'menu_name' => 'Books',
- 'parent_item_colon' => 'Parent Book',
- 'all_items' => 'All Books',
- 'view_item' => 'View Book',
- 'add_new_item' => 'Add New Book',
- 'add_new' => 'New Book',
- 'edit_item' => 'Edit Book',
- 'update_item' => 'Update Book',
- 'search_items' => 'Search Books',
- 'not_found' => 'No books found',
- 'not_found_in_trash' => 'No books found in Trash'
- );
-
- $this->assertClassHasAttribute( 'labels', '\Base_Model_CPT' );
- $this->assertTrue( method_exists( $this->cpt, 'init_labels' ) );
- $this->reflectionMethodInvokeArgs( $this->cpt, 'init_labels', 'footxtdomain' );
- $this->assertEquals( $expected, $this->getReflectionPropertyValue( $this->cpt, 'labels' ) );
- }
-
- /**
- * @covers Base_Model_CPT::get_singular
- */
- public function testMethodGetSingular()
- {
- $this->assertTrue( method_exists( $this->cpt, 'get_singular' ), 'get_singular() does not exist' );
- $this->assertSame( 'Book', $this->cpt->get_singular() );
- }
-
- /**
- * @covers Base_Model_CPT::get_plural
- */
- public function testMethodGetPlural()
- {
- $this->assertTrue( method_exists( $this->cpt, 'get_plural' ), 'get_plural() does not exist' );
- $this->assertSame( 'Books', $this->cpt->get_plural() );
- }
-
- /**
- * @covers Base_Model_CPT::get_slug
- */
- public function testMethodGetSlug()
- {
- $this->assertClassHasAttribute( 'slug', '\Base_Model_CPT' );
- $this->assertTrue( method_exists( $this->cpt, 'get_slug' ) );
- $this->assertEquals( 'fooslug', $this->cpt->get_slug() );
- }
-
- /**
- * @covers Base_Model_CPT::set_args
- */
- public function testMethodSetArgs()
- {
- $this->assertTrue( method_exists( $this->cpt, 'set_args' ) );
- $this->cpt->set_args( array( 'foo' => 'bar' ) );
- $this->assertEquals( array( 'foo' => 'bar' ), $this->getReflectionPropertyValue( $this->cpt, 'args' ) );
- }
-
- /**
- * @covers Base_Model_CPT::set_args
- */
- public function testMethodSetArgsNonArray()
- {
- $this->assertTrue( method_exists( $this->cpt, 'set_args' ) );
- $this->assertEquals(
- new \WP_Error( 'FAIL', 'Base_Model_CPT::set_args expects an array', 'foo' ),
- $this->cpt->set_args( 'foo' )
- );
- }
-
- /**
- * @covers Base_Model_CPT::get_args
- */
- public function testMethodGetArgs()
- {
- $this->assertTrue( method_exists( $this->cpt, 'get_args' ) );
- $this->setReflectionPropertyValue( $this->cpt, 'args', array( 'foo' => 'bar' ) );
- $this->assertEquals( array( 'foo' => 'bar' ), $this->cpt->get_args( array( 'foo' => 'bar' ) ) );
- }
-
- /**
- * Test the return of default arguments
- *
- * @covers Base_Model_CPT::get_args
- */
- public function testMethodGetArgsDefaults()
- {
- $this->assertTrue( method_exists( $this->cpt, 'get_args' ) );
-
- $expected = array(
- 'description' => 'Books',
- 'labels' => array(
- 'name' => 'Books',
- 'singular_name' => 'Book',
- 'menu_name' => 'Books',
- 'parent_item_colon' => 'Parent Book',
- 'all_items' => 'All Books',
- 'view_item' => 'View Book',
- 'add_new_item' => 'Add New Book',
- 'add_new' => 'New Book',
- 'edit_item' => 'Edit Book',
- 'update_item' => 'Update Book',
- 'search_items' => 'Search Books',
- 'not_found' => 'No books found',
- 'not_found_in_trash' => 'No books found in Trash'
- ),
- 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
- 'hierarchical' => false,
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'show_in_nav_menus' => true,
- 'show_in_admin_bar' => true,
- 'menu_icon' => null,
- 'can_export' => true,
- 'has_archive' => true,
- 'exclude_from_search' => false,
- 'publicly_queryable' => true,
- 'rewrite' => array( 'slug' => 'fooslug' ),
- );
-
- $this->assertSame( $expected, $this->cpt->get_args() );
- }
- }
-} //namespace
diff --git a/views/class-metabox-view-base.php b/views/class-metabox-view-base.php
deleted file mode 100644
index ae61fd1..0000000
--- a/views/class-metabox-view-base.php
+++ /dev/null
@@ -1,84 +0,0 @@
-args = $args;
- }
-
- /**
- * Render a metabox.
- *
- * This function serves as the callback for a metabox.
- *
- * @param WP_Post $post The WP post object.
- * @param object $metabox The WP_Metabox object to be rendered.
- * @internal
- * @access public
- * @since WPMVCBase 0.4
- */
- public function render( $post, $metabox ) {
-
- //Is a view file specified for this metabox?
- if ( isset( $metabox['args']['view'] ) ) {
- if ( file_exists( $metabox['args']['view'] ) ) {
-
- //include view for this metabox
- include $metabox['args']['view'];
- return;
- }
-
- if ( ! file_exists( $metabox['args']['view'] ) ) {
- printf(
- __( 'The view file %s for metabox id %s does not exist', 'wpmvcb' ),
- $metabox['args']['view'],
- $metabox['id']
- );
- return;
- }
- }
-
- if ( ! isset( $metabox['args']['view'] ) ) {
- printf(
- __( 'No view specified in the callback arguments for metabox id %s', 'wpmvcb' ),
- $metabox['id']
- );
- return;
- }
-
- }
-
-}
diff --git a/views/class-metabox-view-default.php b/views/class-metabox-view-default.php
deleted file mode 100644
index 920d352..0000000
--- a/views/class-metabox-view-default.php
+++ /dev/null
@@ -1,44 +0,0 @@
-item = $item;
+ parent::__construct( $args );
+
}
+ /**
+ * @param string $template
+ * @param array $args
+ */
public function the_template( $template, $args = array() ) {
$item = $this->item;
+ /**
+ * Yes, we are aware of the dangers of extract. However, this is the
+ * exact intended use of extract(), which enables this library
+ * to emulate the global nature of WordPress variables available in theme templates.
+ */
extract( $args );
if( file_exists( $template ) ) {
- printf( '', str_replace( WP_CONTENT_DIR, 'CONTENT_DIR', $template ) );
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
+ printf( '', str_replace( WP_CONTENT_DIR, 'CONTENT_DIR', $template ) );
+ }
require $template;
}
}
+ /**
+ * @param string $size
+ * @param array $args
+ */
public function the_image( $size = 'full', $args = array() ) {
if ( is_callable( array( $this->item, 'get_image' ) ) ) {
diff --git a/views/class-view-base.php b/views/class-view-base.php
new file mode 100644
index 0000000..af16380
--- /dev/null
+++ b/views/class-view-base.php
@@ -0,0 +1,44 @@
+foo() Return the value of foo fetched from the model
+ * $this->the_foo() Echo the value of foo fetched from the model
+ *
+ * @param string $method
+ * @param array $args
+ *
+ * @return null|mixed
+ */
+ public function __call( $method, $args ) {
+
+ $value = null;
+
+ do {
+ if ( preg_match( '#^the_(.+)?$#', $method ) ) {
+ break;
+ }
+
+ $value = $this->model()->{$method}();
+ } while ( false );
+
+ return $value;
+
+ }
+}
\ No newline at end of file
diff --git a/wpmvcb.php b/wpmvcb.php
index 77ec6d9..0a7c265 100644
--- a/wpmvcb.php
+++ b/wpmvcb.php
@@ -1,4 +1,6 @@
autoload_classes = array(
- 'WPMVC_Controller_Base' => __DIR__ . '/controllers/class-controller-base.php',
- 'WPMVCB_Cpt_Base' => __DIR__ . '/controllers/class-cpt-base.php',
- 'Base_Controller_Plugin' => __DIR__ . '/controllers/class-base-controller-plugin.php',
- 'WPMVCB_Settings_Base' => __DIR__ . '/controllers/class-settings-base.php',
- 'WPMVCB_Taxonomy_Base' => __DIR__ . '/controllers/class-taxonomy-base.php',
- 'WPMVCB_Metabox' => __DIR__ . '/controllers/class-metabox-base.php',
- 'WPMVCB_Model_Base' => __DIR__ . '/models/class-model-base.php',
- 'WPMVCB_Admin_Notice_Model_Base' => __DIR__ . '/models/class-admin-notice-model-base.php',
- 'WPMVCB_Post_Model_Base' => __DIR__ . '/models/class-post-model-base.php',
- 'Base_Model_Help_Tab' => __DIR__ . '/models/class-base-model-help-tab.php',
- 'Base_Model_JS_Object' => __DIR__ . '/models/class-base-model-js-object.php',
- 'WPMVCB_Menu_Page_Model_Base' => __DIR__ . '/models/class-menu-page-model-base.php',
- 'WPMVCB_Metabox_Model_Base' => __DIR__ . '/models/class-metabox-model-base.php',
- 'Base_Model_Plugin' => __DIR__ . '/models/class-base-model-plugin.php',
- 'WPMVCB_Settings_Model_Base' => __DIR__ . '/models/class-settings-model-base.php',
- 'WPMVCB_Taxonomy_Model_Base' => __DIR__ . '/models/class-base-model-taxonomy.php',
- 'WPMVCB_Post_View_Base' => __DIR__ . '/views/class-post-view-base.php',
- 'WPMVCB_Metabox_View_Base' => __DIR__ . '/views/class-metabox-view-base.php',
- 'WPMVCB_Metabox_Default_View' => __DIR__ . '/views/class-metabox-view-default.php',
- 'Helper_Functions' => __DIR__ . '/helpers/class-base-helpers.php',
+ __NAMESPACE__ . '\Base' => __DIR__ . '/includes/class-base.php',
+ __NAMESPACE__ . '\Controller_Base' => __DIR__ . '/controllers/class-controller-base.php',
+ __NAMESPACE__ . '\Post_Type_Base' => __DIR__ . '/controllers/class-post-type-base.php',
+ __NAMESPACE__ . '\Post_Base' => __DIR__ . '/controllers/class-post-base.php',
+// 'Base_Controller_Plugin' => __DIR__ . '/controllers/class-base-controller-plugin.php',
+// 'WPMVCB_Settings_Base' => __DIR__ . '/controllers/class-settings-base.php',
+ __NAMESPACE__ . '\Taxonomy_Base' => __DIR__ . '/controllers/class-taxonomy-base.php',
+// 'WPMVCB_Metabox' => __DIR__ . '/controllers/class-metabox-base.php',
+ __NAMESPACE__ . '\Model_Base' => __DIR__ . '/models/class-model-base.php',
+// 'WPMVCB_Admin_Notice_Model_Base' => __DIR__ . '/models/class-admin-notice-model-base.php',
+ __NAMESPACE__ . '\Post_Model_Base' => __DIR__ . '/models/class-post-model-base.php',
+// 'Base_Model_Help_Tab' => __DIR__ . '/models/class-base-model-help-tab.php',
+// 'Base_Model_JS_Object' => __DIR__ . '/models/class-base-model-js-object.php',
+// 'WPMVCB_Menu_Page_Model_Base' => __DIR__ . '/models/class-menu-page-model-base.php',
+// 'WPMVCB_Metabox_Model_Base' => __DIR__ . '/models/class-metabox-model-base.php',
+// 'Base_Model_Plugin' => __DIR__ . '/models/class-base-model-plugin.php',
+// 'WPMVCB_Settings_Model_Base' => __DIR__ . '/models/class-settings-model-base.php',
+// 'WPMVCB_Taxonomy_Model_Base' => __DIR__ . '/models/class-base-model-taxonomy.php',
+ __NAMESPACE__ . '\Post_View_Base' => __DIR__ . '/views/class-post-view-base.php',
+// 'WPMVCB_Metabox_View_Base' => __DIR__ . '/views/class-metabox-view-base.php',
+// 'WPMVCB_Metabox_Default_View' => __DIR__ . '/views/class-metabox-view-default.php',
+// 'Helper_Functions' => __DIR__ . '/helpers/class-base-helpers.php',
);
spl_autoload_register( array( $this, 'autoloader' ) );
@@ -104,7 +108,7 @@ public function autoloader( $class ) {
if ( isset( $this->autoload_classes[ $class ] ) ) {
if ( file_exists( $this->autoload_classes[ $class ] ) ) {
require_once $this->autoload_classes[ $class ];
- if ( is_callable( "{$class}::on_load" ) ) {
+ if ( is_callable( array( $class, 'on_load') ) ) {
call_user_func( array( $class, 'on_load' ) );
}
}