afform_mock - The extra dep should be a real module
authorTim Otten <totten@civicrm.org>
Thu, 19 Dec 2019 03:03:53 +0000 (19:03 -0800)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:20 +0000 (19:13 -0700)
Using a real Angular module means that the page can be opened in an E2E test.

ext/afform/mock/ang/mockBespoke.ang.php [new file with mode: 0644]
ext/afform/mock/ang/mockBespoke.css [new file with mode: 0644]
ext/afform/mock/ang/mockBespoke.js [new file with mode: 0644]
ext/afform/mock/ang/mockPage.aff.json
ext/afform/mock/tests/phpunit/api/v4/AfformTest.php

diff --git a/ext/afform/mock/ang/mockBespoke.ang.php b/ext/afform/mock/ang/mockBespoke.ang.php
new file mode 100644 (file)
index 0000000..ecbfb40
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+// This file declares an Angular module which can be autoloaded
+// in CiviCRM. See also:
+// \https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules/n
+return array (
+  'js' =>
+  array (
+    0 => 'ang/mockBespoke.js',
+    1 => 'ang/mockBespoke/*.js',
+    2 => 'ang/mockBespoke/*/*.js',
+  ),
+  'css' =>
+  array (
+    0 => 'ang/mockBespoke.css',
+  ),
+  'partials' =>
+  array (
+    0 => 'ang/mockBespoke',
+  ),
+  'requires' =>
+  array (
+    0 => 'crmUi',
+    1 => 'crmUtil',
+    2 => 'ngRoute',
+  ),
+  'settings' =>
+  array (
+  ),
+);
diff --git a/ext/afform/mock/ang/mockBespoke.css b/ext/afform/mock/ang/mockBespoke.css
new file mode 100644 (file)
index 0000000..3e347a3
--- /dev/null
@@ -0,0 +1 @@
+/* Add any CSS rules for Angular module "mockBespoke" */
diff --git a/ext/afform/mock/ang/mockBespoke.js b/ext/afform/mock/ang/mockBespoke.js
new file mode 100644 (file)
index 0000000..9eaf766
--- /dev/null
@@ -0,0 +1,4 @@
+(function(angular, $, _) {
+  // Declare a list of dependencies.
+  angular.module('mockBespoke', CRM.angRequires('mockBespoke'));
+})(angular, CRM.$, CRM._);
index de1f8212ec5f5fe5bfe64ba0708c8a5bbae6e388..2bdf31cc781f78408650f25c760ef65c26989073 100644 (file)
@@ -1 +1 @@
-{"server_route": "civicrm/mock-page", "requires":["extraMock"], "permission": "access Foobar" }
+{"server_route": "civicrm/mock-page", "requires":["mockBespoke"], "permission": "access Foobar" }
index cd1af772d22044d94f5cde7ebe714688f1544819..392e9f95010fdbaad3316780caa63b78f1d4ab6e 100644 (file)
@@ -205,9 +205,9 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
     // The default mockPage has 1 explicit requirement + 2 automatic requirements.
     Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
     $angModule = Civi::service('angular')->getModule($formName);
-    $this->assertEquals(['afCore', 'extraMock', 'mockBareFile', 'mockFoo'], $angModule['requires']);
+    $this->assertEquals(['afCore', 'mockBespoke', 'mockBareFile', 'mockFoo'], $angModule['requires']);
     $storedRequires = Civi\Api4\Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
-    $this->assertEquals(['extraMock'], $storedRequires[0]['requires']);
+    $this->assertEquals(['mockBespoke'], $storedRequires[0]['requires']);
 
     // Knock down to 1 explicit + 1 automatic.
     Civi\Api4\Afform::update()
@@ -216,9 +216,9 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
       ->setValues(['layout' => '<div>The bare file says "<span mock-bare-file/>"</div>'])
       ->execute();
     $angModule = Civi::service('angular')->getModule($formName);
-    $this->assertEquals(['afCore', 'extraMock', 'mockBareFile'], $angModule['requires']);
+    $this->assertEquals(['afCore', 'mockBespoke', 'mockBareFile'], $angModule['requires']);
     $storedRequires = Civi\Api4\Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
-    $this->assertEquals(['extraMock'], $storedRequires[0]['requires']);
+    $this->assertEquals(['mockBespoke'], $storedRequires[0]['requires']);
 
     // Remove the last explict and implicit requirements.
     Civi\Api4\Afform::update()
@@ -236,7 +236,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
 
     Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
     $angModule = Civi::service('angular')->getModule($formName);
-    $this->assertEquals(['afCore', 'extraMock', 'mockBareFile', 'mockFoo'], $angModule['requires']);
+    $this->assertEquals(['afCore', 'mockBespoke', 'mockBareFile', 'mockFoo'], $angModule['requires']);
   }
 
 }