fixed the api and added tests
authoraditya-nambiar <aditya.nambiar007@gmail.com>
Sat, 26 Jul 2014 11:52:37 +0000 (17:22 +0530)
committeraditya-nambiar <aditya.nambiar007@gmail.com>
Sat, 26 Jul 2014 11:52:37 +0000 (17:22 +0530)
CRM/Mailing/BAO/MailingAB.php
api/v3/MailingAB.php
api/v3/examples/MailingAB/Create.php [new file with mode: 0644]
js/angular-crmMailingAB.js
partials/abtesting/list.html [new file with mode: 0644]
partials/abtesting/main.html
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/MailingABTest.php

index 2df15ea1a226198dde4f87022cd86685f3dc2f50..6e2cc44dba1b9e951349b0d055b0b524d6edd2dd 100644 (file)
@@ -67,6 +67,7 @@ class CRM_Mailing_BAO_MailingAB extends CRM_Mailing_DAO_MailingAB {
       return $mailingab;
     }
     $transaction->commit();
+    return $mailingab;
   }
 
   /**
@@ -133,5 +134,4 @@ class CRM_Mailing_BAO_MailingAB extends CRM_Mailing_DAO_MailingAB {
 
     CRM_Utils_Hook::post('delete', 'MailingAB', $id, $dao);
   }
-
 }
index 4c295ea48f7209c69c03a2e2464c74a103990359..f853209bbe32e42061f3dad4a4e5ad892ac392b3 100644 (file)
@@ -49,7 +49,7 @@
  *
  * @return array API Success Array
  */
-function civicrm_api3_mailingab_create($params) {
+function civicrm_api3_mailing_a_b_create($params) {
   return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
@@ -61,7 +61,7 @@ function civicrm_api3_mailingab_create($params) {
  *
  * @return array API Success Array
  */
-function civicrm_api3_mailingab_delete($params) {
+function civicrm_api3_mailing_a_b_delete($params) {
   return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
@@ -71,7 +71,7 @@ function civicrm_api3_mailingab_delete($params) {
  * @param array $params
  * @return array
  */
-function civicrm_api3_mailingab_get($params) {
+function civicrm_api3_mailing_a_b_get($params) {
   return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
diff --git a/api/v3/examples/MailingAB/Create.php b/api/v3/examples/MailingAB/Create.php
new file mode 100644 (file)
index 0000000..dea3cb4
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Test Generated example of using mailing_a_b create API
+ * *
+ */
+function mailing_a_b_create_example(){
+$params = array(
+  'mailing_id_a' => 1,
+  'mailing_id_b' => 2,
+  'mailing_id_c' => 3,
+  'testing_criteria_id' => 1,
+  'winner_criteria_id' => 1,
+  'declare_winning_time' => '+2 days',
+  'group_percentage' => 10,
+);
+
+try{
+  $result = civicrm_api3('mailing_a_b', 'create', $params);
+}
+catch (CiviCRM_API3_Exception $e) {
+  // handle error here
+  $errorMessage = $e->getMessage();
+  $errorCode = $e->getErrorCode();
+  $errorData = $e->getExtraParams();
+  return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
+}
+
+return $result;
+}
+
+/**
+ * Function returns array of result expected from previous function
+ */
+function mailing_a_b_create_expectedresult(){
+
+  $expectedResult = array(
+  'is_error' => 0,
+  'version' => 3,
+  'count' => 1,
+  'id' => 1,
+  'values' => array(
+      '1' => array(
+          'id' => '1',
+          'mailing_id_a' => '1',
+          'mailing_id_b' => '2',
+          'mailing_id_c' => '3',
+          'domain_id' => '1',
+          'testing_criteria_id' => '1',
+          'winner_criteria_id' => '1',
+          'specific_url' => '',
+          'declare_winning_time' => '20140728171837',
+          'group_percentage' => '10',
+        ),
+    ),
+);
+
+  return $expectedResult;
+}
+
+
+/*
+* This example has been generated from the API test suite. The test that created it is called
+*
+* testMailingABCreateSuccess and can be found in
+* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MailingABTest.php
+*
+* You can see the outcome of the API tests at
+* https://test.civicrm.org/job/CiviCRM-master-git/
+*
+* To Learn about the API read
+* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
+*
+* Browse the api on your own site with the api explorer
+* http://MYSITE.ORG/path/to/civicrm/api/explorer
+*
+* Read more about testing here
+* http://wiki.civicrm.org/confluence/display/CRM/Testing
+*
+* API Standards documentation:
+* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
+*/
index bd31b0515eb01afeedfc56c76f0ba408efe5b2b3..5724e164aec9ae544ed95b944e3bc47df66d4924 100644 (file)
 
 (function (angular, $, _) {
 
-       var partialUrl = function (relPath) {
-               return CRM.resourceUrls['civicrm'] + '/partials/abtesting/' + relPath;
-       };
-
-       var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils']);
-
-       crmMailingAB.run(function ($rootScope, $templateCache) {
-               $rootScope.$on('$viewContentLoaded', function () {
-                       $templateCache.removeAll();
-               });
-       });
-
-       crmMailingAB.config([
-               '$routeProvider',
-               function ($routeProvider) {
-                       $routeProvider.when('/mailing/abtesting', {
-                               templateUrl: partialUrl('main.html'),
-                               controller: 'TabsDemoCtrl',
-                               resolve: {
-                                       mailingList: function ($route, crmApi) {
-                                               return crmApi('Mailing', 'get', {});
-                                       }
-                               }
-                       });
-               }
-       ]);
+  var partialUrl = function (relPath) {
+    return CRM.resourceUrls['civicrm'] + '/partials/abtesting/' + relPath;
+  };
+
+  var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils']);
+
+  crmMailingAB.run(function ($rootScope, $templateCache) {
+    $rootScope.$on('$viewContentLoaded', function () {
+      $templateCache.removeAll();
+    });
+  });
+
+  crmMailingAB.config([
+    '$routeProvider',
+    function ($routeProvider) {
+      $routeProvider.when('/mailing/abtesting', {
+        templateUrl: partialUrl('list.html'),
+        controller: 'ListingCtrl',
+        resolve: {
+          mailingList: function ($route, crmApi) {
+            return crmApi('Mailing', 'get', {});
+          }
+        }
+      });
+      $routeProvider.when('/mailing/abtesting/:id', {
+        templateUrl: partialUrl('main.html'),
+        controller: 'TabsDemoCtrl',
+        resolve: {
+          mailingList: function ($route, crmApi) {
+            return crmApi('Mailing', 'get', {});
+          }
+        }
+      });
+    }
+  ]);
 
 //-----------------------------------------
-       // Add a new record by name.
-       // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
-
-       crmMailingAB.controller('TabsDemoCtrl', function ($scope, crmApi) {
-
-               $scope.groups = CRM.crmMailing.groupNames;
-               $scope.mailList = CRM.crmMailing.civiMails;
-
-               $scope.tab_val = 0;
-               $scope.max_tab = 0;
-               $scope.campaign_clicked = function () {
-                       if ($scope.max_tab >= 0) {
-                               $scope.tab_val = 0;
-                       }
-               };
-               $scope.compose_clicked = function () {
-                       if ($scope.max_tab >= 1) {
-                               $scope.tab_val = 1;
-                       }
-               };
-               $scope.rec_clicked = function () {
-                       if ($scope.max_tab >= 2) {
-                               $scope.tab_val = 2;
-                       }
-               };
-               $scope.preview_clicked = function () {
-                       if ($scope.max_tab >= 3) {
-                               $scope.tab_val = 3;
-                       }
-               };
-               $scope.templates =
-                       [
-                               { name: 'Subject Lines', url: partialUrl('subject_lines.html')},
-                               { name: 'From Name', url: partialUrl('from_name.html')},
-                               {name: 'Two different Emails', url: partialUrl('two_emails.html')}
-                       ];
-               $scope.template = $scope.templates[0];
-
-               $scope.slide_value = 0;
-
-               $scope.setifyes = function (val) {
-                       if (val == 1) {
-                               $scope.ifyes = true;
-                       }
-                       else {
-                               $scope.ifyes = false;
-                       }
-               };
-
-               $scope.send_date = "01/01/2000";
-
-               $scope.dt = "";
-
-               $scope.mailA = {};
-
-               $scope.mailB = {};
-               $scope.save = function (dat) {
-
-                       var result = crmApi('Mailing', 'create', dat, true);
-                       console.log("Ac " + result);
-               };
-
-               $scope.init = function (par) {
-
-                       $scope.whatnext = par.toString()
-               };
-
-               $scope.setdate = function (par) {
-                       console.log("called")
-                       console.log("av " + par)
-                       $scope.send_date = par;
-                       $scope.dt = par;
-                       $scope.apply();
-               };
-
-               $scope.scheddate = {};
-               $scope.scheddate.date = "6";
-               $scope.scheddate.time = "";
-               $scope.incGroup = [];
-               $scope.excGroup = [];
-
-
-       });
-
-       crmMailingAB.directive('nexttab', function () {
-               return {
-                       // Restrict it to be an attribute in this case
-                       restrict: 'A',
-
-                       priority: 500,
-                       // responsible for registering DOM listeners as well as updating the DOM
-                       link: function (scope, element, attrs) {
-
-                               $(element).parent().parent().parent().parent().tabs(scope.$eval(attrs.nexttab));
-                               var myarr = new Array(1, 2, 3)
-                               $(element).parent().parent().parent().parent().tabs({disabled: myarr});
-
-                               $(element).on("click", function () {
-                                       scope.tab_val = scope.tab_val + 1;
-
-                                       scope.max_tab = Math.max(scope.tab_val, scope.max_tab);
-                                       var myArray1 = new Array();
-                                       for (var i = scope.max_tab + 1; i < 4; i++) {
-                                               myArray1.push(i);
-                                       }
-                                       $(element).parent().parent().parent().parent().parent().tabs("option", "disabled", myArray1);
-                                       $(element).parent().parent().parent().parent().parent().tabs("option", "active", scope.tab_val);
-                                       scope.$apply();
-                                       console.log("Adir");
-                               });
-                       }
-               };
-       });
-
-       crmMailingAB.directive('prevtab', function () {
-               return {
-                       // Restrict it to be an attribute in this case
-                       restrict: 'A',
-                       priority: 500,
-                       // responsible for registering DOM listeners as well as updating the DOM
-                       link: function (scope, element, attrs) {
-
-
-                               $(element).on("click", function () {
-                                       var temp = scope.tab_val - 1;
-                                       scope.tab_val = scope.tab_val - 1;
-
-                                       console.log(temp);
-                                       if (temp == 3) {
-
-                                       }
-                                       else {
-                                               $(element).parent().parent().parent().parent().parent().tabs("option", "active", temp);
-                                       }
-
-                                       scope.$apply();
-
-                               });
-                       }
-               };
-       });
-
-       crmMailingAB.directive('groupselect', function () {
-               return {
-                       restrict: 'AE',
-                       link: function (scope, element, attrs) {
-                               function format(item) {
-                                       if (!item.id) {
-                                               // return `text` for optgroup
-                                               return item.text;
-                                       }
-                                       // return item template
-                                       var a = item.id.split(" ");
-                                       if (a[1] == "group" && a[2] == "include") {
-                                               return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item.text;
-                                       }
-                                       if (a[1] == "group" && a[2] == "exclude") {
-                                               return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item.text;
-                                       }
-                                       if (a[1] == "mail" && a[2] == "include") {
-                                               return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item.text;
-                                       }
-                                       if (a[1] == "mail" && a[2] == "exclude") {
-                                               return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item.text;
-                                       }
-                               }
-
-                               $(element).select2({
-                                       width: "400px",
-                                       placeholder: "Select the groups you wish to include",
-                                       formatResult: format,
-                                       formatSelection: format,
-                                       escapeMarkup: function (m) {
-                                               return m;
-                                       }
-                               });
-
-                               $(element).on('select2-selecting', function (e) {
-                                       var a = e.val.split(" ");
-                                       var l = a.length;
-                                       if (a[2] == "include") {
-                                               var str = "";
-                                               for (i = 3; i < l; i++) {
-                                                       str += a[i];
-                                                       str += " ";
-                                               }
-                                               scope.incGroup.push(str);
-                                               scope.$apply();
-                                       }
-
-                                       else {
-                                               var str = "";
-                                               for (i = 3; i < l; i++) {
-                                                       str += a[i];
-                                                       str += " ";
-                                               }
-
-                                               scope.excGroup.push(str);
-                                               scope.$apply();
-                                       }
-
-                               });
-                               $(element).on("select2-removed", function (e) {
-                                       if (e.val.split(" ")[2] == "exclude") {
-                                               var index = scope.excGroup.indexOf(e.val.split(" ")[3]);
-                                               scope.excGroup.splice(index, 1);
-                                               scope.$apply();
-                                       }
-                                       else {
-                                               var index = scope.incGroup.indexOf(e.val.split(" ")[3]);
-                                               scope.incGroup.splice(index, 1);
-                                               scope.$apply();
-                                       }
-                               });
-                       }
-               };
-
-       });
-
-       crmMailingAB.directive('sliderbar', function () {
-               return{
-                       restrict: 'AE',
-                       link: function (scope, element, attrs) {
-                               $(element).slider({min: 1});
-                               $(element).slider({
-                                       slide: function (event, ui) {
-                                               scope.slide_value = ui.value;
-                                               scope.$apply();
-                                       }
-                               });
-                       }
-               };
-       });
-
-       crmMailingAB.directive('tpmax', function () {
-               return {
-                       restrict: 'E',
-                       link: function (scope, element, attr) {
-                               scope.$watch('automated', function (val) {
-                                       if (val == "Yes") {
-                                               $(element).dialog({
-                                                       title: 'Automated A/B Testing',
-                                                       width: 800,
-                                                       height: 600,
-                                                       closed: false,
-                                                       cache: false,
-                                                       modal: true
-                                               });
-                                       }
-                               });
-
-                               $(element).find("#closebutton").on("click", function () {
-                                       $(element).dialog("close");
-                               });
-                       }
-               };
-       });
-
-       crmMailingAB.directive('numbar', function () {
-               return{
-                       restrict: 'AE',
-                       link: function (scope, element, attrs) {
-                               $(element).spinner({max: attrs.numbar, min: 0});
-                       }
-               };
-       });
-
-       crmMailingAB.directive('datepick', function () {
-               return {
-
-
-                       restrict: 'AE',
-                       link: function (scope, element, attrs) {
-                               $(element).datepicker({
-                                       dateFormat: "yy-mm-dd",
-                                       onSelect: function (date) {
-                                               $(".ui-datepicker a").removeAttr("href");
-
-                                               scope.scheddate.date = date.toString();
-                                               scope.$apply();
-                                               console.log(scope.scheddate.date);
-
-                                       }
-
-
-                               });
-                       }
-               };
-       });
-
-       crmMailingAB.directive('submitform', function () {
-               return {
-                       restrict: 'A',
-                       priority: 1000,
-                       link: function (scope, element, attrs) {
-                               $(element).on("click", function () {
-
-                                       console.log("clicked");
-                                       scope.save({
-                                               "sequential": 1,
-                                               "name": "Aditya Nambiar",
-                                               "subject": scope.mailA.subj,
-                                               "created_id": "2",
-                                               "from_email": scope.mailA.fromEmail,
-                                               "body_text": scope.mailA.body
-
-                                       });
-                                       console.log("Truth " + scope.whatnext)
-
-                                       if (scope.whatnext == "3") {
-                                               console.log("sdf");
-                                               scope.mailB.subj = scope.mailA.subj;
-                                               scope.mailB.body = scope.mailA.body;
-
-                                       }
-                                       else {
-                                               if (scope.whatnext == "2") {
-                                                       scope.mailB.fromEmail = scope.mailA.fromEmail;
-                                                       scope.mailB.body = scope.mailA.body;
-
-                                               }
-                                       }
-
-
-                                       scope.save({
-                                               "sequential": 1,
-                                               "name": "Aditya Nambiar",
-                                               "subject": scope.mailB.subj,
-                                               "created_id": "2",
-                                               "from_email": scope.mailB.fromEmail,
-                                               "body_text": scope.mailB.body
-
-                                       });
-
-                               });
-                       }
-               };
-
-       });
-
-       crmMailingAB.directive('nextbutton', function () {
-               return {
-                       restrict: 'AE',
-                       replace: 'true',
-                       template: '<div class="crm-submit-buttons" id="campaignbutton">' +
-                               '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view"   >' +
-                               '<input type="submit" value="Next"  id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" nexttab={{tab_val}}>' +
-                               '</div></div>'
-
-               };
-       });
-
-       crmMailingAB.directive('cancelbutton', function () {
-               return {
-                       restrict: 'AE',
-                       replace: 'true',
-                       template: '<div class="crm-submit-buttons" id="campaignbutton">' +
-                               '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view"   >' +
-                               '<input type="submit" value="Cancel"  id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" >' +
-                               '</div></div>'
-
-               };
-       });
-
-       crmMailingAB.directive('prevbutton', function () {
-               return {
-                       restrict: 'AE',
-                       replace: 'true',
-                       template: '<div class="crm-submit-buttons" >' +
-                               '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view"   >' +
-                               '<input type="submit" value="Previous"  id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" prevtab={{tab_val}}>' +
-                               '</div></div>'
-
-               };
-       });
+  // Add a new record by name.
+  // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
+  crmMailingAB.controller('ListingCtrl', function ($scope, crmApi) {
+    $scope.mailList = CRM.crmMailing.civiMails;
+
+  })
+  crmMailingAB.controller('TabsDemoCtrl', function ($scope, crmApi) {
+
+    $scope.groups = CRM.crmMailing.groupNames;
+    $scope.mailList = CRM.crmMailing.civiMails;
+
+    $scope.tab_val = 0;
+    $scope.max_tab = 0;
+    $scope.campaign_clicked = function () {
+      if ($scope.max_tab >= 0) {
+        $scope.tab_val = 0;
+      }
+    };
+    $scope.compose_clicked = function () {
+      if ($scope.max_tab >= 1) {
+        $scope.tab_val = 1;
+      }
+    };
+    $scope.rec_clicked = function () {
+      if ($scope.max_tab >= 2) {
+        $scope.tab_val = 2;
+      }
+    };
+    $scope.preview_clicked = function () {
+      if ($scope.max_tab >= 3) {
+        $scope.tab_val = 3;
+      }
+    };
+    $scope.templates =
+      [
+        { name: 'Subject Lines', url: partialUrl('subject_lines.html')},
+        { name: 'From Name', url: partialUrl('from_name.html')},
+        {name: 'Two different Emails', url: partialUrl('two_emails.html')}
+      ];
+    $scope.template = $scope.templates[0];
+
+    $scope.slide_value = 0;
+
+    $scope.setifyes = function (val) {
+      if (val == 1) {
+        $scope.ifyes = true;
+      }
+      else {
+        $scope.ifyes = false;
+      }
+    };
+
+    $scope.send_date = "01/01/2000";
+
+    $scope.dt = "";
+
+    $scope.mailA = {};
+
+    $scope.mailB = {};
+    $scope.save = function (dat) {
+
+      var result = crmApi('Mailing', 'create', dat, true);
+      console.log("Ac " + result);
+    };
+
+    $scope.init = function (par) {
+
+      $scope.whatnext = par.toString()
+    };
+
+    $scope.setdate = function (par) {
+      console.log("called")
+      console.log("av " + par)
+      $scope.send_date = par;
+      $scope.dt = par;
+      $scope.apply();
+    };
+
+    $scope.scheddate = {};
+    $scope.scheddate.date = "6";
+    $scope.scheddate.time = "";
+    $scope.incGroup = [];
+    $scope.excGroup = [];
+
+
+  });
+
+  crmMailingAB.directive('nexttab', function () {
+    return {
+      // Restrict it to be an attribute in this case
+      restrict: 'A',
+
+      priority: 500,
+      // responsible for registering DOM listeners as well as updating the DOM
+      link: function (scope, element, attrs) {
+
+        $(element).parent().parent().parent().parent().tabs(scope.$eval(attrs.nexttab));
+        var myarr = new Array(1, 2, 3)
+        $(element).parent().parent().parent().parent().tabs({disabled: myarr});
+
+        $(element).on("click", function () {
+          scope.tab_val = scope.tab_val + 1;
+
+          scope.max_tab = Math.max(scope.tab_val, scope.max_tab);
+          var myArray1 = new Array();
+          for (var i = scope.max_tab + 1; i < 4; i++) {
+            myArray1.push(i);
+          }
+          $(element).parent().parent().parent().parent().parent().tabs("option", "disabled", myArray1);
+          $(element).parent().parent().parent().parent().parent().tabs("option", "active", scope.tab_val);
+          scope.$apply();
+          console.log("Adir");
+        });
+      }
+    };
+  });
+
+  crmMailingAB.directive('prevtab', function () {
+    return {
+      // Restrict it to be an attribute in this case
+      restrict: 'A',
+      priority: 500,
+      // responsible for registering DOM listeners as well as updating the DOM
+      link: function (scope, element, attrs) {
+
+
+        $(element).on("click", function () {
+          var temp = scope.tab_val - 1;
+          scope.tab_val = scope.tab_val - 1;
+
+          console.log(temp);
+          if (temp == 3) {
+
+          }
+          else {
+            $(element).parent().parent().parent().parent().parent().tabs("option", "active", temp);
+          }
+
+          scope.$apply();
+
+        });
+      }
+    };
+  });
+
+  crmMailingAB.directive('groupselect', function () {
+    return {
+      restrict: 'AE',
+      link: function (scope, element, attrs) {
+        function format(item) {
+          if (!item.id) {
+            // return `text` for optgroup
+            return item.text;
+          }
+          // return item template
+          var a = item.id.split(" ");
+          if (a[1] == "group" && a[2] == "include") {
+            return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item.text;
+          }
+          if (a[1] == "group" && a[2] == "exclude") {
+            return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item.text;
+          }
+          if (a[1] == "mail" && a[2] == "include") {
+            return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item.text;
+          }
+          if (a[1] == "mail" && a[2] == "exclude") {
+            return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item.text;
+          }
+        }
+
+        $(element).select2({
+          width: "400px",
+          placeholder: "Select the groups you wish to include",
+          formatResult: format,
+          formatSelection: format,
+          escapeMarkup: function (m) {
+            return m;
+          }
+        });
+
+        $(element).on('select2-selecting', function (e) {
+          var a = e.val.split(" ");
+          var l = a.length;
+          if (a[2] == "include") {
+            var str = "";
+            for (i = 3; i < l; i++) {
+              str += a[i];
+              str += " ";
+            }
+            scope.incGroup.push(str);
+            scope.$apply();
+          }
+
+          else {
+            var str = "";
+            for (i = 3; i < l; i++) {
+              str += a[i];
+              str += " ";
+            }
+
+            scope.excGroup.push(str);
+            scope.$apply();
+          }
+
+        });
+        $(element).on("select2-removed", function (e) {
+          if (e.val.split(" ")[2] == "exclude") {
+            var index = scope.excGroup.indexOf(e.val.split(" ")[3]);
+            scope.excGroup.splice(index, 1);
+            scope.$apply();
+          }
+          else {
+            var index = scope.incGroup.indexOf(e.val.split(" ")[3]);
+            scope.incGroup.splice(index, 1);
+            scope.$apply();
+          }
+        });
+      }
+    };
+
+  });
+
+  crmMailingAB.directive('sliderbar', function () {
+    return{
+      restrict: 'AE',
+      link: function (scope, element, attrs) {
+        $(element).slider({min: 1});
+        $(element).slider({
+          slide: function (event, ui) {
+            scope.slide_value = ui.value;
+            scope.$apply();
+          }
+        });
+      }
+    };
+  });
+
+  crmMailingAB.directive('tpmax', function () {
+    return {
+      restrict: 'E',
+      link: function (scope, element, attr) {
+        scope.$watch('automated', function (val) {
+          if (val == "Yes") {
+            $(element).dialog({
+              title: 'Automated A/B Testing',
+              width: 800,
+              height: 600,
+              closed: false,
+              cache: false,
+              modal: true
+            });
+          }
+        });
+
+        $(element).find("#closebutton").on("click", function () {
+          $(element).dialog("close");
+        });
+      }
+    };
+  });
+
+  crmMailingAB.directive('numbar', function () {
+    return{
+      restrict: 'AE',
+      link: function (scope, element, attrs) {
+        $(element).spinner({max: attrs.numbar, min: 0});
+      }
+    };
+  });
+
+  crmMailingAB.directive('datepick', function () {
+    return {
+
+
+      restrict: 'AE',
+      link: function (scope, element, attrs) {
+        $(element).datepicker({
+          dateFormat: "yy-mm-dd",
+          onSelect: function (date) {
+            $(".ui-datepicker a").removeAttr("href");
+
+            scope.scheddate.date = date.toString();
+            scope.$apply();
+            console.log(scope.scheddate.date);
+
+          }
+
+
+        });
+      }
+    };
+  });
+
+  crmMailingAB.directive('submitform', function () {
+    return {
+      restrict: 'A',
+      priority: 1000,
+      link: function (scope, element, attrs) {
+        $(element).on("click", function () {
+
+          console.log("clicked");
+          scope.save({
+            "sequential": 1,
+            "name": "Aditya Nambiar",
+            "subject": scope.mailA.subj,
+            "created_id": "2",
+            "from_email": scope.mailA.fromEmail,
+            "body_text": scope.mailA.body
+
+          });
+          console.log("Truth " + scope.whatnext)
+
+          if (scope.whatnext == "3") {
+            console.log("sdf");
+            scope.mailB.subj = scope.mailA.subj;
+            scope.mailB.body = scope.mailA.body;
+
+          }
+          else {
+            if (scope.whatnext == "2") {
+              scope.mailB.fromEmail = scope.mailA.fromEmail;
+              scope.mailB.body = scope.mailA.body;
+
+            }
+          }
+
+
+          scope.save({
+            "sequential": 1,
+            "name": "Aditya Nambiar",
+            "subject": scope.mailB.subj,
+            "created_id": "2",
+            "from_email": scope.mailB.fromEmail,
+            "body_text": scope.mailB.body
+
+          });
+
+        });
+      }
+    };
+
+  });
+
+  crmMailingAB.directive('nextbutton', function () {
+    return {
+      restrict: 'AE',
+      replace: 'true',
+      template: '<div class="crm-submit-buttons" id="campaignbutton">' +
+        '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view"   >' +
+        '<input type="submit" value="Next"  id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" nexttab={{tab_val}}>' +
+        '</div></div>'
+
+    };
+  });
+
+  crmMailingAB.directive('cancelbutton', function () {
+    return {
+      restrict: 'AE',
+      replace: 'true',
+      template: '<div class="crm-submit-buttons" id="campaignbutton">' +
+        '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view"   >' +
+        '<input type="submit" value="Cancel"  id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" >' +
+        '</div></div>'
+
+    };
+  });
+
+  crmMailingAB.directive('prevbutton', function () {
+    return {
+      restrict: 'AE',
+      replace: 'true',
+      template: '<div class="crm-submit-buttons" >' +
+        '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view"   >' +
+        '<input type="submit" value="Previous"  id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" prevtab={{tab_val}}>' +
+        '</div></div>'
+
+    };
+  });
 
 
 })(angular, CRM.$, CRM._);
diff --git a/partials/abtesting/list.html b/partials/abtesting/list.html
new file mode 100644 (file)
index 0000000..023dbcd
--- /dev/null
@@ -0,0 +1,14 @@
+<div>
+Current Running AB Tests are
+  <table>
+    <tr>
+      <td><h3>Name</h3></td>
+      <td><h3>Subject</h3></td>
+    </tr>
+    <tr ng-repeat="ml in mailList">
+      <td>{{ml.name}}</td>
+      <td>{{ml.subject}}</td>
+    </tr>
+  </table>
+
+</div>
\ No newline at end of file
index 006420f006a0a4309322fa0e161a866b4e05a70d..62038e1dc564b8178a2722e3518ad4197bf49c20 100644 (file)
-
-
 <div>
 
+  <div ui-jq="tabs" id="alltabs">
+    <ul>
 
-    <div ui-jq="tabs" id="alltabs" >
-        <ul>
-
-            <li><a href="#tabs-1" ng-click="campaign_clicked()" >Campaign</a></li>
-            <li><a href="#tabs-2" ng-click="compose_clicked()">Compose</a></li>
-            <li><a href="#tabs-3" ng-click="rec_clicked()">Recipients and Winner Criteria</a> </li>
-            <li><a href="#tabs-4" ng-click="preview_clicked()">Preview and Send</a></li>
-        </ul>
+      <li><a href="#tabs-1" ng-click="campaign_clicked()">Campaign</a></li>
+      <li><a href="#tabs-2" ng-click="compose_clicked()">Compose</a></li>
+      <li><a href="#tabs-3" ng-click="rec_clicked()">Recipients and Winner Criteria</a></li>
+      <li><a href="#tabs-4" ng-click="preview_clicked()">Preview and Send</a></li>
+    </ul>
 
-        <div  id="tabs-1" >
+    <div id="tabs-1">
 
-            <form name="myForm" >
+      <form name="myForm">
 
-                <h3> What would you like to test ?</h3><br><br>
+        <h3> What would you like to test ?</h3><br><br>
 
-                &nbsp <input type="radio" ng-model="template" ng-value="templates[0]">  Subject Lines <br/><br>
-                &nbsp <input type="radio" ng-model="template" ng-value="templates[1]"> From Names <br/><br>
-                &nbsp <input type="radio" ng-model="template" ng-value="templates[2]"> Two different Emails <br/><br>
-                &nbsp <div style="position:relative; left:220px; top: 30px;" nextbutton></div> <div style="position:relative; left:300px; top:-1px;" cancelbutton></div>
+        &nbsp <input type="radio" ng-model="template" ng-value="templates[0]"> Subject Lines <br/><br>
+        &nbsp <input type="radio" ng-model="template" ng-value="templates[1]"> From Names <br/><br>
+        &nbsp <input type="radio" ng-model="template" ng-value="templates[2]"> Two different Emails <br/><br>
+        &nbsp
+        <div style="position:relative; left:220px; top: 30px;" nextbutton></div>
+        <div style="position:relative; left:300px; top:-1px;" cancelbutton></div>
 
 
-            </form>
-        </div>
-
-        <div id="tabs-2"  >
+      </form>
+    </div>
 
-            <form>
-            <div  ng-include="template.url">
-            </div>
-                <div style="position:relative; left:200px; top:61px;" prevbutton></div>
-                <div style="position:relative; left:300px; top: 30px;" nextbutton></div>
-                <div style="position:relative; left:375px; top:-1px;"cancelbutton></div>
+    <div id="tabs-2">
 
-            </form>
+      <form>
+        <div ng-include="template.url">
         </div>
+        <div style="position:relative; left:200px; top:61px;" prevbutton></div>
+        <div style="position:relative; left:300px; top: 30px;" nextbutton></div>
+        <div style="position:relative; left:375px; top:-1px;" cancelbutton></div>
 
-        <div id="tabs-3">
-
-            <form name="impform"  novalidate>
-                <h3>Select the groups you would like to add</h3><br>
-
-
-                &nbsp<br>
-                <select multiple groupselect >
-                    <option id= "1" ng-repeat="grp in groups" value="{{grp.id}} group include {{grp.title}}" > {{grp.title}} </option>
-                    <option ng-repeat="grp in groups" value="{{grp.id}} group exclude {{grp.title}}" > {{grp.title}} </option>
-                    <option ng-repeat="ml in mailList" value="{{ml.id}} mail include {{ml.title}}" > {{ml.name}} </option>
-                    <option ng-repeat="ml in mailList" value="{{ml.id}} mail exclude {{ml.title}}" > {{ml.name}} </option>
-                </select>
-                <br> <br><br><br>
-                {{incGroup}}<br>{{excGroup}}
-
-                <h3>Select the size of your test group</h3><br>
-                &nbsp Percentage Selected - {{slide_value}}%
-
-                <div sliderbar id="trial" style="margin: 10px;"></div>
-
-                <h3>How will the winner be decided</h3><br>
-                &nbsp <input type="radio" ng-model="winner_criteria" value="Open" name="cri" required> Open <br/><br>
-                &nbsp <input type="radio" ng-model="winner_criteria" value="Total Unique Clicks" name="cri" checked="checked" > Total Unique Clicks <br/><br>
-                &nbsp <input type="radio" ng-model="winner_criteria" value="Total Clicks on a particular link" name="cri" > Total Clicks on a particular link <br/><br>
- <!-- Remove automated
-                <h3>Do you want the A/B test to be automated </h3>
-                &nbsp<input type="radio" ng-model="automated" value="Yes" ng-click="setifyes(1)" name="auto" required>Yes &nbsp
-                &nbsp<input type="radio" ng-model="automated" value="No" ng-click="setifyes(2)" name="auto" checked="checked"> No <br/><br>
-
-                <tpmax ng-show="ifyes">
-
-                    <h3> Please enter the confidence level at which a decision can be made</h3>
-                    &nbsp &nbsp <input type="text" style="height: 20px; width: 25px;" ng-model="conf" numbar=99 ><br><br>
-                    <div ng-show="conf==null || conf ==0 || conf>99" style="color: red;">&nbsp Please Enter a Valid Number</div>
-
-                    <h3>If the confidence level is not reached what do you want us to do?</h3>
-                    &nbsp <input type="radio" ng-model="ifnot" value="Inform me" name="ifnot"/> Inform me <br/><br>
-                    &nbsp <input type="radio" checked="checked" ng-model="ifnot" value="Send Version A" name="ifnot" /> Send Version A <br/><br>
-                    &nbsp <input type="radio" ng-model="ifnot" value="Send Version B" name="ifnot"/> Send Version B <br/><br>
-
+      </form>
+    </div>
 
-                    <div nextbutton></div>
+    <div id="tabs-3">
+
+      <form name="impform" novalidate>
+        <h3>Select the groups you would like to add</h3><br>
+
+
+        &nbsp<br>
+        <select multiple groupselect>
+          <option id="1" ng-repeat="grp in groups" value="{{grp.id}} group include {{grp.title}}"> {{grp.title}}
+          </option>
+          <option ng-repeat="grp in groups" value="{{grp.id}} group exclude {{grp.title}}"> {{grp.title}}</option>
+          <option ng-repeat="ml in mailList" value="{{ml.id}} mail include {{ml.title}}"> {{ml.name}}</option>
+          <option ng-repeat="ml in mailList" value="{{ml.id}} mail exclude {{ml.title}}"> {{ml.name}}</option>
+        </select>
+        <br> <br><br><br>
+        {{incGroup}}<br>{{excGroup}}
+
+        <h3>Select the size of your test group</h3><br>
+        &nbsp Percentage Selected - {{slide_value}}%
+
+        <div sliderbar id="trial" style="margin: 10px;"></div>
+
+        <h3>How will the winner be decided</h3><br>
+        &nbsp <input type="radio" ng-model="winner_criteria" value="Open" name="cri" required> Open <br/><br>
+        &nbsp <input type="radio" ng-model="winner_criteria" value="Total Unique Clicks" name="cri" checked="checked">
+        Total Unique Clicks <br/><br>
+        &nbsp <input type="radio" ng-model="winner_criteria" value="Total Clicks on a particular link" name="cri"> Total
+        Clicks on a particular link <br/><br>
+        <!-- Remove automated
+                       <h3>Do you want the A/B test to be automated </h3>
+                       &nbsp<input type="radio" ng-model="automated" value="Yes" ng-click="setifyes(1)" name="auto" required>Yes &nbsp
+                       &nbsp<input type="radio" ng-model="automated" value="No" ng-click="setifyes(2)" name="auto" checked="checked"> No <br/><br>
+
+                       <tpmax ng-show="ifyes">
+
+                           <h3> Please enter the confidence level at which a decision can be made</h3>
+                           &nbsp &nbsp <input type="text" style="height: 20px; width: 25px;" ng-model="conf" numbar=99 ><br><br>
+                           <div ng-show="conf==null || conf ==0 || conf>99" style="color: red;">&nbsp Please Enter a Valid Number</div>
+
+                           <h3>If the confidence level is not reached what do you want us to do?</h3>
+                           &nbsp <input type="radio" ng-model="ifnot" value="Inform me" name="ifnot"/> Inform me <br/><br>
+                           &nbsp <input type="radio" checked="checked" ng-model="ifnot" value="Send Version A" name="ifnot" /> Send Version A <br/><br>
+                           &nbsp <input type="radio" ng-model="ifnot" value="Send Version B" name="ifnot"/> Send Version B <br/><br>
+
+
+                           <div nextbutton></div>
+
+                       </tpmax>
+       -->
+        <h3>Declare the winner in how much time?</h3><br>
+        &nbsp <input type="text" style="height: 20px; width: 15px;" ng-model="days" numbar=7 name="d"> Days
+        &nbsp <input type="text" style="height: 20px; width: 15px;" ng-model="hours" numbar=23 name="h"> Hours
+        &nbsp <input type="text" style="height: 20px; width: 15px;" ng-model="minutes" numbar=59 name="m"> Minutes
+        <div
+          ng-show="((days == null || days ==0 ) && (hours==null|| hours == 0 ) && (minutes==null || minutes ==0 )|| days>99 || minutes>59 || hours >23) "
+          style="color: red;">&nbsp Please a Valid Time
+        </div>
+        <br>
+        <br>
 
-                </tpmax>
--->
-                <h3>Declare the winner in how much time?</h3><br>
-                &nbsp <input type="text" style="height: 20px; width: 15px;" ng-model="days" numbar=7 name="d"> Days
-                &nbsp <input type="text" style="height: 20px; width: 15px;" ng-model="hours" numbar=23 name="h"> Hours
-                &nbsp <input type="text" style="height: 20px; width: 15px;" ng-model="minutes" numbar=59 name="m"> Minutes
-                <div ng-show="((days == null || days ==0 ) && (hours==null|| hours == 0 ) && (minutes==null || minutes ==0 )|| days>99 || minutes>59 || hours >23) " style="color: red;">&nbsp Please a Valid Time</div>
-                <br>
-                <br>
 
+        <div style="position:relative; left:200px; top:30px;" prevbutton></div>
+        <div style="position:relative; left:300px; top: 00px;" nextbutton></div>
+        <div style="position:relative; left:375px; top: -31px;" cancelbutton></div>
 
-                <div style="position:relative; left:200px; top:30px;" prevbutton></div>
-                <div style="position:relative; left:300px; top: 00px;" nextbutton></div>
-                <div style="position:relative; left:375px; top: -31px;" cancelbutton></div>
+      </form>
+    </div>
 
-            </form>
+    <div id="tabs-4">
+
+      <h3>Details</h3><br>
+      <table>
+        <tr>
+          <td>Test Criteria</td>
+          <td>{{template.name}}</td>
+        </tr>
+        <tr>
+          <td>Groups Included</td>
+          <td>{{incGroup}}</td>
+        </tr>
+        <tr>
+          <td>Groups Excluded</td>
+          <td>{{excGroup}}</td>
+        </tr>
+        <tr>
+          <td>Size of Test Group</td>
+          <td>{{slide_value}}</td>
+        </tr>
+        <tr>
+          <td>Winner Criteria</td>
+          <td>{{winner_criteria}}</td>
+        </tr>
+
+        <tr ng-show="automated=='Yes'">
+          <td>Minum Confidence Level</td>
+          <td>{{conf}}%</td>
+        </tr>
+        <tr ng-show="automated=='Yes'">
+          <td>If Level not Achieved</td>
+          <td>{{ifnot}}</td>
+        </tr>
+        <tr>
+          <td>Declare Winner in</td>
+          <td>{{days}} Days {{hours}} Hours {{minutes}} Minutes</td>
+        </tr>
+      </table>
+
+      <h3><a href="#">Preview Mailing</a></h3><br>
+
+      <h3>When to Start</h3><br>
+
+      <div>
+        <input type="radio" name="Start" ng-model="start" value="now"> Now &nbsp
+        <input type="radio" name="Start" ng-model="start" value="later"> Later
+
+        &nbsp &nbsp <input type="text" class="dateplugin" ng-show="start=='later'" ng-model="send_date" datepick>
+      </div>
+
+
+      <br><br>
+
+      <div>
+
+        <div style="position:relative; left:200px; top:60px;" prevbutton></div>
+        <div class="crm-submit-buttons" style="position:relative; left:295px; top: 30px;">
+          <div class="crm-button crm-button-type-upload crm-button_qf_Contact_upload_view">
+            <input type="submit" value="Submit & Send" id="campaignbutton _qf_Contact_upload_view-top"
+                   class="btn btn-primary" nexttab={{tab_val}}>
+          </div>
         </div>
+        <div style="position:relative; left:430px; top:-1px;" cancelbutton></div>
 
-        <div id="tabs-4">
-
-            <h3>Details</h3><br>
-            <table>
-            <tr>
-                <td>Test Criteria</td>
-                <td>{{template.name}}</td>
-            </tr>
-            <tr>
-                 <td>Groups Included</td>
-                 <td>{{incGroup}}</td>
-            </tr>
-            <tr>
-                    <td>Groups Excluded</td>
-                    <td>{{excGroup}}</td>
-            </tr>
-            <tr>
-                 <td>Size of Test Group</td>
-                 <td>{{slide_value}}</td>
-            </tr>
-            <tr>
-                 <td>Winner Criteria</td>
-                 <td>{{winner_criteria}}</td>
-            </tr>
-
-            <tr ng-show="automated=='Yes'">
-                 <td>Minum Confidence Level</td>
-                 <td>{{conf}}%</td>
-            </tr>
-            <tr ng-show="automated=='Yes'">
-                 <td>If Level not Achieved</td>
-                 <td>{{ifnot}}</td>
-            </tr>
-            <tr>
-                 <td>Declare Winner in</td>
-                 <td>{{days}} Days {{hours}} Hours {{minutes}} Minutes</td>
-            </tr>
-            </table>
-
-            <h3><a href="#">Preview Mailing</a></h3><br>
-
-            <h3>When to Start</h3><br>
-            <div>
-            <input type="radio" name="Start" ng-model="start" value="now"> Now &nbsp
-            <input type="radio" name="Start"  ng-model="start" value="later"> Later
-
-            &nbsp &nbsp <input type="text"  class = "dateplugin" ng-show="start=='later'" ng-model="send_date" datepick>
-            </div>
-
-
-            <br><br>
-            <div>
-
-                <div style="position:relative; left:200px; top:60px;" prevbutton></div>
-                <div class="crm-submit-buttons" style="position:relative; left:295px; top: 30px;" >
-                  <div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view"   >
-                  <input type="submit" value="Submit & Send"  id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" nexttab={{tab_val}}>
-                  </div>
-                </div>
-                <div style="position:relative; left:430px; top:-1px;" cancelbutton></div>
-
-            </div>
+      </div>
 
-        </div>
     </div>
+  </div>
 </div>
\ No newline at end of file
index 9be2eda3cd74d3f67f8bd14d44aa173624b76815..86e27d76d54e28b68c2fd36b32dc41888cc52633 100644 (file)
@@ -925,7 +925,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       throw new Exception('Invalid getcount result : ' . print_r($result, TRUE) . " type :" . gettype($result));
     }
     if(is_int($count)){
-      $this->assertEquals($count, $result, "incorect count returned from $entity getcount");
+      $this->assertEquals($count, $result, "incorrect count returned from $entity getcount");
     }
     return $result;
   }
index e52b2c49aa5d8c7c03f12e289e331aabcddc1f4f..9e48d0e3bf68930f09a0d121a4dbc6ff0d9fe8e2 100644 (file)
@@ -78,7 +78,7 @@ class api_v3_MailingABTest extends CiviUnitTestCase {
    * Test civicrm_mailing_create
    */
   public function testMailingABCreateSuccess() {
-    $result = $this->callAPIAndDocument('MailingAB', 'create', $this->_params, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
     $this->assertTrue(is_numeric($result['id']), "In line " . __LINE__);
     $this->assertEquals($this->_params['group_percentage'], $result['values'][$result['id']]['group_percentage']);
   }
@@ -88,7 +88,6 @@ class api_v3_MailingABTest extends CiviUnitTestCase {
    */
   public function testMailerDeleteSuccess() {
     $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
-    $this->assertAPIDeleted($this->_entity, $result['id']);
+    $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
   }
-
 }