Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dataprocessor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Extensions
dataprocessor
Commits
e970c847
Commit
e970c847
authored
5 years ago
by
sarvesh21
Browse files
Options
Downloads
Patches
Plain Diff
added testcase for importing data processor
parent
125827f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!12
Testing
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/phpunit/CRM/Myextension/ImportDataProcessorTest.php
+155
-0
155 additions, 0 deletions
tests/phpunit/CRM/Myextension/ImportDataProcessorTest.php
tests/phpunit/CRM/Myextension/test.json
+73
-0
73 additions, 0 deletions
tests/phpunit/CRM/Myextension/test.json
with
228 additions
and
0 deletions
tests/phpunit/CRM/Myextension/ImportDataProcessorTest.php
0 → 100644
+
155
−
0
View file @
e970c847
<?php
use
CRM_Dataprocessor_ExtensionUtil
as
E
;
use
Civi\Test\HeadlessInterface
;
use
Civi\Test\HookInterface
;
use
Civi\Test\TransactionalInterface
;
/**
* FIXME - Add test description.
*
* Tips:
* - With HookInterface, you may implement CiviCRM hooks directly in the test class.
* Simply create corresponding functions (e.g. "hook_civicrm_post(...)" or similar).
* - With TransactionalInterface, any data changes made by setUp() or test****() functions will
* rollback automatically -- as long as you don't manipulate schema or truncate tables.
* If this test needs to manipulate schema or truncate tables, then either:
* a. Do all that using setupHeadless() and Civi\Test.
* b. Disable TransactionalInterface, and handle all setup/teardown yourself.
*
* @group headless
*/
class
CRM_Myextension_MyHeadlessTest
extends
\PHPUnit_Framework_TestCase
implements
HeadlessInterface
,
HookInterface
,
TransactionalInterface
{
public
function
setUpHeadless
()
{
// Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
// See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
return
\Civi\Test
::
headless
()
->
installMe
(
__DIR__
)
->
apply
();
}
public
function
setUp
()
{
parent
::
setUp
();
}
public
function
tearDown
()
{
parent
::
tearDown
();
}
public
function
checkDataProcessor
(
$result
,
$id
){
$returnvalue
=
True
;
$values
=
$result
[
'values'
][
$id
];
if
(
$values
[
'name'
]
!=
'test'
)
$returnvalue
=
False
;
if
(
$values
[
'title'
]
!=
'Test'
)
$returnvalue
=
False
;
if
(
$values
[
'description'
]
!=
'This is a test Data Processor'
)
$returnvalue
=
False
;
if
(
$values
[
'is_active'
]
!=
1
)
$returnvalue
=
False
;
return
$returnvalue
;
}
public
function
checkDataProcessorFields
(
$fields
){
$keys
=
array_keys
(
$fields
[
'values'
]);
$returnvalue
=
True
;
$field_0
=
$fields
[
'values'
][
$keys
[
0
]];
if
(
$field_0
[
'name'
]
!=
'contact_id'
)
$returnvalue
=
False
;
if
(
$field_0
[
'configuration'
][
'field'
]
!=
'id'
)
$returnvalue
=
False
;
if
(
$field_0
[
'configuration'
][
'datasource'
]
!=
'contact'
)
$returnvalue
=
False
;
$field_1
=
$fields
[
'values'
][
$keys
[
1
]];
if
(
$field_1
[
'name'
]
!=
'first_name'
)
$returnvalue
=
False
;
if
(
$field_1
[
'configuration'
][
'field'
]
!=
'first_name'
)
$returnvalue
=
False
;
if
(
$field_1
[
'configuration'
][
'datasource'
]
!=
'contact'
)
$returnvalue
=
False
;
$field_2
=
$fields
[
'values'
][
$keys
[
2
]];
if
(
$field_2
[
'name'
]
!=
'gender'
)
$returnvalue
=
False
;
if
(
$field_2
[
'configuration'
][
'field'
]
!=
'gender_id'
)
$returnvalue
=
False
;
if
(
$field_2
[
'configuration'
][
'datasource'
]
!=
'contact'
)
$returnvalue
=
False
;
return
$returnvalue
;
}
public
function
checkDataProcessorSource
(
$datasource
){
$keys
=
array_keys
(
$datasource
[
'values'
]);
$returnvalue
=
True
;
$datasource_check
=
$datasource
[
'values'
][
$keys
[
0
]];
if
(
$datasource_check
[
'name'
]
!=
'contact'
)
$returnvalue
=
False
;
if
(
$datasource_check
[
'title'
]
!=
'Contact'
)
$returnvalue
=
False
;
if
(
$datasource_check
[
'type'
]
!=
'contact'
)
$returnvalue
=
False
;
if
(
$datasource_check
[
'configuration'
][
'filter'
][
'is_deleted'
][
'op'
]
!=
'='
)
$returnvalue
=
False
;
if
(
$datasource_check
[
'configuration'
][
'filter'
][
'is_deleted'
][
'value'
]
!=
0
)
$returnvalue
=
False
;
return
$returnvalue
;
}
public
function
checkDataProcessorOutput
(
$output
){
$keys
=
array_keys
(
$output
[
'values'
]);
$returnvalue
=
True
;
$output_check
=
$output
[
'values'
][
$keys
[
0
]];
if
(
$output_check
[
'type'
]
!=
'contact_search'
)
$returnvalue
=
False
;
if
(
$output_check
[
'configuration'
][
'title'
]
!=
'Test'
)
$returnvalue
=
False
;
if
(
$output_check
[
'configuration'
][
'contact_id_field'
]
!=
'contact_id'
)
$returnvalue
=
False
;
return
$returnvalue
;
}
public
function
testImportDataProcessor
()
{
$file
=
__DIR__
.
'/test.json'
;
$configuration
=
file_get_contents
(
$file
);
$importCode
=
json_decode
(
$configuration
,
true
);
$importResult
=
CRM_Dataprocessor_Utils_Importer
::
import
(
$importCode
,
''
,
true
);
$id
=
$importResult
[
'original_id'
];
$result
=
civicrm_api3
(
'DataProcessor'
,
'get'
,
array
(
"id"
=>
$id
));
$fields
=
civicrm_api3
(
'DataProcessorField'
,
'get'
,
array
(
"data_processor_id"
=>
$id
));
$datasource
=
civicrm_api3
(
'DataProcessorSource'
,
'get'
,
array
(
"data_processor_id"
=>
$id
));
$outputs
=
civicrm_api3
(
'DataProcessorOutput'
,
'get'
,
array
(
"data_processor_id"
=>
$id
));
if
(
$this
->
checkDataProcessor
(
$result
,
$id
))
$this
->
assertTrue
(
true
);
else
$this
->
assertFalse
(
true
);
if
(
$this
->
checkDataProcessorFields
(
$fields
))
$this
->
assertTrue
(
true
);
else
$this
->
assertFalse
(
true
);
if
(
$this
->
checkDataProcessorSource
(
$datasource
))
$this
->
assertTrue
(
true
);
else
$this
->
assertFalse
(
true
);
if
(
$this
->
checkDataProcessorOutput
(
$outputs
))
$this
->
assertTrue
(
true
);
else
$this
->
assertFalse
(
true
);
}
}
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Myextension/test.json
0 → 100644
+
73
−
0
View file @
e970c847
{
"name"
:
"test"
,
"title"
:
"Test"
,
"type"
:
"default"
,
"configuration"
:
[],
"aggregation"
:
[],
"is_active"
:
"1"
,
"description"
:
"This is a test Data Processor"
,
"storage_configuration"
:
[],
"data_sources"
:
[
{
"weight"
:
"1"
,
"name"
:
"contact"
,
"title"
:
"Contact"
,
"type"
:
"contact"
,
"configuration"
:
{
"filter"
:
{
"is_deleted"
:
{
"op"
:
"="
,
"value"
:
"0"
}
}
},
"join_configuration"
:
[]
}
],
"filters"
:
[],
"fields"
:
[
{
"weight"
:
"1"
,
"name"
:
"contact_id"
,
"title"
:
"Contact ID"
,
"type"
:
"raw"
,
"configuration"
:
{
"field"
:
"id"
,
"datasource"
:
"contact"
}
},
{
"weight"
:
"2"
,
"name"
:
"first_name"
,
"title"
:
"First Name"
,
"type"
:
"raw"
,
"configuration"
:
{
"field"
:
"first_name"
,
"datasource"
:
"contact"
}
},
{
"weight"
:
"3"
,
"name"
:
"gender"
,
"title"
:
"Gender"
,
"type"
:
"raw"
,
"configuration"
:
{
"field"
:
"gender_id"
,
"datasource"
:
"contact"
}
}
],
"outputs"
:
[
{
"type"
:
"contact_search"
,
"configuration"
:
{
"title"
:
"Test"
,
"contact_id_field"
:
"contact_id"
,
"hide_id_field"
:
"0"
,
"help_text"
:
""
,
"navigation_parent_path"
:
"Search"
},
"permission"
:
"access CiviCRM"
}
]
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment