Skip to content
Snippets Groups Projects
Commit 92413f65 authored by Josh Pollock's avatar Josh Pollock
Browse files

get integration tests working with Caldera Forms

parent 1d129def
No related branches found
No related tags found
No related merge requests found
...@@ -6,4 +6,5 @@ vendor/ ...@@ -6,4 +6,5 @@ vendor/
*.sql *.sql
*.tar.gz *.tar.gz
*.zip *.zip
.php_cs.cache .php_cs.cache
\ No newline at end of file Tests/plugins/
\ No newline at end of file
<?php <?php
namespace CalderaLearn\RestSearch\Tests\Integration; namespace calderawp\CalderaFormsQuery\Tests\Integration;
/** /**
* Class IntegrationTestCase * Class IntegrationTestCase
......
<?php <?php
namespace CalderaLearn\RestSearch\Tests\Integration; namespace calderawp\CalderaFormsQuery\Tests\Integration;
// phpcs:disable // phpcs:disable
/** /**
......
<?php
namespace CalderaLearn\RestSearch\Tests\Integration;
use CalderaLearn\RestSearch\FilterWPQuery;
use CalderaLearn\RestSearch\Tests\Mock\AlwaysFilterWPQuery;
class RestRequestTest extends RestAPITestCase
{
/**
* Ensures that REST API requests will be filtered
*
* @covers FilterWPQuery::callback()
*/
public function testShouldFilter()
{
//Create a request
$request = new \WP_REST_Request('GET', '/wp/v2/posts');
rest_api_loaded();
//Make sure the method returns true
$this->assertTrue(FilterWPQuery::shouldFilter());
}
/**
* Ensure that REST API response data was correctly altered
*
* @covers FilterWPQuery::shouldFilter();
* @covers FilterWPQuery::callback()
*/
public function testFilteringRESTRequest()
{
//Setup filter
AlwaysFilterWPQuery::addFilter();
$this->assertTrue(AlwaysFilterWPQuery::shouldFilter());
//Create a request
$request = new \WP_REST_Request('GET', '/wp/v2/posts');
//Dispatch request
$response = rest_get_server()->dispatch($request);
//Test response status
$this->assertSame(200, $response->get_status());
//Test the response data
//Use the mock data we have in our mock class as the expected values
$expected = FilterWPQuery::getPosts();
//Test that the expected results and the actual results are the same
$responseData = $response->get_data();
$this->assertTrue(is_array($responseData));
$this->assertSame(count($expected), count($responseData));
foreach ($responseData as $i => $responsePost) {
$this->assertTrue(isset($expected[$i]));
$this->assertSame($expected[$i]->post_title, $responsePost[ 'title' ][ 'rendered' ]);
}
}
}
<?php
namespace calderawp\CalderaFormsQuery\Tests\Integration;
/**
* Class TestsTest
*
* Tests to ensure integration test environment is working
* @package calderawp\CalderaFormsQuery\Tests\Integration
*/
class TestsTest extends IntegrationTestCase
{
/**
* Check that Caldera Forms is usable
*/
public function testCalderaFormsIsInstalled()
{
$this->assertTrue( defined( 'CFCORE_VER' ) );
$this->assertTrue( class_exists( '\Caldera_Forms' ) );
}
}
\ No newline at end of file
#
\ No newline at end of file
<?php <?php
if( class_exists( 'wpdb')){
return;
}
//phpcs:disable //phpcs:disable
class wpdb class wpdb
{ {
......
...@@ -13,11 +13,12 @@ if (! $_tests_dir) { ...@@ -13,11 +13,12 @@ if (! $_tests_dir) {
require_once $_tests_dir . '/includes/functions.php'; require_once $_tests_dir . '/includes/functions.php';
/** /**
* Manually load the plugin being tested. * Manually load the plugin being tested and plugins it depends on
*/ */
function _manually_load_plugin() function _manually_load_plugin()
{ {
require dirname(dirname(__FILE__)) . '/caldera-forms-query.php'; require dirname(dirname(__FILE__)) . '/caldera-forms-query.php';
require __DIR__ . '/plugins/caldera-forms/caldera-core.php';
} }
tests_add_filter('muplugins_loaded', '_manually_load_plugin'); tests_add_filter('muplugins_loaded', '_manually_load_plugin');
......
...@@ -31,8 +31,9 @@ if (! function_exists('__')) { ...@@ -31,8 +31,9 @@ if (! function_exists('__')) {
return translate($text, $domain); return translate($text, $domain);
} }
} }
//Mock WPDB (not using autoloader so it doesn't load during integration tests
include_once __DIR__ . '/Mock/wpdb.php';
//WordPress WPDB constants
if ( ! defined( 'ARRAY_A')) { if ( ! defined( 'ARRAY_A')) {
define('OBJECT', 'OBJECT'); define('OBJECT', 'OBJECT');
define('object', 'OBJECT'); define('object', 'OBJECT');
......
#
\ No newline at end of file
caldera-forms @ 3b0a81ff
Subproject commit 3b0a81ff69ed4aaaaa92987c0fff4520e7252f25
...@@ -11,24 +11,10 @@ ...@@ -11,24 +11,10 @@
* *
*/ */
include_once __DIR__ .'/vendor/autoload.php'; include_once __DIR__ .'/vendor/autoload.php';
if( function_exists( 'add_action' ) ){ if( function_exists( 'add_action' ) ){
add_action( 'caldera_forms_includes_complete', function(){ add_action( 'caldera_forms_includes_complete', function(){
$x= 1;
$entry = new \calderawp\CalderaFormsQuery\Select\Entry(
new \calderawp\CalderaFormsQuery\MySqlBuilder(),
'wp_cf_form_entries'
);
$entry->queryByFormsId( 'cf12345' );
$entry->addOrderBy( 'form_id', false );
$sql = $entry->getPreparedSql();
$x= 1;
}); });
} }
......
...@@ -9,6 +9,12 @@ ...@@ -9,6 +9,12 @@
"email": "josh@calderawp.com" "email": "josh@calderawp.com"
} }
], ],
"repositories" : [
{
"type": "git",
"url" : "git@github.com:CalderaWP/Caldera-Forms.git"
}
],
"require": { "require": {
"php": ">=5.6", "php": ">=5.6",
"nilportugues/sql-query-builder": "^1.5" "nilportugues/sql-query-builder": "^1.5"
...@@ -33,15 +39,19 @@ ...@@ -33,15 +39,19 @@
"psr-4": { "psr-4": {
"calderawp\\CalderaFormsQuery\\Tests\\": "Tests/" "calderawp\\CalderaFormsQuery\\Tests\\": "Tests/"
}, }
"files" : [
"./Tests/Mock/wpdb.php"
]
}, },
"require-dev": { "require-dev": {
"php": "^7.1", "php": "^7.1",
"phpunit/phpunit": "^7.0", "phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^3.2", "squizlabs/php_codesniffer": "^3.2",
"jakub-onderka/php-parallel-lint": "^1.0" "jakub-onderka/php-parallel-lint": "^1.0",
"Desertsnowman/caldera-forms": "dev-develop",
"composer/installers": "~1.0"
},
"extra" : {
"installer-paths" : {
"Tests/plugins/{$name}/" : ["type:wordpress-plugin"]
}
} }
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "db6310436913680c3c5b50bdff00c88c", "content-hash": "a6eee6d6f3062af42dc7b830f7971dac",
"packages": [ "packages": [
{ {
"name": "nilportugues/sql-query-builder", "name": "nilportugues/sql-query-builder",
...@@ -127,6 +127,154 @@ ...@@ -127,6 +127,154 @@
} }
], ],
"packages-dev": [ "packages-dev": [
{
"name": "Desertsnowman/caldera-forms",
"version": "dev-develop",
"source": {
"type": "git",
"url": "git@github.com:CalderaWP/Caldera-Forms.git",
"reference": "3b0a81ff69ed4aaaaa92987c0fff4520e7252f25"
},
"type": "wordpress-plugin",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "David Cramer",
"homepage": "http://cramer.co.za",
"role": "Lead Developer"
}
],
"description": "Create complex grid based, responsive forms easily with an easy to use drag and drop layout builder",
"homepage": "http://calderaforms.com",
"keywords": [
"caldera",
"forms",
"wordpress"
],
"time": "2018-04-03T13:13:16+00:00"
},
{
"name": "composer/installers",
"version": "v1.5.0",
"source": {
"type": "git",
"url": "https://github.com/composer/installers.git",
"reference": "049797d727261bf27f2690430d935067710049c2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/installers/zipball/049797d727261bf27f2690430d935067710049c2",
"reference": "049797d727261bf27f2690430d935067710049c2",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0"
},
"replace": {
"roundcube/plugin-installer": "*",
"shama/baton": "*"
},
"require-dev": {
"composer/composer": "1.0.*@dev",
"phpunit/phpunit": "^4.8.36"
},
"type": "composer-plugin",
"extra": {
"class": "Composer\\Installers\\Plugin",
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\Installers\\": "src/Composer/Installers"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kyle Robinson Young",
"email": "kyle@dontkry.com",
"homepage": "https://github.com/shama"
}
],
"description": "A multi-framework Composer library installer",
"homepage": "https://composer.github.io/installers/",
"keywords": [
"Craft",
"Dolibarr",
"Eliasis",
"Hurad",
"ImageCMS",
"Kanboard",
"Lan Management System",
"MODX Evo",
"Mautic",
"Maya",
"OXID",
"Plentymarkets",
"Porto",
"RadPHP",
"SMF",
"Thelia",
"WolfCMS",
"agl",
"aimeos",
"annotatecms",
"attogram",
"bitrix",
"cakephp",
"chef",
"cockpit",
"codeigniter",
"concrete5",
"croogo",
"dokuwiki",
"drupal",
"eZ Platform",
"elgg",
"expressionengine",
"fuelphp",
"grav",
"installer",
"itop",
"joomla",
"kohana",
"laravel",
"lavalite",
"lithium",
"magento",
"majima",
"mako",
"mediawiki",
"modulework",
"modx",
"moodle",
"osclass",
"phpbb",
"piwik",
"ppi",
"puppet",
"pxcms",
"reindex",
"roundcube",
"shopware",
"silverstripe",
"sydes",
"symfony",
"typo3",
"wordpress",
"yawik",
"zend",
"zikula"
],
"time": "2017-12-29T09:13:20+00:00"
},
{ {
"name": "doctrine/instantiator", "name": "doctrine/instantiator",
"version": "1.1.0", "version": "1.1.0",
...@@ -1683,7 +1831,9 @@ ...@@ -1683,7 +1831,9 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"desertsnowman/caldera-forms": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment