-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
952 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
db/migrations/wp_testing/20150324041508_AddSectionsTable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_BaseMigration.php'; | ||
|
||
class AddSectionsTable extends BaseMigration | ||
{ | ||
|
||
public function up() | ||
{ | ||
$this->drop_table(WPT_DB_PREFIX . 'sections'); | ||
$table = $this->create_table(WPT_DB_PREFIX . 'sections', array( | ||
'id' => false, | ||
'options' => 'ENGINE=' . $this->get_wp_table_engine(), | ||
)); | ||
$table->column('section_id', 'biginteger', array( | ||
'unsigned' => true, | ||
'null' => false, | ||
'primary_key' => true, | ||
'auto_increment' => true, | ||
)); | ||
$table->column('test_id', 'biginteger', array( | ||
'unsigned' => true, | ||
'null' => false, | ||
)); | ||
$table->column('question_id', 'biginteger', array( | ||
'unsigned' => true, | ||
'null' => false, | ||
)); | ||
$table->column('section_title', 'text', array( | ||
'null' => false, | ||
)); | ||
$table->finish(); | ||
|
||
$global_prefix = WP_DB_PREFIX; | ||
$plugin_prefix = WPT_DB_PREFIX; | ||
$this->execute(" | ||
ALTER TABLE {$plugin_prefix}sections | ||
ADD CONSTRAINT fk_section_test | ||
FOREIGN KEY (test_id) | ||
REFERENCES {$global_prefix}posts (ID) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
ADD INDEX fk_section_test (test_id), | ||
ADD CONSTRAINT fk_section_question | ||
FOREIGN KEY (question_id) | ||
REFERENCES {$plugin_prefix}questions (question_id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
ADD INDEX fk_section_question (question_id), | ||
ADD UNIQUE INDEX uq_section_test_question (test_id, question_id) | ||
"); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->drop_table(WPT_DB_PREFIX . 'sections'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DELETE FROM wp_posts WHERE 'test 1' = post_title; | ||
|
||
SELECT * FROM wp_posts ORDER BY ID DESC; | ||
|
||
SELECT * FROM wp_term_relationships; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
interface WpTesting_Addon_IAddon extends WpTesting_Component_IRootable | ||
{ | ||
|
||
/** | ||
* @return WpTesting_Addon_IAddon | ||
*/ | ||
public function setWp(WpTesting_Addon_IWordPressFacade $wp); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
interface WpTesting_Addon_IFacade | ||
{ | ||
|
||
/** | ||
* @param WpTesting_Addon_IAddon $addon | ||
* @return WpTesting_Addon_IFacade | ||
*/ | ||
public function registerAddon($addon); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
interface WpTesting_Addon_IWordPressFacade | ||
{ | ||
|
||
/** | ||
* Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. | ||
* @var integer | ||
*/ | ||
const PRIORITY_DEFAULT = 10; | ||
|
||
/** | ||
* Hooks a function on to a specific action. | ||
* | ||
* @since 1.2.0 | ||
* @link http://codex.wordpress.org/Function_Reference/add_action | ||
* | ||
* @param string $tag The name of the action to which the $function is hooked. | ||
* @param callback $function The name of the function you wish to be called. | ||
* @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. | ||
* @param int $functionArgsCount optional. The number of arguments the function accept (default 1). | ||
* @return WpTesting_Addon_IWordPressFacade | ||
*/ | ||
public function addAction($tag, $function, $priority = self::PRIORITY_DEFAULT, $functionArgsCount = 1); | ||
|
||
/** | ||
* Add a meta box to an edit form. | ||
* | ||
* @since 2.5.0 | ||
* | ||
* @param string $id String for use in the 'id' attribute of tags. | ||
* @param string $title Title of the meta box. | ||
* @param callable $function Function that fills the box with the desired content. | ||
* The function should echo its output. | ||
* @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post | ||
* type, 'link', or 'comment'). Default is the current screen. | ||
* @param string $context Optional. The context within the screen where the boxes | ||
* should display. Available contexts vary from screen to | ||
* screen. Post edit screen contexts include 'normal', 'side', | ||
* and 'advanced'. Comments screen contexts include 'normal' | ||
* and 'side'. Menus meta boxes (accordion sections) all use | ||
* the 'side' context. Global default is 'advanced'. | ||
* @param string $priority Optional. The priority within the context where the boxes | ||
* should show ('high', 'low'). Default 'default'. | ||
* @param array $functionArgs Optional. Data that should be set as the $args property | ||
* of the box array (which is the second parameter passed | ||
* to your callback). Default null. | ||
* @return WpTesting_Addon_IWordPressFacade | ||
*/ | ||
public function addMetaBox($id, $title, $function, $screen = null, $context = 'advanced', $priority = 'default', $functionArgs = null); | ||
|
||
/** | ||
* Hooks a function or method to a specific filter action. | ||
* | ||
* @since 0.71 | ||
* | ||
* @param string $tag The name of the action to which the $function is hooked. | ||
* @param callback $function The name of the function you wish to be called. | ||
* @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. | ||
* @param int $functionArgsCount optional. The number of arguments the function accept (default 1). | ||
* @return WpTesting_WordPressFacade | ||
*/ | ||
public function addFilter($tag, $function, $priority = self::PRIORITY_DEFAULT, $functionArgsCount = 1); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
interface WpTesting_Component_IRootable | ||
{ | ||
|
||
/** | ||
* @return string Class name placed in root | ||
*/ | ||
public function getClass(); | ||
|
||
/** | ||
* @return string Absolute path without ending slash | ||
*/ | ||
public function getRoot(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
class WpTesting_Component_Loader | ||
{ | ||
|
||
/** | ||
* Prefix => Dirname | ||
* @var array | ||
*/ | ||
private $prefixToPath = array(); | ||
|
||
private $requiredPrefix = ''; | ||
|
||
public function __construct($requiredPrefix) | ||
{ | ||
$this->requiredPrefix = $requiredPrefix; | ||
spl_autoload_register(array($this, 'autoload')); | ||
} | ||
|
||
public function autoload($class) | ||
{ | ||
if (empty($this->prefixToPath) || false === strpos($class, $this->requiredPrefix)) { | ||
return; | ||
} | ||
$prefix = $this->getPrefix($class); | ||
if (!isset($this->prefixToPath[$prefix])) { | ||
return; | ||
} | ||
$path = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; | ||
$path = str_replace($prefix, $this->prefixToPath[$prefix], $path); | ||
require_once $path; | ||
} | ||
|
||
/** | ||
* @param WpTesting_Component_IRootable $rootable | ||
* @return WpTesting_Component_Loader | ||
*/ | ||
public function addPrefixPath($rootable) | ||
{ | ||
$this->prefixToPath[$this->getPrefix($rootable->getClass())] = $rootable->getRoot(); | ||
return $this; | ||
} | ||
|
||
private function getPrefix($class) | ||
{ | ||
return substr($class, 0, strpos($class, '_')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.