diff --git a/.gitignore b/.gitignore index 3b6e0170e19d0471d76e24606ef2423f1249f230..0e6ecb9508d9f7d9f78797eb692af3b0a234ef14 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ vendor/ *.sql *.tar.gz *.zip -.php_cs.cache \ No newline at end of file +.php_cs.cache +Tests/plugins/ \ No newline at end of file diff --git a/Tests/Integration/IntegrationTestCase.php b/Tests/Integration/IntegrationTestCase.php index 8a5c71da418dfa670215c1da723b417a69e60393..0a47f4a8ac123d8c088b114ee5e3c551c81437a1 100755 --- a/Tests/Integration/IntegrationTestCase.php +++ b/Tests/Integration/IntegrationTestCase.php @@ -1,7 +1,7 @@ <?php -namespace CalderaLearn\RestSearch\Tests\Integration; +namespace calderawp\CalderaFormsQuery\Tests\Integration; /** * Class IntegrationTestCase diff --git a/Tests/Integration/RestAPITestCase.php b/Tests/Integration/RestAPITestCase.php index 8903dbcc08e77f2c63d71c15ddf1343eec8ccfe9..5088ec91d06c74a58813378db842be21c43c38d2 100755 --- a/Tests/Integration/RestAPITestCase.php +++ b/Tests/Integration/RestAPITestCase.php @@ -1,6 +1,6 @@ <?php -namespace CalderaLearn\RestSearch\Tests\Integration; +namespace calderawp\CalderaFormsQuery\Tests\Integration; // phpcs:disable /** diff --git a/Tests/Integration/RestRequestTest.php b/Tests/Integration/RestRequestTest.php deleted file mode 100755 index 184d4881bac87ea15396b6baf3602896c8213859..0000000000000000000000000000000000000000 --- a/Tests/Integration/RestRequestTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?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' ]); - } - } -} diff --git a/Tests/Integration/TestsTest.php b/Tests/Integration/TestsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..de82c30702234a40314079157b531485ce22604a --- /dev/null +++ b/Tests/Integration/TestsTest.php @@ -0,0 +1,24 @@ +<?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 diff --git a/Tests/Mock/.gitkeep b/Tests/Mock/.gitkeep index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..4287ca8617970fa8fc025b75cb319c7032706910 100644 --- a/Tests/Mock/.gitkeep +++ b/Tests/Mock/.gitkeep @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/Tests/Mock/wpdb.php b/Tests/Mock/wpdb.php index 78c027a5c094496e73f137daaeb7c663ff4aff97..d2a09e0807922ddec6a5a2be284578ba0b0fbf15 100644 --- a/Tests/Mock/wpdb.php +++ b/Tests/Mock/wpdb.php @@ -1,4 +1,7 @@ <?php +if( class_exists( 'wpdb')){ + return; +} //phpcs:disable class wpdb { diff --git a/Tests/bootstrap-integration.php b/Tests/bootstrap-integration.php index 2474e3551016fc10ad313db5ce3be520577c0462..b8d92072b469dab7da458f6d0d339c04e83a4415 100755 --- a/Tests/bootstrap-integration.php +++ b/Tests/bootstrap-integration.php @@ -13,11 +13,12 @@ if (! $_tests_dir) { 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() { require dirname(dirname(__FILE__)) . '/caldera-forms-query.php'; + require __DIR__ . '/plugins/caldera-forms/caldera-core.php'; } tests_add_filter('muplugins_loaded', '_manually_load_plugin'); diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 8c20631ac027f6f19718c5b477c02f4849d94212..6e9dc42650214eaa6dc2577be387cbe11177f23b 100755 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -31,8 +31,9 @@ if (! function_exists('__')) { 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')) { define('OBJECT', 'OBJECT'); define('object', 'OBJECT'); diff --git a/Tests/plugins/.gitkeep b/Tests/plugins/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..4287ca8617970fa8fc025b75cb319c7032706910 --- /dev/null +++ b/Tests/plugins/.gitkeep @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/Tests/plugins/caldera-forms b/Tests/plugins/caldera-forms new file mode 160000 index 0000000000000000000000000000000000000000..3b0a81ff69ed4aaaaa92987c0fff4520e7252f25 --- /dev/null +++ b/Tests/plugins/caldera-forms @@ -0,0 +1 @@ +Subproject commit 3b0a81ff69ed4aaaaa92987c0fff4520e7252f25 diff --git a/caldera-forms-query.php b/caldera-forms-query.php index bb6192896a906e64d7ac96885fc179f07cddb15e..9efda7e0e2ebe576b9febb3d43208dc6885a57de 100644 --- a/caldera-forms-query.php +++ b/caldera-forms-query.php @@ -11,24 +11,10 @@ * */ - include_once __DIR__ .'/vendor/autoload.php'; if( function_exists( 'add_action' ) ){ 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; - - - }); } diff --git a/composer.json b/composer.json index dc74d2e178c18ea9354852143964feb2604cfc7e..3e7ae9fadab49ed079710f868d02110c3d6642ad 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,12 @@ "email": "josh@calderawp.com" } ], + "repositories" : [ + { + "type": "git", + "url" : "git@github.com:CalderaWP/Caldera-Forms.git" + } + ], "require": { "php": ">=5.6", "nilportugues/sql-query-builder": "^1.5" @@ -33,15 +39,19 @@ "psr-4": { "calderawp\\CalderaFormsQuery\\Tests\\": "Tests/" - }, - "files" : [ - "./Tests/Mock/wpdb.php" - ] + } }, "require-dev": { "php": "^7.1", "phpunit/phpunit": "^7.0", "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"] + } } } diff --git a/composer.lock b/composer.lock index e8c1188f434673ff461226d3332592cd85b8f284..d5f6230433af7506f08fa4b54ea0a2fdbd2d3aa7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "db6310436913680c3c5b50bdff00c88c", + "content-hash": "a6eee6d6f3062af42dc7b830f7971dac", "packages": [ { "name": "nilportugues/sql-query-builder", @@ -127,6 +127,154 @@ } ], "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", "version": "1.1.0", @@ -1683,7 +1831,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "desertsnowman/caldera-forms": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": {