initial
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Gravity_Forms\Gravity_Tools\Utils\GeoData;
|
||||
|
||||
class GeoDataTest extends TestCase {
|
||||
|
||||
public function testCountriesDataIsProperlyFormatted() {
|
||||
$countries_data = GeoData::countries();
|
||||
// Countries data should be an array
|
||||
$this->assertTrue( is_array( $countries_data ) );
|
||||
|
||||
// Countries data should contain known keys
|
||||
$this->assertTrue( array_key_exists( 'US', $countries_data ) );
|
||||
$this->assertTrue( array_key_exists( 'CA', $countries_data ) );
|
||||
|
||||
// Countries data values should be translated
|
||||
$this->assertEquals( $countries_data['AU'], 'Australia');
|
||||
}
|
||||
|
||||
public function testCountriesDataCanBeTransformed() {
|
||||
$transform_callback = function( $items ) {
|
||||
foreach( $items as $key => $value ) {
|
||||
$items[ $key ] = 'OVERRIDDEN';
|
||||
}
|
||||
|
||||
return $items;
|
||||
};
|
||||
$countries_data = GeoData::countries( false, $transform_callback );
|
||||
|
||||
$this->assertEquals( $countries_data['AF'], 'OVERRIDDEN' );
|
||||
}
|
||||
|
||||
public function testDataReturnsJson() {
|
||||
$countries_data = GeoData::countries( true );
|
||||
$this->assertTrue( is_string( $countries_data ) );
|
||||
$this->assertFalse( is_array( $countries_data ) );
|
||||
|
||||
$countries_data = json_decode( $countries_data, true );
|
||||
|
||||
$this->assertEquals( $countries_data['AU'], 'Australia' );
|
||||
}
|
||||
|
||||
public function testPhoneDataReturns() {
|
||||
$phone_data = GeoData::phone_info();
|
||||
$this->assertTrue( is_array( $phone_data ) );
|
||||
$first_value = $phone_data[0];
|
||||
|
||||
$this->assertEquals( $first_value['iso'], 'AF' );
|
||||
$this->assertEquals( $first_value['calling_code'], '93' );
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Gravity_Forms\Gravity_Tools\Service_Container;
|
||||
use Gravity_Forms\Gravity_Tools\Service_Provider;
|
||||
|
||||
class ServiceContainerTest extends TestCase {
|
||||
|
||||
public function testServiceIsAdded() {
|
||||
$container = new Service_Container();
|
||||
$service = array( 'foo', 'bar' );
|
||||
$service_name = 'test_service';
|
||||
|
||||
$container->add( $service_name, $service );
|
||||
|
||||
$this->assertSame( $container->get( $service_name ), $service );
|
||||
}
|
||||
|
||||
public function testServiceIsAddedDeferred() {
|
||||
global $foo;
|
||||
$foo = 'before';
|
||||
$container = new Service_Container();
|
||||
|
||||
$container->add( 'foo_service', function() {
|
||||
global $foo;
|
||||
$foo = 'after';
|
||||
}, true );
|
||||
|
||||
$this->assertEquals( 'before', $foo );
|
||||
|
||||
$container->get( 'foo_service' );
|
||||
|
||||
$this->assertEquals( 'after', $foo );
|
||||
}
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
hero {
|
||||
name
|
||||
metricHeight: height(format: METRIC)
|
||||
mainFriends: friends {
|
||||
id(format: INT)
|
||||
date
|
||||
secondaryFriends: friends(created_gt: 11/12/2023) {
|
||||
created_at
|
||||
website
|
||||
tertiaryFriends: friends {
|
||||
email
|
||||
phone
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+2721
File diff suppressed because it is too large
Load Diff
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
contact {
|
||||
first_name,
|
||||
main_email: email,
|
||||
phone,
|
||||
phone_two: secondary_phone
|
||||
friends: contact {
|
||||
first_name
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
group {
|
||||
name: label,
|
||||
employees: contact {
|
||||
first_name,
|
||||
lname: last_name,
|
||||
phone_two: secondary_phone
|
||||
}
|
||||
},
|
||||
company: group {
|
||||
name: label,
|
||||
employees: contact {
|
||||
first_name,
|
||||
lname: last_name,
|
||||
phone_two: secondary_phone
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+279
@@ -0,0 +1,279 @@
|
||||
SET NAMES utf8;
|
||||
SET time_zone = '+00:00';
|
||||
SET foreign_key_checks = 0;
|
||||
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_address`;
|
||||
CREATE TABLE `wp_gravitycrm_address` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`type` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`lineOne` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`lineTwo` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`city` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`state` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
|
||||
`country` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`postalCode` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`isPrimary` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`contactId` mediumint DEFAULT NULL,
|
||||
`companyId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `lineOne` (`lineOne`),
|
||||
FULLTEXT KEY `lineTwo` (`lineTwo`),
|
||||
FULLTEXT KEY `city` (`city`),
|
||||
FULLTEXT KEY `state` (`state`),
|
||||
FULLTEXT KEY `country` (`country`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_address` (`id`, `type`, `lineOne`, `lineTwo`, `city`, `state`, `country`, `postalCode`, `isPrimary`, `contactId`, `companyId`, `dateCreated`, `dateUpdated`) VALUES
|
||||
(1, '', '123 Street St', '', 'City', 'NY', 'US', '55555', 0, NULL, 1, '2025-10-02 19:01:17', '2025-10-02 19:01:17'),
|
||||
(2, '', '123 B Street', '', 'City', 'NY', 'US', '55555', 0, NULL, 2, '2025-10-02 19:01:36', '2025-10-02 19:01:36');
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_company`;
|
||||
CREATE TABLE `wp_gravitycrm_company` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`companyName` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`companyLogo` mediumint DEFAULT NULL,
|
||||
`companyBanner` mediumint DEFAULT NULL,
|
||||
`description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`source` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `companyName` (`companyName`),
|
||||
FULLTEXT KEY `description` (`description`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_company` (`id`, `companyName`, `companyLogo`, `companyBanner`, `description`, `source`, `dateCreated`, `dateUpdated`) VALUES
|
||||
(1, 'Company A', 0, NULL, '', NULL, '2025-10-02 18:58:25', '2025-10-02 18:58:25'),
|
||||
(2, 'Company B', 0, NULL, '', NULL, '2025-10-02 18:59:12', '2025-10-02 18:59:12');
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_company_contact`;
|
||||
CREATE TABLE `wp_gravitycrm_company_contact` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`company_id` mediumint NOT NULL,
|
||||
`contact_id` mediumint NOT NULL,
|
||||
`isMain` tinyint(1) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_company_contact` (`id`, `company_id`, `contact_id`, `isMain`) VALUES
|
||||
(1, 1, 1, 0),
|
||||
(2, 1, 2, 0),
|
||||
(3, 2, 3, 0);
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_contact`;
|
||||
CREATE TABLE `wp_gravitycrm_contact` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`firstName` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`lastName` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`jobTitle` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`contactAvatar` mediumint DEFAULT NULL,
|
||||
`contactBanner` mediumint DEFAULT NULL,
|
||||
`source` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `firstName` (`firstName`),
|
||||
FULLTEXT KEY `lastName` (`lastName`),
|
||||
FULLTEXT KEY `jobTitle` (`jobTitle`),
|
||||
FULLTEXT KEY `description` (`description`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_contact` (`id`, `firstName`, `lastName`, `jobTitle`, `description`, `contactAvatar`, `contactBanner`, `source`, `dateCreated`, `dateUpdated`) VALUES
|
||||
(1, 'Jane', 'Smith', '', '', 0, NULL, NULL, '2025-10-02 18:59:50', '2025-10-02 18:59:50'),
|
||||
(2, 'John', 'Smith', '', '', 0, NULL, NULL, '2025-10-02 19:00:12', '2025-10-02 19:00:12'),
|
||||
(3, 'Rob', 'Carlin', '', '', 0, NULL, NULL, '2025-10-02 19:00:41', '2025-10-02 19:00:41');
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_deal`;
|
||||
CREATE TABLE `wp_gravitycrm_deal` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`label` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`source` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`value` bigint NOT NULL,
|
||||
`estimatedCloseDate` bigint DEFAULT NULL,
|
||||
`notes` mediumtext COLLATE utf8mb4_unicode_520_ci,
|
||||
`attachments` mediumtext COLLATE utf8mb4_unicode_520_ci,
|
||||
`previousNeighbor` mediumint DEFAULT '0',
|
||||
`pipelineId` mediumint DEFAULT NULL,
|
||||
`stageId` mediumint DEFAULT NULL,
|
||||
`userId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `label` (`label`),
|
||||
FULLTEXT KEY `notes` (`notes`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_deal_company`;
|
||||
CREATE TABLE `wp_gravitycrm_deal_company` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`deal_id` mediumint NOT NULL,
|
||||
`company_id` mediumint NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_deal_contact`;
|
||||
CREATE TABLE `wp_gravitycrm_deal_contact` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`deal_id` mediumint NOT NULL,
|
||||
`contact_id` mediumint NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_email`;
|
||||
CREATE TABLE `wp_gravitycrm_email` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`type` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`address` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`isPrimary` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`contactId` mediumint DEFAULT NULL,
|
||||
`companyId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `address` (`address`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_email` (`id`, `type`, `address`, `isPrimary`, `contactId`, `companyId`, `dateCreated`, `dateUpdated`) VALUES
|
||||
(1, '', 'support@companya.local', 0, NULL, 1, '2025-10-02 18:58:25', '2025-10-02 18:58:25'),
|
||||
(2, '', 'feedback@companya.local', 0, NULL, 1, '2025-10-02 18:58:25', '2025-10-02 18:58:25'),
|
||||
(3, '', 'foo@companyb.local', 0, NULL, 2, '2025-10-02 18:59:12', '2025-10-02 18:59:12'),
|
||||
(4, '', 'bar@companyb.local', 0, NULL, 2, '2025-10-02 18:59:12', '2025-10-02 18:59:12'),
|
||||
(5, '', 'jane@companya.local', 0, 1, NULL, '2025-10-02 18:59:50', '2025-10-02 18:59:50'),
|
||||
(6, '', 'john@companya.local', 0, 2, NULL, '2025-10-02 19:00:12', '2025-10-02 19:00:12'),
|
||||
(7, '', 'rob@companyb.local', 0, 3, NULL, '2025-10-02 19:00:41', '2025-10-02 19:00:41');
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_file`;
|
||||
CREATE TABLE `wp_gravitycrm_file` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`path` mediumtext COLLATE utf8mb4_unicode_520_ci,
|
||||
`fileName` mediumtext COLLATE utf8mb4_unicode_520_ci,
|
||||
`extension` tinytext COLLATE utf8mb4_unicode_520_ci,
|
||||
`size` int DEFAULT NULL,
|
||||
`dealId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_meta`;
|
||||
CREATE TABLE `wp_gravitycrm_meta` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`object_type` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`object_id` mediumint NOT NULL,
|
||||
`meta_name` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`meta_value` mediumtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `meta_value` (`meta_value`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_note`;
|
||||
CREATE TABLE `wp_gravitycrm_note` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`contents` mediumtext COLLATE utf8mb4_unicode_520_ci,
|
||||
`userId` mediumint DEFAULT NULL,
|
||||
`dealId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `contents` (`contents`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_phone`;
|
||||
CREATE TABLE `wp_gravitycrm_phone` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`type` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`number` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`countryCode` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`isPrimary` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`contactId` mediumint DEFAULT NULL,
|
||||
`companyId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `number` (`number`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_phone` (`id`, `type`, `number`, `countryCode`, `isPrimary`, `contactId`, `companyId`, `dateCreated`, `dateUpdated`) VALUES
|
||||
(1, '', '14445556666', 'US', 0, NULL, 1, '2025-10-02 18:58:25', '2025-10-02 18:58:25'),
|
||||
(2, '', '12223334444', 'US', 0, NULL, 1, '2025-10-02 18:58:25', '2025-10-02 18:58:25'),
|
||||
(3, '', '18887776666', 'US', 0, NULL, 2, '2025-10-02 18:59:12', '2025-10-02 18:59:12'),
|
||||
(4, '', '19998887777', 'US', 0, NULL, 2, '2025-10-02 18:59:12', '2025-10-02 18:59:12'),
|
||||
(5, '', '19998887777', 'US', 0, 1, NULL, '2025-10-02 18:59:50', '2025-10-02 18:59:50'),
|
||||
(6, '', '18887779797', 'US', 0, 2, NULL, '2025-10-02 19:00:12', '2025-10-02 19:00:12'),
|
||||
(7, '', '17776668686', 'US', 0, 3, NULL, '2025-10-02 19:00:41', '2025-10-02 19:00:41');
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_pipeline`;
|
||||
CREATE TABLE `wp_gravitycrm_pipeline` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`label` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`source` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `label` (`label`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_social`;
|
||||
CREATE TABLE `wp_gravitycrm_social` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`platform` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`identifier` varchar(300) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`isPrimary` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`contactId` mediumint DEFAULT NULL,
|
||||
`companyId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `identifier` (`identifier`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_social` (`id`, `platform`, `identifier`, `isPrimary`, `contactId`, `companyId`, `dateCreated`, `dateUpdated`) VALUES
|
||||
(1, 'instagram', 'companyb', 0, NULL, 2, '2025-10-02 19:01:48', '2025-10-02 19:01:48'),
|
||||
(2, 'instagram', 'companya', 0, NULL, 1, '2025-10-02 19:02:02', '2025-10-02 19:02:02');
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_stage`;
|
||||
CREATE TABLE `wp_gravitycrm_stage` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`label` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`labelStyle` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`pipelineId` mediumint DEFAULT NULL,
|
||||
`previousNeighbor` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `label` (`label`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `wp_gravitycrm_website`;
|
||||
CREATE TABLE `wp_gravitycrm_website` (
|
||||
`id` mediumint NOT NULL AUTO_INCREMENT,
|
||||
`type` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`url` varchar(300) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`isPrimary` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`contactId` mediumint DEFAULT NULL,
|
||||
`companyId` mediumint DEFAULT NULL,
|
||||
`dateCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`dateUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`id`),
|
||||
FULLTEXT KEY `url` (`url`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
||||
|
||||
INSERT INTO `wp_gravitycrm_website` (`id`, `type`, `url`, `isPrimary`, `contactId`, `companyId`, `dateCreated`, `dateUpdated`) VALUES
|
||||
(1, '', 'https://companya.local', 0, NULL, 1, '2025-10-02 18:58:25', '2025-10-02 18:58:25'),
|
||||
(2, '', 'https://companyb.local', 0, NULL, 2, '2025-10-02 18:59:12', '2025-10-02 18:59:12');
|
||||
|
||||
-- 2025-10-02 19:05:09 UTC
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace emails;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Emails\Email_Templatizer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EmailTemplatizerTest extends TestCase {
|
||||
|
||||
public function testTokenReplacement() {
|
||||
$markup = '<div>{{ foo }} <span>{{ bar.0.bash }}</span></div>';
|
||||
$data = array(
|
||||
'foo' => 'Hey this is foo.',
|
||||
'bar' => array(
|
||||
array(
|
||||
'bash' => 'And this is bash.',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$templatizer = new Email_Templatizer( $markup );
|
||||
|
||||
$result = $templatizer->render( $data );
|
||||
|
||||
$this->assertEquals( '<div>Hey this is foo. <span>And this is bash.</span></div>', $result );
|
||||
}
|
||||
|
||||
public function testConditionals() {
|
||||
$markup = '<div>
|
||||
<span>Hey there</span>
|
||||
{{|if stats.recipients.0 |}}
|
||||
This should only be rendered if recipient 1 exists.
|
||||
{{|endif|}}
|
||||
|
||||
{{|if stats.recipients.1 |}}
|
||||
This should only be rendered if recipient 2 exists.
|
||||
{{|endif|}}
|
||||
</div>';
|
||||
|
||||
$data = array(
|
||||
'stats' => array(
|
||||
'recipients' => array(
|
||||
array(
|
||||
'foo' => 'bar',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$templatizer = new Email_Templatizer( $markup );
|
||||
|
||||
$result = $templatizer->render( $data );
|
||||
|
||||
$this->assertTrue( strpos( $result, 'recipient 1' ) !== false );
|
||||
$this->assertTrue( strpos( $result, 'recipient 2' ) === false );
|
||||
}
|
||||
|
||||
public function testLoops() {
|
||||
$markup = '
|
||||
{{|if stats.vendors |}}
|
||||
Should not appear
|
||||
{{|endif|}}
|
||||
|
||||
{{|for recipient in stats.recipients |}}
|
||||
|
||||
<div>
|
||||
<h1>{{ recipient.name }}</h1>
|
||||
<p>You have requested {{ frequency }} digests per week.</p>
|
||||
</div>
|
||||
|
||||
{{|endfor|}}';
|
||||
|
||||
$template = new Email_Templatizer( $markup );
|
||||
|
||||
$data = array(
|
||||
'frequency' => 10,
|
||||
'stats' => array(
|
||||
'recipients' => array(
|
||||
array(
|
||||
'name' => 'Bob',
|
||||
),
|
||||
array(
|
||||
'name' => 'Jim',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$rendered = $template->render( $data );
|
||||
|
||||
$this->assertTrue( strpos( $rendered, 'Bob' ) !== false );
|
||||
$this->assertTrue( strpos( $rendered, 'Jim' ) !== false );
|
||||
$this->assertTrue( strpos( $rendered, 'Should not appear' ) === false );
|
||||
}
|
||||
}
|
||||
+398
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
namespace hermes;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Enum\Field_Type_Validation_Enum;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Mutation_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Query_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Connect_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Delete_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Disconnect_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Insert_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Schema_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Update_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Query_Token;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Utils\Model_Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use tad\FunctionMocker\FunctionMocker;
|
||||
|
||||
global $wpdb;
|
||||
|
||||
class HandlerTest extends TestCase {
|
||||
|
||||
protected $model_collection;
|
||||
protected $contact_model;
|
||||
protected $group_model;
|
||||
protected $query_handler;
|
||||
protected $mutation_handler;
|
||||
protected $db_namespace;
|
||||
protected $deal_model;
|
||||
protected $stage_model;
|
||||
protected $company_model;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->model_collection = new Model_Collection();
|
||||
$this->contact_model = new \FakeContactModel();
|
||||
$this->group_model = new \FakeGroupModel();
|
||||
$this->company_model = new \FakeCompanyModel();
|
||||
$this->deal_model = new \FakeDealModel();
|
||||
$this->stage_model = new \FakeStageModel();
|
||||
|
||||
$this->model_collection->add( 'contact', $this->contact_model );
|
||||
$this->model_collection->add( 'group', $this->group_model );
|
||||
$this->model_collection->add( 'deal', $this->deal_model );
|
||||
$this->model_collection->add( 'stage', $this->stage_model );
|
||||
$this->model_collection->add( 'company', $this->company_model );
|
||||
$this->db_namespace = 'gravitycrm';
|
||||
|
||||
$schema_runner = new Schema_Runner( $this->model_collection );
|
||||
$this->query_handler = new Query_Handler( $this->db_namespace, $this->model_collection, $schema_runner );
|
||||
|
||||
$runners = array(
|
||||
'insert' => new Insert_Runner( $this->db_namespace, $this->query_handler, $this->model_collection, new Connect_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ) ),
|
||||
'delete' => new Delete_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ),
|
||||
'connect' => new Connect_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ),
|
||||
'update' => new Update_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ),
|
||||
'disconnect' => new Disconnect_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ),
|
||||
);
|
||||
|
||||
$this->mutation_handler = new Mutation_Handler( $this->db_namespace, $this->model_collection, $this->query_handler, $runners );
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @dataProvider mutationHandlerProvider
|
||||
// *
|
||||
// * @param $text
|
||||
// * @param $expected
|
||||
// *
|
||||
// * @return void
|
||||
// */
|
||||
// public function testMutationHandler( $text, $expected ) {
|
||||
//
|
||||
// try {
|
||||
// $data = $this->mutation_handler->handle_mutation( $text );
|
||||
// } catch ( \Exception $e ) {
|
||||
// $this->assertEquals( $expected, 'failure' );
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// $this->assertEquals( $expected, 'success' );
|
||||
// }
|
||||
//
|
||||
// public function mutationHandlerProvider() {
|
||||
// return array(
|
||||
// // Valid
|
||||
// array(
|
||||
// '{
|
||||
// insert_contact(objects: [{firstName: "Foo", lastName: "Bar"}, {firstName: "Bing", lastName: "Bash", secondary_phone: "4445554848" }]) {
|
||||
// returning {
|
||||
// id,
|
||||
// firstName,
|
||||
// lastName,
|
||||
// secondary_phone,
|
||||
// }
|
||||
// }
|
||||
// }',
|
||||
// 'success',
|
||||
// ),
|
||||
//
|
||||
// // Invalid custom callback
|
||||
// array(
|
||||
// '{
|
||||
// insert_contact(objects: [{foobar: "bar", firstName: true, lastName: "Bar"}, {firstName: "Bing", lastName: "Bash", secondary_phone: "4445554848" }]) {
|
||||
// returning {
|
||||
// id,
|
||||
// firstName,
|
||||
// lastName,
|
||||
// secondary_phone,
|
||||
// }
|
||||
// }
|
||||
// }',
|
||||
// 'failure',
|
||||
// ),
|
||||
//
|
||||
// // Valid update
|
||||
// array(
|
||||
// '{
|
||||
// update_contact(id: 1, firstName: "Foo", lastName: "Bar", secondary_phone: "4445554848") {
|
||||
// returning {
|
||||
// id,
|
||||
// firstName,
|
||||
// lastName,
|
||||
// secondary_phone,
|
||||
// }
|
||||
// }
|
||||
// }',
|
||||
// 'success',
|
||||
// ),
|
||||
//
|
||||
// // Update missing ID
|
||||
// array(
|
||||
// '{
|
||||
// update_contact( firstName: "Foo", lastName: "Bar", secondary_phone: "4445554848") {
|
||||
// returning {
|
||||
// id,
|
||||
// firstName,
|
||||
// lastName,
|
||||
// secondary_phone,
|
||||
// }
|
||||
// }
|
||||
// }',
|
||||
// 'failure',
|
||||
// ),
|
||||
//
|
||||
// // Delete
|
||||
// array(
|
||||
// '{
|
||||
// delete_contact(id: 1) {
|
||||
// }
|
||||
// }',
|
||||
// 'success',
|
||||
// ),
|
||||
//
|
||||
// // Delete missing ID
|
||||
// array(
|
||||
// '{
|
||||
// delete_contact() {
|
||||
// }
|
||||
// }',
|
||||
// 'failure',
|
||||
// ),
|
||||
//
|
||||
// // Delete missing valid object type
|
||||
// array(
|
||||
// '{
|
||||
// delete_invalid_object(id: 1) {
|
||||
// }
|
||||
// }',
|
||||
// 'failure',
|
||||
// ),
|
||||
//
|
||||
// // Connect with only one connection
|
||||
// array(
|
||||
// '{
|
||||
// connect_group_contact(from: 1, to: 2) {
|
||||
// }
|
||||
// }',
|
||||
// 'success',
|
||||
// ),
|
||||
//
|
||||
// // Connect with only one connection as an array
|
||||
// array(
|
||||
// '{
|
||||
// connect_group_contact([{from:1, to: 2}])
|
||||
// }',
|
||||
// 'success',
|
||||
// ),
|
||||
//
|
||||
// // Connect with multiple connections as an array
|
||||
// array(
|
||||
// '{
|
||||
// connect_group_contact([{from:1, to: 2}, {from:1, to:3}])
|
||||
// }',
|
||||
// 'success',
|
||||
// ),
|
||||
//
|
||||
// array(
|
||||
// '{
|
||||
// disconnect_group_contact([{from:1, to: 2}, {from:1, to:3}])
|
||||
// }',
|
||||
// 'success'
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// public function testInsertMutation() {
|
||||
// global $wpdb;
|
||||
// \gravitytools_tests_reset_db();
|
||||
//
|
||||
// $text = '{
|
||||
// insert_contact(objects: [{firstName: "Foo", lastName: "Bar"}, {firstName: "Bing", lastName: "Bash", secondary_phone: "4445554848" }]) {
|
||||
// returning {
|
||||
// id,
|
||||
// firstName,
|
||||
// lastName,
|
||||
// secondary_phone,
|
||||
// }
|
||||
// }
|
||||
// }';
|
||||
//
|
||||
// $this->mutation_handler->handle_mutation( $text );
|
||||
// $table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'contact' );
|
||||
// $meta_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'meta' );
|
||||
//
|
||||
// $check_query = sprintf( 'SELECT * FROM %s', $table_name );
|
||||
// $results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
//
|
||||
// $this->assertEquals( 2, count( $results ) );
|
||||
//
|
||||
// $record = $results[1];
|
||||
//
|
||||
// $this->assertEquals( 'Bing', $record['firstName'] );
|
||||
//
|
||||
// $meta_check_query = sprintf( 'SELECT meta_value FROM %s WHERE object_id = "%s" AND meta_name = "%s"', $meta_table_name, $record['id'], 'secondary_phone' );
|
||||
// $meta_results = $wpdb->get_results( $meta_check_query, ARRAY_A );
|
||||
//
|
||||
// $this->assertEquals( '4445554848', $meta_results[0]['meta_value'] );
|
||||
// }
|
||||
//
|
||||
// public function testUpdateMutation() {
|
||||
// global $wpdb;
|
||||
// \gravitytools_tests_reset_db();
|
||||
//
|
||||
// $table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'contact' );
|
||||
// $meta_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'meta' );
|
||||
//
|
||||
// $insert_query = sprintf( 'INSERT INTO %s (firstName, lastName) VALUES ("Test", "User" )', $table_name );
|
||||
// $wpdb->query( $insert_query );
|
||||
//
|
||||
// $insert_meta_query = sprintf( 'INSERT INTO %s (meta_name, meta_value, object_type, object_id) VALUES ("secondary_phone", "4445554545", "contact", "1" )', $meta_table_name );
|
||||
// $wpdb->query( $insert_meta_query );
|
||||
//
|
||||
// $text = '{
|
||||
// update_contact(id: 1, firstName: "Foo", lastName: "Bar", secondary_phone: "4445554848") {
|
||||
// returning {
|
||||
// id,
|
||||
// firstName,
|
||||
// lastName,
|
||||
// secondary_phone,
|
||||
// }
|
||||
// }
|
||||
// }';
|
||||
//
|
||||
// $this->mutation_handler->handle_mutation( $text );
|
||||
//
|
||||
// $check_query = sprintf( 'SELECT * FROM %s', $table_name );
|
||||
// $results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
//
|
||||
// $this->assertEquals( 1, count( $results ) );
|
||||
//
|
||||
// $check_query = sprintf( 'SELECT * FROM %s WHERE id = "%s"', $table_name, 1 );
|
||||
// $results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
//
|
||||
// $record = $results[0];
|
||||
//
|
||||
// $this->assertEquals( 'Foo', $record['firstName'] );
|
||||
// $this->assertEquals( 'Bar', $record['lastName'] );
|
||||
//
|
||||
// $meta_check_query = sprintf( 'SELECT meta_value FROM %s WHERE object_id = "%s" AND meta_name = "%s"', $meta_table_name, $record['id'], 'secondary_phone' );
|
||||
// $meta_results = $wpdb->get_results( $meta_check_query, ARRAY_A );
|
||||
//
|
||||
// $this->assertEquals( '4445554848', $meta_results[0]['meta_value'] );
|
||||
// }
|
||||
//
|
||||
// public function testDeleteMutation() {
|
||||
// global $wpdb;
|
||||
// \gravitytools_tests_reset_db();
|
||||
//
|
||||
// $table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'contact' );
|
||||
// $meta_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'meta' );
|
||||
//
|
||||
// $insert_query = sprintf( 'INSERT INTO %s (firstName, lastName) VALUES ("Test", "User" )', $table_name );
|
||||
// $wpdb->query( $insert_query );
|
||||
//
|
||||
// $text = '{
|
||||
// delete_contact(id: 1) {}
|
||||
// }';
|
||||
//
|
||||
// $check_query = sprintf( 'SELECT * FROM %s', $table_name );
|
||||
// $results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
//
|
||||
// $this->assertEquals( 1, count( $results ) );
|
||||
//
|
||||
// $this->mutation_handler->handle_mutation( $text );
|
||||
//
|
||||
// $check_query = sprintf( 'SELECT * FROM %s', $table_name );
|
||||
// $results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
//
|
||||
// $this->assertEquals( 0, count( $results ) );
|
||||
// }
|
||||
|
||||
public function testOtmConnectMutation() {
|
||||
global $wpdb;
|
||||
\gravitytools_tests_reset_db();
|
||||
|
||||
$deal_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'deal' );
|
||||
$stage_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'stage' );
|
||||
|
||||
$insert_query = sprintf( 'INSERT INTO %s (label) VALUES ("Fun Test Deal")', $deal_table_name );
|
||||
$wpdb->query( $insert_query );
|
||||
|
||||
$insert_query = sprintf( 'INSERT INTO %s (label) VALUES ("Test Stage")', $stage_table_name );
|
||||
$wpdb->query( $insert_query );
|
||||
|
||||
$text = '{
|
||||
connect_deal_stage( objects: [ {from: 1, to: 1} ]) {}
|
||||
}';
|
||||
|
||||
$check_query = sprintf( 'SELECT * FROM %s WHERE stageId = "1" AND id = "1"', $deal_table_name );
|
||||
$results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
|
||||
$this->assertEquals( 0, count( $results ) );
|
||||
|
||||
$this->mutation_handler->handle_mutation( $text, true );
|
||||
|
||||
$results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
|
||||
$this->assertEquals( 1, count( $results ) );
|
||||
$this->assertEquals( 1, $results[0]['stageId'] );
|
||||
$this->assertEquals( 1, $results[0]['id'] );
|
||||
|
||||
$text = '{
|
||||
disconnect_deal_stage([{from:1, to: 1}]) {}
|
||||
}';
|
||||
|
||||
$this->mutation_handler->handle_mutation( $text, true );
|
||||
|
||||
|
||||
$check_query = sprintf( 'SELECT * FROM %s WHERE stageId = "1" AND id = "1"', $deal_table_name );
|
||||
$results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
|
||||
$this->assertEquals( 0, count( $results ) );
|
||||
}
|
||||
|
||||
public function testConnectMutation() {
|
||||
global $wpdb;
|
||||
\gravitytools_tests_reset_db();
|
||||
|
||||
$contact_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'contact' );
|
||||
$company_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'company' );
|
||||
$connect_table_name = sprintf( '%s%s_%s', $wpdb->prefix, $this->db_namespace, 'company_contact' );
|
||||
|
||||
$insert_query = sprintf( 'INSERT INTO %s (firstName, lastName) VALUES ("Test", "User")', $contact_table_name );
|
||||
$wpdb->query( $insert_query );
|
||||
|
||||
$insert_query = sprintf( 'INSERT INTO %s (companyName) VALUES ("Test Company")', $company_table_name );
|
||||
$wpdb->query( $insert_query );
|
||||
|
||||
$text = '{
|
||||
connect_company_contact(objects: [ {from: 1, to: 1} ]) {}
|
||||
}';
|
||||
|
||||
$check_query = sprintf( 'SELECT * FROM %s', $connect_table_name );
|
||||
$results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
|
||||
$this->assertEquals( 0, count( $results ) );
|
||||
|
||||
$this->mutation_handler->handle_mutation( $text, true );
|
||||
|
||||
$check_query = sprintf( 'SELECT * FROM %s', $connect_table_name );
|
||||
$results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
|
||||
$this->assertEquals( 1, count( $results ) );
|
||||
$this->assertEquals( 1, $results[0]['company_id'] );
|
||||
$this->assertEquals( 1, $results[0]['contact_id'] );
|
||||
|
||||
$text = '{
|
||||
disconnect_company_contact([{from:1, to: 1}]) {}
|
||||
}';
|
||||
|
||||
$this->mutation_handler->handle_mutation( $text, true );
|
||||
|
||||
$check_query = sprintf( 'SELECT * FROM %s', $connect_table_name );
|
||||
$results = $wpdb->get_results( $check_query, ARRAY_A );
|
||||
|
||||
$this->assertEquals( 0, count( $results ) );
|
||||
}
|
||||
}
|
||||
+327
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Enum\Field_Type_Validation_Enum;
|
||||
|
||||
class FieldTypeValidationEnumTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider fieldValuesProvider
|
||||
*
|
||||
* @param $field_type
|
||||
* @param $value
|
||||
* @param $expected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFieldsAreValidated( $field_type, $value, $expected ) {
|
||||
$result = Field_Type_Validation_Enum::validate( $field_type, $value );
|
||||
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array with the following values:
|
||||
*
|
||||
* - Field type to check
|
||||
* - Value to validate
|
||||
* - Expected result
|
||||
*
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function fieldValuesProvider() {
|
||||
return array(
|
||||
|
||||
// Basic string
|
||||
array(
|
||||
Field_Type_Validation_Enum::STRING,
|
||||
'foobar',
|
||||
'foobar'
|
||||
),
|
||||
|
||||
// String that needs to be slashified
|
||||
array(
|
||||
Field_Type_Validation_Enum::STRING,
|
||||
"'s-Hertogenbosch",
|
||||
"\'s-Hertogenbosch",
|
||||
),
|
||||
|
||||
// Non-string that should return null
|
||||
array(
|
||||
Field_Type_Validation_Enum::STRING,
|
||||
array(),
|
||||
null,
|
||||
),
|
||||
|
||||
// Non-string that should return null
|
||||
array(
|
||||
Field_Type_Validation_Enum::STRING,
|
||||
12,
|
||||
null,
|
||||
),
|
||||
|
||||
// Basic integer
|
||||
array(
|
||||
Field_Type_Validation_Enum::INT,
|
||||
5,
|
||||
5,
|
||||
),
|
||||
|
||||
// Basic string integer
|
||||
array(
|
||||
Field_Type_Validation_Enum::INT,
|
||||
'5',
|
||||
5,
|
||||
),
|
||||
|
||||
// Float cast as integer
|
||||
array(
|
||||
Field_Type_Validation_Enum::INT,
|
||||
5.0,
|
||||
5,
|
||||
),
|
||||
|
||||
// Non-numeric string that should return null
|
||||
array(
|
||||
Field_Type_Validation_Enum::INT,
|
||||
'five',
|
||||
null,
|
||||
),
|
||||
|
||||
// Non-integer that should return null
|
||||
array(
|
||||
Field_Type_Validation_Enum::INT,
|
||||
array(),
|
||||
null,
|
||||
),
|
||||
|
||||
// Basic float
|
||||
array(
|
||||
Field_Type_Validation_Enum::FLOAT,
|
||||
5.25,
|
||||
5.25
|
||||
),
|
||||
|
||||
// String masquerading as float
|
||||
array(
|
||||
Field_Type_Validation_Enum::FLOAT,
|
||||
'5.25',
|
||||
5.25
|
||||
),
|
||||
|
||||
// Invalid float
|
||||
array(
|
||||
Field_Type_Validation_Enum::FLOAT,
|
||||
'5.2f',
|
||||
null
|
||||
),
|
||||
|
||||
// Truly unhinged float
|
||||
array(
|
||||
Field_Type_Validation_Enum::FLOAT,
|
||||
array( 'FLOAT' ),
|
||||
null
|
||||
),
|
||||
|
||||
// Boolean true
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
true,
|
||||
true
|
||||
),
|
||||
|
||||
// Boolean true
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'true',
|
||||
true
|
||||
),
|
||||
|
||||
// Boolean true
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
1,
|
||||
true
|
||||
),
|
||||
|
||||
// Boolean true
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'yes',
|
||||
true
|
||||
),
|
||||
|
||||
// Boolean true
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'1',
|
||||
true
|
||||
),
|
||||
|
||||
// Boolean true
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'on',
|
||||
true
|
||||
),
|
||||
|
||||
// Boolean false
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
false,
|
||||
false
|
||||
),
|
||||
|
||||
// Boolean false
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'false',
|
||||
false
|
||||
),
|
||||
|
||||
// Boolean false
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
0,
|
||||
false
|
||||
),
|
||||
|
||||
// Boolean false
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'no',
|
||||
false
|
||||
),
|
||||
|
||||
// Boolean false
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'0',
|
||||
false
|
||||
),
|
||||
|
||||
// Boolean false
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
'off',
|
||||
false
|
||||
),
|
||||
|
||||
// Boolean null
|
||||
array(
|
||||
Field_Type_Validation_Enum::BOOLEAN,
|
||||
new \stdClass(),
|
||||
null
|
||||
),
|
||||
|
||||
// Y/m/d
|
||||
array(
|
||||
Field_Type_Validation_Enum::DATE,
|
||||
'2000/12/01',
|
||||
'2000/12/01'
|
||||
),
|
||||
|
||||
// m-d-Y
|
||||
array(
|
||||
Field_Type_Validation_Enum::DATE,
|
||||
'12-01-2000',
|
||||
'12-01-2000'
|
||||
),
|
||||
|
||||
// Timestamp
|
||||
array(
|
||||
Field_Type_Validation_Enum::DATE,
|
||||
'2000-12-01 12:00:00',
|
||||
'2000-12-01 12:00:00'
|
||||
),
|
||||
|
||||
// Invalid m-d-y
|
||||
array(
|
||||
Field_Type_Validation_Enum::DATE,
|
||||
'24-24-2000',
|
||||
null
|
||||
),
|
||||
|
||||
// Not a date
|
||||
array(
|
||||
Field_Type_Validation_Enum::DATE,
|
||||
array(),
|
||||
null
|
||||
),
|
||||
|
||||
// Simple email
|
||||
array(
|
||||
Field_Type_Validation_Enum::EMAIL,
|
||||
'foo@bar.com',
|
||||
'foo@bar.com',
|
||||
),
|
||||
|
||||
// advanced email
|
||||
array(
|
||||
Field_Type_Validation_Enum::EMAIL,
|
||||
'foo+stu_ff.here@bar.com',
|
||||
'foo+stu_ff.here@bar.com',
|
||||
),
|
||||
|
||||
// Bad email
|
||||
array(
|
||||
Field_Type_Validation_Enum::EMAIL,
|
||||
'foo@bar',
|
||||
null,
|
||||
),
|
||||
|
||||
// Another bad email
|
||||
array(
|
||||
Field_Type_Validation_Enum::EMAIL,
|
||||
'foo here@bar.com',
|
||||
null,
|
||||
),
|
||||
|
||||
// Custom Callback
|
||||
array(
|
||||
function( $value ) {
|
||||
return 'hey';
|
||||
},
|
||||
'foo here@bar.com',
|
||||
'hey',
|
||||
),
|
||||
|
||||
// Custom array callback
|
||||
array(
|
||||
array( $this, 'custom_validation_callback' ),
|
||||
'foo',
|
||||
'got foo',
|
||||
),
|
||||
|
||||
// Custom array callback
|
||||
array(
|
||||
array( $this, 'custom_validation_callback' ),
|
||||
'bar',
|
||||
'got bar',
|
||||
),
|
||||
|
||||
// Custom array callback
|
||||
array(
|
||||
array( $this, 'custom_validation_callback' ),
|
||||
'bazinga',
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function custom_validation_callback( $value ) {
|
||||
if ( $value === 'foo' ) {
|
||||
return 'got foo';
|
||||
}
|
||||
|
||||
if ( $value === 'bar' ) {
|
||||
return 'got bar';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\queries;
|
||||
|
||||
use Exception;
|
||||
use FakeCompanyModel;
|
||||
use FakeContactModel;
|
||||
use FakeDealModel;
|
||||
use FakeEmailModel;
|
||||
use FakePhoneModel;
|
||||
use FakeStageModel;
|
||||
use FakeWebsiteModel;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Mutation_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Query_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Connect_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Delete_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Disconnect_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Insert_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Schema_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Update_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Utils\Model_Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
global $wpdb;
|
||||
|
||||
class MutationResultsTest extends TestCase {
|
||||
|
||||
protected $model_collection;
|
||||
protected $contact_model;
|
||||
protected $company_model;
|
||||
protected $email_model;
|
||||
protected $website_model;
|
||||
protected $query_handler;
|
||||
protected $phone_model;
|
||||
protected $mutation_handler;
|
||||
protected $db_namespace;
|
||||
protected $deal_model;
|
||||
protected $stage_model;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->model_collection = new Model_Collection();
|
||||
$this->contact_model = new FakeContactModel();
|
||||
$this->company_model = new FakeCompanyModel();
|
||||
$this->phone_model = new FakePhoneModel();
|
||||
$this->email_model = new FakeEmailModel();
|
||||
$this->website_model = new FakeWebsiteModel();
|
||||
$this->deal_model = new FakeDealModel();
|
||||
$this->stage_model = new FakeStageModel();
|
||||
|
||||
$this->model_collection->add( 'contact', $this->contact_model );
|
||||
$this->model_collection->add( 'company', $this->company_model );
|
||||
$this->model_collection->add( 'email', $this->email_model );
|
||||
$this->model_collection->add( 'phone', $this->phone_model );
|
||||
$this->model_collection->add( 'website', $this->website_model );
|
||||
$this->model_collection->add( 'deal', $this->deal_model );
|
||||
$this->model_collection->add( 'stage', $this->stage_model );
|
||||
$this->db_namespace = 'gravitycrm';
|
||||
|
||||
$schema_runner = new Schema_Runner( $this->model_collection );
|
||||
|
||||
$this->query_handler = new Query_Handler( $this->db_namespace, $this->model_collection, $schema_runner );
|
||||
|
||||
$connect_runner = new Connect_Runner( $this->db_namespace, $this->query_handler, $this->model_collection );
|
||||
|
||||
$runners = array(
|
||||
'insert' => new Insert_Runner( $this->db_namespace, $this->query_handler, $this->model_collection, $connect_runner ),
|
||||
'delete' => new Delete_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ),
|
||||
'connect' => $connect_runner,
|
||||
'disconnect' => new Disconnect_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ),
|
||||
'update' => new Update_Runner( $this->db_namespace, $this->query_handler, $this->model_collection ),
|
||||
);
|
||||
|
||||
$this->mutation_handler = new Mutation_Handler( $this->db_namespace, $this->model_collection, $this->query_handler, $runners );
|
||||
}
|
||||
|
||||
public function testItemsAddedWithOtmRelationships() {
|
||||
$text = '{
|
||||
insert_deal(
|
||||
objects: [
|
||||
{
|
||||
label: "Cool Deal"
|
||||
stage: [{
|
||||
label: "New",
|
||||
}]
|
||||
}
|
||||
]
|
||||
) {
|
||||
returning {
|
||||
id,
|
||||
label,
|
||||
stage {
|
||||
id,
|
||||
}
|
||||
}
|
||||
}
|
||||
}';
|
||||
|
||||
try {
|
||||
$data = $this->mutation_handler->handle_mutation( $text, true );
|
||||
} catch ( Exception $e ) {
|
||||
$this->assertEquals( 'success', $e->getMessage() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertEquals( 1, count( $data['deal'] ) );
|
||||
$this->assertEquals( 1, count( $data['deal'][0]['stage'] ) );
|
||||
}
|
||||
|
||||
public function testItemsAddedWithRelationships() {
|
||||
$text = '{
|
||||
insert_company(
|
||||
objects: [
|
||||
{
|
||||
companyName: "Test Company"
|
||||
email: [
|
||||
{ type: "work", address: "testcompany@abc.com" }
|
||||
{ type: "work", address: "test@company.com" }
|
||||
]
|
||||
phone: [{ type: "work", number: "12223334444", countryCode: "US" }]
|
||||
website: [{ type: "work", url: "testcompany.com" }]
|
||||
}
|
||||
]
|
||||
) {
|
||||
returning {
|
||||
id,
|
||||
companyName,
|
||||
email {
|
||||
id,
|
||||
address,
|
||||
type,
|
||||
}
|
||||
phone {
|
||||
id,
|
||||
number,
|
||||
type,
|
||||
}
|
||||
website {
|
||||
id,
|
||||
url,
|
||||
type
|
||||
}
|
||||
}
|
||||
}
|
||||
}';
|
||||
|
||||
try {
|
||||
$data = $this->mutation_handler->handle_mutation( $text, true );
|
||||
} catch ( Exception $e ) {
|
||||
$this->assertEquals( 'success', $e->getMessage() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertEquals( 1, count( $data['company'] ) );
|
||||
$this->assertEquals( 2, count( $data['company'][0]['email'] ) );
|
||||
$this->assertEquals( 1, count( $data['company'][0]['phone'] ) );
|
||||
$this->assertEquals( 1, count( $data['company'][0]['website'] ) );
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\queries;
|
||||
|
||||
use FakeDealModel;
|
||||
use FakeStageModel;
|
||||
use FakeUserModel;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Query_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Schema_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Utils\Model_Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AdvancedQueryResultsTest extends TestCase {
|
||||
|
||||
protected $model_collection;
|
||||
protected $query_handler;
|
||||
protected $db_namespace;
|
||||
protected $deal_model;
|
||||
protected $stage_model;
|
||||
protected $user_model;
|
||||
|
||||
public function setUp(): void {
|
||||
global $wpdb;
|
||||
\gravitytools_tests_reset_db();
|
||||
$this->model_collection = new Model_Collection();
|
||||
$this->deal_model = new FakeDealModel();
|
||||
$this->stage_model = new FakeStageModel();
|
||||
$this->user_model = new FakeUserModel();
|
||||
|
||||
$this->model_collection->add( 'deal', $this->deal_model );
|
||||
$this->model_collection->add( 'stage', $this->stage_model );
|
||||
$this->model_collection->add( 'user', $this->user_model );
|
||||
$this->db_namespace = 'gravitycrm';
|
||||
|
||||
$schema_runner = new Schema_Runner( $this->model_collection );
|
||||
$this->query_handler = new Query_Handler( $this->db_namespace, $this->model_collection, $schema_runner );
|
||||
|
||||
$wpdb->query("INSERT INTO `wp_gravitycrm_stage` (`label`, `dateCreated`, `dateUpdated`)
|
||||
VALUES ('New', '0000-00-00 00:00:00', '0000-00-00 00:00:00');");
|
||||
|
||||
$wpdb->query("INSERT INTO `wp_gravitycrm_stage` (`label`, `dateCreated`, `dateUpdated`)
|
||||
VALUES ('Won', '0000-00-00 00:00:00', '0000-00-00 00:00:00');");
|
||||
|
||||
$wpdb->query("INSERT INTO `wp_gravitycrm_stage` (`label`, `dateCreated`, `dateUpdated`)
|
||||
VALUES ('Lost', '0000-00-00 00:00:00', '0000-00-00 00:00:00');");
|
||||
|
||||
$wpdb->query("INSERT INTO `wp_gravitycrm_deal` (`label`, `source`, `value`, `estimatedCloseDate`, `notes`, `attachments`, `dateCreated`, `dateUpdated`, `pipelineId`, `stageId`, `userId`)
|
||||
VALUES ('Great Deal 2', 'imported', '1000000', '0000-00-00 00:00:00', NULL, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '1', '2', '1');");
|
||||
|
||||
$wpdb->query("INSERT INTO `wp_gravitycrm_deal` (`label`, `source`, `value`, `estimatedCloseDate`, `notes`, `attachments`, `dateCreated`, `dateUpdated`, `pipelineId`, `stageId`, `userId`)
|
||||
VALUES ('Great Deal 3', 'imported', '1000000', '0000-00-00 00:00:00', NULL, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '1', '3', '1');");
|
||||
}
|
||||
|
||||
public function testOTMRelationships() {
|
||||
$query = '{
|
||||
deal {
|
||||
id,
|
||||
label,
|
||||
stage {
|
||||
label,
|
||||
}
|
||||
}
|
||||
}';
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
$this->assertEquals( 2, count( $result['deal'] ) );
|
||||
|
||||
$this->assertEquals( 'Won', $result['deal'][0]['stage'][0]['label']);
|
||||
$this->assertEquals( 'Lost', $result['deal'][1]['stage'][0]['label']);
|
||||
}
|
||||
|
||||
public function testCustomTableQueries() {
|
||||
$query = '{
|
||||
user {
|
||||
ID,
|
||||
user_nicename,
|
||||
user_login,
|
||||
}
|
||||
}';
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
|
||||
$this->assertEquals( 1, count( $result['user'] ) );
|
||||
$this->assertEquals( 'admin', $result['user'][0]['user_login'] );
|
||||
}
|
||||
|
||||
public function testCustomTableQueriesWithRelationships() {
|
||||
$query = '{
|
||||
deal {
|
||||
id,
|
||||
label,
|
||||
user {
|
||||
ID,
|
||||
user_login
|
||||
}
|
||||
}
|
||||
}';
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
|
||||
$this->assertEquals( 2, count( $result['deal' ] ) );
|
||||
$this->assertEquals( 'admin', $result['deal'][0]['user'][0]['user_login'] );
|
||||
|
||||
$query = '{
|
||||
user {
|
||||
ID,
|
||||
user_nicename,
|
||||
deal {
|
||||
id,
|
||||
label,
|
||||
}
|
||||
}
|
||||
}';
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
|
||||
$this->assertEquals( 2, count( $result['user'][0]['deal'] ) );
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\queries;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Mutation_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Query_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Connect_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Delete_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Insert_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Schema_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Update_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Utils\Model_Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
global $wpdb;
|
||||
|
||||
class QueryResultsTest extends TestCase {
|
||||
|
||||
protected $model_collection;
|
||||
protected $contact_model;
|
||||
protected $company_model;
|
||||
protected $email_model;
|
||||
protected $website_model;
|
||||
protected $query_handler;
|
||||
protected $phone_model;
|
||||
protected $db_namespace;
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
gravitytools_tests_reset_db();
|
||||
$sql = file_get_contents( dirname( __FILE__ ) . '/../../_data/prepopulated.sql' );
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
||||
\dbDelta( $sql );
|
||||
}
|
||||
|
||||
public function setUp(): void {
|
||||
$this->model_collection = new Model_Collection();
|
||||
$this->contact_model = new \FakeContactModel();
|
||||
$this->company_model = new \FakeCompanyModel();
|
||||
$this->phone_model = new \FakePhoneModel();
|
||||
$this->email_model = new \FakeEmailModel();
|
||||
$this->website_model = new \FakeWebsiteModel();
|
||||
|
||||
$this->model_collection->add( 'contact', $this->contact_model );
|
||||
$this->model_collection->add( 'company', $this->company_model );
|
||||
$this->model_collection->add( 'email', $this->email_model );
|
||||
$this->model_collection->add( 'phone', $this->phone_model );
|
||||
$this->model_collection->add( 'website', $this->website_model );
|
||||
$this->db_namespace = 'gravitycrm';
|
||||
|
||||
$schema_runner = new Schema_Runner( $this->model_collection );
|
||||
$this->query_handler = new Query_Handler( $this->db_namespace, $this->model_collection, $schema_runner );
|
||||
}
|
||||
|
||||
// Single item type query
|
||||
public function testSingleItemQuery() {
|
||||
$query = "
|
||||
{
|
||||
contact() {
|
||||
id,
|
||||
firstName,
|
||||
lastName
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
|
||||
$this->assertEquals( 3, count( $result['contact'] ) );
|
||||
}
|
||||
|
||||
public function testSingleItemQueryWithAliases() {
|
||||
$query = "
|
||||
{
|
||||
contact() {
|
||||
contactId: id,
|
||||
firstName,
|
||||
lastName
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
|
||||
$this->assertEquals( 3, count( $result['contact'] ) );
|
||||
}
|
||||
|
||||
// Multiple item type query
|
||||
public function testMultiItemQuery() {
|
||||
$query = "
|
||||
{
|
||||
contact() {
|
||||
id,
|
||||
firstName,
|
||||
lastName
|
||||
},
|
||||
company() {
|
||||
id,
|
||||
companyName,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
|
||||
$this->assertEquals( 3, count( $result['contact'] ) );
|
||||
$this->assertEquals( 2, count( $result['company'] ) );
|
||||
}
|
||||
// Nested query with M2M
|
||||
// Nested query with O2M
|
||||
// Query with transformations
|
||||
public function testQueryWithTransformations() {
|
||||
$query = "
|
||||
{
|
||||
contact() {
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
fakeThumb: id( transformMakeThumb: 'square|large' ),
|
||||
fakeThumbDefaults: id( transformMakeThumb: '' ),
|
||||
fakeThumbSingle: id( transformMakeThumb: 'rectangle' ),
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
$result = $this->query_handler->handle_query( $query, true );
|
||||
|
||||
$this->assertEquals( 'thumbnail_url:1/square/large', $result['contact'][0]['fakeThumb']);
|
||||
$this->assertEquals( 'thumbnail_url:1/hexagon/medium', $result['contact'][0]['fakeThumbDefaults']);
|
||||
$this->assertEquals( 'thumbnail_url:1/rectangle/medium', $result['contact'][0]['fakeThumbSingle']);
|
||||
}
|
||||
}
|
||||
wp-content/plugins/gravitysmtp/vendor/gravityforms/gravity-tools/tests/hermes/queries/SchemaTest.php
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Query_Handler;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Runners\Schema_Runner;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Utils\Model_Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SchemaTest extends TestCase {
|
||||
|
||||
protected $model_collection;
|
||||
protected $contact_model;
|
||||
protected $company_model;
|
||||
protected $email_model;
|
||||
protected $website_model;
|
||||
|
||||
/**
|
||||
* @var Query_Handler
|
||||
*/
|
||||
protected $query_handler;
|
||||
protected $phone_model;
|
||||
protected $db_namespace;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->model_collection = new Model_Collection();
|
||||
$this->contact_model = new \FakeContactModel();
|
||||
$this->company_model = new \FakeCompanyModel();
|
||||
$this->phone_model = new \FakePhoneModel();
|
||||
$this->email_model = new \FakeEmailModel();
|
||||
$this->website_model = new \FakeWebsiteModel();
|
||||
|
||||
$this->model_collection->add( 'contact', $this->contact_model );
|
||||
$this->model_collection->add( 'company', $this->company_model );
|
||||
$this->model_collection->add( 'email', $this->email_model );
|
||||
$this->model_collection->add( 'phone', $this->phone_model );
|
||||
$this->model_collection->add( 'website', $this->website_model );
|
||||
$this->db_namespace = 'gravitycrm';
|
||||
|
||||
$schema_runner = new Schema_Runner( $this->model_collection );
|
||||
|
||||
$this->query_handler = new Query_Handler( $this->db_namespace, $this->model_collection, $schema_runner );
|
||||
}
|
||||
|
||||
public function testSchemaQueries() {
|
||||
$text = '{ __schema(){ name, fields { name, type }, metaFields { name, type }, relationships { to, accessCap } } }';
|
||||
|
||||
$results = $this->query_handler->handle_query( $text, true );
|
||||
|
||||
$this->assertEquals( 5, count( $results['__schema'] ) );
|
||||
}
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\tokens;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Arguments_Token;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ArgumentsTokenTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider queryStringProvider
|
||||
*
|
||||
* @param $query_string
|
||||
* @param $expected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testQueryStringParsesCorrectly( $query_string, $expected ) {
|
||||
$token = new Arguments_Token( $query_string );
|
||||
|
||||
$this->assertEquals( $expected, $token->items() );
|
||||
}
|
||||
|
||||
public function queryStringProvider() {
|
||||
return array(
|
||||
|
||||
// Single argument with standard equal operator
|
||||
array(
|
||||
'id: 5',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '=',
|
||||
'value' => '5',
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// Multiple arguments with equal operators
|
||||
array(
|
||||
'id: 5, date: 2000-01-01',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '=',
|
||||
'value' => '5',
|
||||
),
|
||||
array(
|
||||
'key' => 'date',
|
||||
'comparator' => '=',
|
||||
'value' => '2000-01-01',
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// Single argument with lt operator
|
||||
array(
|
||||
'id_lt: 5',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '<',
|
||||
'value' => '5',
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// Single argument with gt operator
|
||||
array(
|
||||
'id_gt: 5',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '>',
|
||||
'value' => '5',
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// Single argument with lte operator
|
||||
array(
|
||||
'id_lte: 5',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '<=',
|
||||
'value' => '5',
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// Single argument with gte operator
|
||||
array(
|
||||
'id_gte: 5',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '>=',
|
||||
'value' => '5',
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// Single argument with ne operator
|
||||
array(
|
||||
'id_ne: 5',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '!=',
|
||||
'value' => '5',
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// Multiple arguments with text contents
|
||||
array(
|
||||
'pipelineID: 1, id: "hey", transformFormatDate: "Y-m-d, H:i:s|1"',
|
||||
array(
|
||||
array(
|
||||
'key' => 'pipelineID',
|
||||
'comparator' => '=',
|
||||
'value' => '1',
|
||||
),
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '=',
|
||||
'value' => 'hey',
|
||||
),
|
||||
array(
|
||||
'key' => 'transformFormatDate',
|
||||
'comparator' => '=',
|
||||
'value' => array(
|
||||
'Y-m-d, H:i:s',
|
||||
'1',
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
// Multiple arguments with mixed operators
|
||||
array(
|
||||
'id: 5, foo_lt: 10, bar_gt: 20, bash_lte: 30, bing_gte: 40, bazinga_ne: 50',
|
||||
array(
|
||||
array(
|
||||
'key' => 'id',
|
||||
'comparator' => '=',
|
||||
'value' => '5',
|
||||
),
|
||||
array(
|
||||
'key' => 'foo',
|
||||
'comparator' => '<',
|
||||
'value' => '10',
|
||||
),
|
||||
array(
|
||||
'key' => 'bar',
|
||||
'comparator' => '>',
|
||||
'value' => '20',
|
||||
),
|
||||
array(
|
||||
'key' => 'bash',
|
||||
'comparator' => '<=',
|
||||
'value' => '30',
|
||||
),
|
||||
array(
|
||||
'key' => 'bing',
|
||||
'comparator' => '>=',
|
||||
'value' => '40',
|
||||
),
|
||||
array(
|
||||
'key' => 'bazinga',
|
||||
'comparator' => '!=',
|
||||
'value' => '50',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\tokens;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Arguments_Token;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Field_Token;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FieldTokenTest extends TestCase {
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider arrayArgsProvider
|
||||
*
|
||||
* @param $matches
|
||||
* @param $marks
|
||||
* @param $arguments
|
||||
* @param $expected_name
|
||||
* @param $expected_alias
|
||||
* @param $expected_arguments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayArgsParseCorrectly( $matches, $marks, $arguments, $expected_name, $expected_alias, $expected_arguments ) {
|
||||
$token = new Field_Token( $matches, $marks, $arguments );
|
||||
|
||||
$this->assertEquals( $expected_name, $token->name() );
|
||||
$this->assertEquals( $expected_alias, $token->alias() );
|
||||
$this->assertEquals( $expected_arguments, $token->children() );
|
||||
}
|
||||
|
||||
public function arrayArgsProvider() {
|
||||
return array(
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'alias' => 'foo',
|
||||
'arguments' => array(),
|
||||
),
|
||||
'foo',
|
||||
'foo',
|
||||
array(),
|
||||
),
|
||||
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'alias' => 'bash',
|
||||
'arguments' => array(),
|
||||
),
|
||||
'foo',
|
||||
'bash',
|
||||
array(),
|
||||
),
|
||||
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'alias' => 'bash',
|
||||
'arguments' => array(
|
||||
'foo' => 'bar',
|
||||
),
|
||||
),
|
||||
'foo',
|
||||
'bash',
|
||||
array(
|
||||
'foo' => 'bar',
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
array( 'foo' => 'bar' ),
|
||||
array( 'bing' => 'bash' ),
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'alias' => 'foo',
|
||||
'arguments' => array(),
|
||||
),
|
||||
'foo',
|
||||
'foo',
|
||||
array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\tokens;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Query_Token;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class QueryTokenTest extends TestCase {
|
||||
|
||||
public function testQueryParsesToArray() {
|
||||
$text = file_get_contents( dirname( __FILE__ ) . '/../../_data/basic.graphql' );
|
||||
$data = new Query_Token( $text );
|
||||
|
||||
$items = $data->items();
|
||||
$this->assertCount( 1, $items );
|
||||
|
||||
$heroFields = $items[0]->fields();
|
||||
$this->assertCount( 3, $heroFields );
|
||||
|
||||
$friendsFields = $heroFields[2]->fields();
|
||||
$this->assertCount( 3, $friendsFields );
|
||||
|
||||
$secondaryFriendFields = $friendsFields[2]->fields();
|
||||
$this->assertCount( 3, $secondaryFriendFields );
|
||||
|
||||
$tertiaryFriendFields = $secondaryFriendFields[2]->fields();
|
||||
$this->assertcount( 2, $tertiaryFriendFields );
|
||||
|
||||
$this->assertEquals( $heroFields[1]->object_type(), 'height' );
|
||||
$this->assertEquals( $heroFields[1]->alias(), 'metricHeight' );
|
||||
$this->assertCount( 1, $heroFields[1]->arguments()->items() );
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\tokens\mutations;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Mutations\Connect\Connection_Values_Token;
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Mutations\Insert\Insert_Mutation_Token;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConnectMutationTokenTest extends TestCase {
|
||||
|
||||
public function testArgumentsParseCorrectly() {
|
||||
$text = '{
|
||||
connect_company_contact([{from: 1, to: 2}, {from:1, to: 3}, {from: 1, to: 4}]) {}
|
||||
}';
|
||||
$token = new Connection_Values_Token( $text );
|
||||
|
||||
$pairs = $token->children();
|
||||
|
||||
$this->assertEquals( 3, count( $pairs ) );
|
||||
|
||||
$this->assertEquals( 1, $pairs[0]['from'] );
|
||||
$this->assertEquals( 1, $pairs[1]['from'] );
|
||||
$this->assertEquals( 1, $pairs[2]['from'] );
|
||||
|
||||
|
||||
$this->assertEquals( 2, $pairs[0]['to'] );
|
||||
$this->assertEquals( 3, $pairs[1]['to'] );
|
||||
$this->assertEquals( 4, $pairs[2]['to'] );
|
||||
}
|
||||
|
||||
|
||||
public function testSingleArgumentParsesCorrectly() {
|
||||
$text = '{
|
||||
connect_company_contact({from: 1, to: 2}) {}
|
||||
}';
|
||||
$token = new Connection_Values_Token( $text );
|
||||
|
||||
$pairs = $token->children();
|
||||
|
||||
$this->assertEquals( 1, count( $pairs ) );
|
||||
|
||||
$this->assertEquals( 1, $pairs[0]['from'] );
|
||||
|
||||
$this->assertEquals( 2, $pairs[0]['to'] );
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace hermes\tokens\mutations;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Hermes\Tokens\Mutations\Insert\Insert_Mutation_Token;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class InsertMutationTokenTest extends TestCase {
|
||||
|
||||
public function testMutationParsesToArray() {
|
||||
$text = '{
|
||||
insert_todos(objects: [{title: "New Todo", status: "active"}, {title: "Second Todo", status: "pending"}]) {
|
||||
returning {
|
||||
id,
|
||||
title,
|
||||
is_completed,
|
||||
is_public,
|
||||
created_at,
|
||||
}
|
||||
}
|
||||
}';
|
||||
$token = new Insert_Mutation_Token( $text );
|
||||
|
||||
$expected_fields = array(
|
||||
"id",
|
||||
"title",
|
||||
"is_completed",
|
||||
"is_public",
|
||||
"created_at",
|
||||
);
|
||||
|
||||
$return_fields = $token->return_fields();
|
||||
|
||||
foreach( $expected_fields as $field ) {
|
||||
$this->assertNotEquals( false, strpos( $return_fields, $field ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function testInsertObjectsParseCorrectly(){
|
||||
$text = '{
|
||||
insert_todos(objects: [{title: "New Todo", status: "active", body: "Hey this is the body. Its a lot of fun, and has \"nested\" quotation marks."}, {title: "Second Todo", status: "pending"}]) {
|
||||
returning {
|
||||
id
|
||||
title
|
||||
is_completed
|
||||
is_public
|
||||
created_at
|
||||
}
|
||||
}
|
||||
}';
|
||||
$token = new Insert_Mutation_Token( $text );
|
||||
|
||||
$this->assertEquals( 2, count( $token->children()->children() ) );
|
||||
|
||||
$expected_fields = array(
|
||||
"id",
|
||||
"title",
|
||||
"is_completed",
|
||||
"is_public",
|
||||
"created_at",
|
||||
);
|
||||
|
||||
$return_fields = $token->return_fields();
|
||||
|
||||
foreach( $expected_fields as $field ) {
|
||||
$this->assertNotEquals( false, strpos( $return_fields, $field ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function testInsertedObjectsWithComplexFields(){
|
||||
$text = '{
|
||||
insert_todos(objects: [{title: "New Todo", status: "active", body: "<html>
|
||||
<body>
|
||||
<p>Hey this is some text. It has <b>bold text</b> and some other <br/> things in it.</p>
|
||||
</body>
|
||||
</html>"}, {title: "Second Todo", status: "pending"}]) {
|
||||
returning {
|
||||
id
|
||||
title
|
||||
is_completed
|
||||
is_public
|
||||
created_at
|
||||
}
|
||||
}
|
||||
}';
|
||||
$token = new Insert_Mutation_Token( $text );
|
||||
|
||||
$this->assertEquals( 2, count( $token->children()->children() ) );
|
||||
|
||||
$expected_fields = array(
|
||||
"id",
|
||||
"title",
|
||||
"is_completed",
|
||||
"is_public",
|
||||
"created_at",
|
||||
);
|
||||
|
||||
$return_fields = $token->return_fields();
|
||||
|
||||
foreach( $expected_fields as $field ) {
|
||||
$this->assertNotEquals( false, strpos( $return_fields, $field ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function testInsertedObjectsWithRelationships() {
|
||||
$text = '{
|
||||
insert_company( objects: [
|
||||
{
|
||||
companyName: "Acme, INC",
|
||||
contact: [
|
||||
{
|
||||
firstName: "John",
|
||||
lastName: "Smith",
|
||||
email: [{
|
||||
type: "work",
|
||||
address: "jsmith@acme.local",
|
||||
}]
|
||||
},
|
||||
{
|
||||
firstName: "Jane",
|
||||
lastName: "Doe",
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
companyName: "Acme2, INC",
|
||||
contact: [
|
||||
{
|
||||
firstName: "Phil",
|
||||
lastName: "Johnson"
|
||||
},
|
||||
{
|
||||
firstName: "Janet",
|
||||
lastName: "Bigelow",
|
||||
}
|
||||
]
|
||||
}
|
||||
]){
|
||||
returning {
|
||||
id,
|
||||
companyName,
|
||||
contact: {
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
email {
|
||||
id,
|
||||
address,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}';
|
||||
|
||||
$token = new Insert_Mutation_Token( $text );
|
||||
|
||||
$objects = $token->children()->children();
|
||||
|
||||
$this->assertEquals( 7, count( $objects ) );
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace system_report;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\System_Report\System_Report_Group;
|
||||
use Gravity_Forms\Gravity_Tools\System_Report\System_Report_Item;
|
||||
use Gravity_Forms\Gravity_Tools\System_Report\System_Report_Repository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SystemReportTest extends TestCase {
|
||||
|
||||
public function testAddGroup() {
|
||||
$repo = System_Report_Repository::instance( true );
|
||||
$group = new System_Report_Group();
|
||||
|
||||
$repo->add( 'foobar', $group );
|
||||
|
||||
$retrieve = $repo->get( 'foobar' );
|
||||
|
||||
$this->assertEquals( $group, $retrieve );
|
||||
}
|
||||
|
||||
public function testHasGroup() {
|
||||
$repo = System_Report_Repository::instance( true );
|
||||
$group = new System_Report_Group();
|
||||
$repo->add( 'foobar', $group );
|
||||
$this->assertTrue( $repo->has( 'foobar' ) );
|
||||
}
|
||||
|
||||
public function testDeleteGroup() {
|
||||
$repo = System_Report_Repository::instance( true );
|
||||
$group = new System_Report_Group();
|
||||
$repo->add( 'foobar', $group );
|
||||
$this->assertTrue( $repo->has( 'foobar' ) );
|
||||
|
||||
$repo->delete( 'foobar' );
|
||||
|
||||
$this->assertFalse( $repo->has( 'foobar' ) );
|
||||
}
|
||||
|
||||
public function testAddItem() {
|
||||
$group = new System_Report_Group();
|
||||
$item = new System_Report_Item( 'foo', 'bar' );
|
||||
|
||||
$group->add( 'foobar', $item );
|
||||
|
||||
$retrieved = $group->get( 'foobar' );
|
||||
|
||||
$this->assertEquals( $retrieved, $item );
|
||||
}
|
||||
|
||||
public function testHasItem() {
|
||||
$group = new System_Report_Group();
|
||||
$item = new System_Report_Item( 'foo', 'bar' );
|
||||
|
||||
$group->add( 'foobar', $item );
|
||||
|
||||
$this->assertTrue( $group->has( 'foobar' ) );
|
||||
}
|
||||
|
||||
public function testDeleteItem() {
|
||||
$group = new System_Report_Group();
|
||||
$item = new System_Report_Item( 'foo', 'bar' );
|
||||
|
||||
$group->add( 'foobar', $item );
|
||||
|
||||
$this->assertTrue( $group->has( 'foobar' ) );
|
||||
|
||||
$group->delete( 'foobar' );
|
||||
|
||||
$this->assertFalse( $group->has( 'foobar' ) );
|
||||
}
|
||||
|
||||
public function testItemEscape() {
|
||||
$item = new System_Report_Item( '<script>hey<script><a>foo</a>', '<a>bar</a>' );
|
||||
|
||||
$this->assertEquals( 'hey<a>foo</a>', $item->key() );
|
||||
$this->assertEquals( '<a>bar</a>', $item->value() );
|
||||
}
|
||||
|
||||
public function testItemSensitive() {
|
||||
$item = new System_Report_Item( 'foo', 'bar', true );
|
||||
|
||||
$this->assertEquals( 'foo', $item->key() );
|
||||
$this->assertEquals( '**********', $item->value() );
|
||||
}
|
||||
|
||||
public function testAsArray() {
|
||||
$repo = System_Report_Repository::instance( true );
|
||||
$group = new System_Report_Group();
|
||||
$item = new System_Report_Item( 'foo', 'bar' );
|
||||
$group->add( 'foobing', $item );
|
||||
|
||||
$item = new System_Report_Item( 'foo', 'bash', true );
|
||||
$group->add( 'foobash', $item );
|
||||
|
||||
$repo->add( 'foobar', $group );
|
||||
|
||||
$expected = array(
|
||||
'foobar' => array(
|
||||
'foobing' => array(
|
||||
'key' => 'foo',
|
||||
'value' => 'bar',
|
||||
),
|
||||
'foobash' => array(
|
||||
'key' => 'foo',
|
||||
'value' => '**********',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $repo->as_array() );
|
||||
}
|
||||
|
||||
public function testAsString() {
|
||||
$repo = System_Report_Repository::instance( true );
|
||||
$group = new System_Report_Group();
|
||||
$item = new System_Report_Item( 'Active Theme', 'Twenty Twenty-One' );
|
||||
$group->add( 'active_theme', $item );
|
||||
|
||||
$item = new System_Report_Item( 'Secret Key', 'Bash', true );
|
||||
$group->add( 'secret_key', $item );
|
||||
|
||||
$repo->add( 'Environment Details', $group );
|
||||
|
||||
$expected = 'Environment Details
|
||||
Active Theme: Twenty Twenty-One
|
||||
Secret Key: **********
|
||||
';
|
||||
|
||||
$this->assertEquals( $expected, $repo->as_string() );
|
||||
}
|
||||
|
||||
public function testDefaultData() {
|
||||
$repo = System_Report_Repository::instance();
|
||||
|
||||
$this->assertTrue( $repo->has( 'Translations' ) );
|
||||
}
|
||||
}
|
||||
Vendored
+226
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace utils;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Utils\Beltloop;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BeltloopTest extends TestCase {
|
||||
|
||||
public function testOrdering() {
|
||||
$data = array(
|
||||
array(
|
||||
'id' => 7,
|
||||
'prevId' => 6,
|
||||
),
|
||||
array(
|
||||
'id' => 1,
|
||||
'prevId' => 0,
|
||||
),
|
||||
array(
|
||||
'id' => 3,
|
||||
'prevId' => 2,
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'prevId' => 4,
|
||||
),
|
||||
array(
|
||||
'id' => 6,
|
||||
'prevId' => 5,
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'prevId' => 1,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'prevId' => 3,
|
||||
),
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'prevId' => 0,
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'prevId' => 1,
|
||||
),
|
||||
array(
|
||||
'id' => 3,
|
||||
'prevId' => 2,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'prevId' => 3,
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'prevId' => 4,
|
||||
),
|
||||
array(
|
||||
'id' => 6,
|
||||
'prevId' => 5,
|
||||
),
|
||||
array(
|
||||
'id' => 7,
|
||||
'prevId' => 6,
|
||||
),
|
||||
);
|
||||
|
||||
$sorted = Beltloop::sort( $data, 'id', 'prevId' );
|
||||
$this->assertEquals( $expected, $sorted );
|
||||
}
|
||||
|
||||
public function testSortWithMissingItems() {
|
||||
$data = array(
|
||||
array(
|
||||
'id' => 8,
|
||||
'prevId' => 7,
|
||||
),
|
||||
array(
|
||||
'id' => 9,
|
||||
'prevId' => 8,
|
||||
),
|
||||
array(
|
||||
'id' => 3,
|
||||
'prevId' => 2,
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'prevId' => 4,
|
||||
),
|
||||
array(
|
||||
'id' => 7,
|
||||
'prevId' => 6,
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'prevId' => 1,
|
||||
),
|
||||
array(
|
||||
'id' => 1,
|
||||
'prevId' => 0,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'prevId' => 3,
|
||||
),
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'prevId' => 0,
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'prevId' => 1,
|
||||
),
|
||||
array(
|
||||
'id' => 3,
|
||||
'prevId' => 2,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'prevId' => 3,
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'prevId' => 4,
|
||||
),
|
||||
array(
|
||||
'id' => 7,
|
||||
'prevId' => 6,
|
||||
),
|
||||
array(
|
||||
'id' => 8,
|
||||
'prevId' => 7,
|
||||
),
|
||||
array(
|
||||
'id' => 9,
|
||||
'prevId' => 8,
|
||||
),
|
||||
);
|
||||
|
||||
$sorted = Beltloop::sort( $data );
|
||||
$this->assertEquals( $expected, $sorted );
|
||||
}
|
||||
|
||||
public function testPartialSort() {
|
||||
$full_list = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'prevId' => 0,
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'prevId' => 1,
|
||||
),
|
||||
array(
|
||||
'id' => 3,
|
||||
'prevId' => 2,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'prevId' => 3,
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'prevId' => 4,
|
||||
),
|
||||
array(
|
||||
'id' => 6,
|
||||
'prevId' => 5,
|
||||
),
|
||||
array(
|
||||
'id' => 7,
|
||||
'prevId' => 6,
|
||||
),
|
||||
);
|
||||
|
||||
$partial_list = array(
|
||||
array(
|
||||
'id' => 7,
|
||||
'prevId' => 6,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'prevId' => 3,
|
||||
),
|
||||
array(
|
||||
'id' => 1,
|
||||
'prevId' => 0,
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'prevId' => 4,
|
||||
),
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'prevId' => 0,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'prevId' => 3,
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'prevId' => 4,
|
||||
),
|
||||
array(
|
||||
'id' => 7,
|
||||
'prevId' => 6,
|
||||
),
|
||||
);
|
||||
|
||||
$result = Beltloop::partial_sort( $full_list, $partial_list );
|
||||
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
||||
}
|
||||
Vendored
+140
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace utils;
|
||||
|
||||
use Exception;
|
||||
use Gravity_Forms\Gravity_Tools\Utils\Bettarray;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BettarrayTest extends TestCase {
|
||||
|
||||
public function testArrayOps() {
|
||||
$init_data = array( 'foo' => 'bar', 'bing' => 'bash' );
|
||||
$data = new Bettarray( $init_data );
|
||||
|
||||
unset( $data['foo'] );
|
||||
|
||||
$this->assertEquals( array( 'bing' => 'bash' ), $data->all() );
|
||||
|
||||
$data['bingo'] = 'bango';
|
||||
|
||||
$this->assertEquals( array( 'bing' => 'bash', 'bingo' => 'bango' ), $data->all() );
|
||||
|
||||
$data[] = 'huzzah';
|
||||
|
||||
$this->assertEquals( array( 'bing' => 'bash', 'bingo' => 'bango', 0 => 'huzzah' ), $data->all() );
|
||||
}
|
||||
|
||||
public function testSet() {
|
||||
$data = new Bettarray( array() );
|
||||
|
||||
$data->set( 'foo', 'bar' );
|
||||
|
||||
$this->assertEquals( array( 'foo' => 'bar' ), $data->all() );
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
$data = new Bettarray( array( 'foo' => 'bar', 'bing' => 'bash' ) );
|
||||
|
||||
$this->assertEquals( 'bar', $data->get( 'foo' ) );
|
||||
$this->assertEquals( 'bash', $data->get( 'bing' ) );
|
||||
|
||||
$data->set( 'bingo', 'bango' );
|
||||
|
||||
$this->assertEquals( 'bango', $data->get( 'bingo' ) );
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
$data = new Bettarray( array( 'foo' => 'bar' ) );
|
||||
$data->delete( 'foo' );
|
||||
|
||||
$this->assertEquals( array(), $data->all() );
|
||||
}
|
||||
|
||||
public function testDotSet() {
|
||||
$data = new Bettarray( array( 'foo' => 'bar' ) );
|
||||
|
||||
$data->set( 'bing.bash.bazinga', array( 1, 2, 3 ) );
|
||||
|
||||
$this->assertEquals( array( 'foo' => 'bar', 'bing' => array( 'bash' => array( 'bazinga' => array( 1, 2, 3 ) ) ) ), $data->all() );
|
||||
}
|
||||
|
||||
public function testDotGet() {
|
||||
$data = new Bettarray( array( 'foo' => array( 'bar' => array( 'bash' => 'found' ) ) ) );
|
||||
|
||||
$value = $data->get( 'foo.bar.bash' );
|
||||
|
||||
$this->assertEquals( 'found', $value );
|
||||
}
|
||||
|
||||
public function testDotDelete() {
|
||||
$data = new Bettarray( array( 'foo' => array( 'bar' => array( 'bash' => 'hey' ) ) ) );
|
||||
$data->delete( 'foo.bar.bash' );
|
||||
|
||||
$this->assertEquals( array( 'foo' => array( 'bar' => array() ) ), $data->all() );
|
||||
}
|
||||
|
||||
public function testAppend() {
|
||||
$data = new Bettarray( array( 'foo' => array( 1, 2, 3 ) ) );
|
||||
$data->append( 'foo', 4 );
|
||||
|
||||
$this->assertEquals( array( 'foo' => array( 1, 2, 3, 4 ) ), $data->all() );
|
||||
}
|
||||
|
||||
public function testDotAppend() {
|
||||
$data = new Bettarray( array( 'foo' => array( 'bar' => array( 1, 2, 3 ) ) ) );
|
||||
$data->append( 'foo.bar', 4 );
|
||||
|
||||
$this->assertEquals( array( 'foo' => array( 'bar' => array( 1, 2, 3, 4, ) ) ), $data->all() );
|
||||
}
|
||||
|
||||
public function testAmend() {
|
||||
$data = new Bettarray( array( 'foo' => array( 'bar' => 'bash' ) ) );
|
||||
$data->amend( 'foo', array( 'bingo' => 'bango' ) );
|
||||
|
||||
$this->assertEquals( array( 'foo' => array( 'bar' => 'bash', 'bingo' => 'bango' ) ), $data->all() );
|
||||
}
|
||||
|
||||
public function testDotAmend() {
|
||||
$data = new Bettarray( array( 'foo' => array( 'bar' => array( 'bingo' => 'bango' ) ) ) );
|
||||
$data->amend( 'foo.bar', array( 'bazinga' => 'bazanga' ) );
|
||||
|
||||
$this->assertEquals( array( 'foo' => array( 'bar' => array( 'bingo' => 'bango', 'bazinga' => 'bazanga' ) ) ), $data->all() );
|
||||
}
|
||||
|
||||
public function testSlice() {
|
||||
$data = new Bettarray( array( 1, 2, 3, 4, 5, 6, 7 ) );
|
||||
|
||||
$new_data = $data->slice( 2, 3 );
|
||||
|
||||
$this->assertEquals( array( 3, 4, 5 ), $new_data->all() );
|
||||
}
|
||||
|
||||
public function testCount() {
|
||||
$data = new Bettarray( array( 1, 2, 3, 4, 5 ) );
|
||||
|
||||
$this->assertEquals( $data->count(), 5 );
|
||||
|
||||
$data = new Bettarray( array( 'foo', 'bar', 'bing', 'bash' ) );
|
||||
|
||||
$this->assertEquals( 4, $data->count() );
|
||||
}
|
||||
|
||||
public function testPluck() {
|
||||
$data = new Bettarray( array( array( 'foo' => 'bar', 'name' => 'Aaron' ), array( 'foo' => 'bar', 'name' => 'Ryan' ) ) );
|
||||
|
||||
$names = $data->pluck( 'name' );
|
||||
|
||||
$this->assertEquals( array( 'Aaron', 'Ryan' ), $names->all() );
|
||||
}
|
||||
|
||||
public function testFilter() {
|
||||
$data = new Bettarray( array( array( 'id' => 1 ), array( 'id' => 2 ), array( 'id' => 3 ), array( 'id' => 4 ) ) );
|
||||
|
||||
$filtered = $data->filter( function( $item ) {
|
||||
return $item['id'] > 2;
|
||||
} );
|
||||
|
||||
$this->assertEquals( 2, $filtered->count() );
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Gravity_Forms\Gravity_Tools\Utils\Moola;
|
||||
use \InvalidArgumentException;
|
||||
|
||||
class MoolaTest extends TestCase {
|
||||
|
||||
public function testValidCurrency() {
|
||||
$this->expectNotToPerformAssertions();
|
||||
new Moola( 100, 'USD' );
|
||||
}
|
||||
|
||||
public function testInvalidCurrencyException() {
|
||||
$this->expectException( InvalidArgumentException::class );
|
||||
new Moola( 100, 'FOO' );
|
||||
}
|
||||
|
||||
public function testRawOutput() {
|
||||
$moola = new Moola( 1000, 'USD' );
|
||||
|
||||
$this->assertEquals( 1000, $moola->raw_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider displayOutputDataProvider
|
||||
*/
|
||||
public function testDisplayOutput( $amount, $currency, $precision, $show_currency, $expected ) {
|
||||
$moola = new Moola( $amount, $currency );
|
||||
$value = $moola->display_value( $precision, $show_currency );
|
||||
|
||||
$this->assertEquals( $expected, $value );
|
||||
}
|
||||
|
||||
public function displayOutputDataProvider() {
|
||||
return array(
|
||||
array(
|
||||
1000,
|
||||
'USD',
|
||||
0,
|
||||
false,
|
||||
10,
|
||||
),
|
||||
|
||||
array(
|
||||
1000,
|
||||
'JPY',
|
||||
0,
|
||||
false,
|
||||
1000,
|
||||
),
|
||||
|
||||
array(
|
||||
1234,
|
||||
'USD',
|
||||
1,
|
||||
false,
|
||||
12.3,
|
||||
),
|
||||
|
||||
array(
|
||||
1234,
|
||||
'USD',
|
||||
2,
|
||||
false,
|
||||
12.34
|
||||
),
|
||||
|
||||
array(
|
||||
1234,
|
||||
'USD',
|
||||
2,
|
||||
true,
|
||||
'$12.34'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testChangeCurrency() {
|
||||
$moola = new Moola( 1000, 'USD' );
|
||||
$moola->change_currency( 'JPY' );
|
||||
|
||||
$this->assertEquals( 10, $moola->raw_value() );
|
||||
|
||||
$moola->change_currency( 'USD' );
|
||||
|
||||
$this->assertEquals( 1000, $moola->raw_value() );
|
||||
|
||||
$this->assertEquals( '10', $moola->display_value() );
|
||||
$moola->change_currency( 'JPY' );
|
||||
|
||||
$this->assertEquals( '10', $moola->display_value() );
|
||||
}
|
||||
|
||||
public function testDisplayValueConversion() {
|
||||
$moola = new Moola( '$1000.00', 'USD', false );
|
||||
$this->assertEquals( 100000, $moola->raw_value() );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user