mirror of
https://codeberg.org/artfulrobot/contactcats.git
synced 2025-06-26 05:48:05 +02:00
update tests, fix stuff, implement bespoke save, create actions for contactcategory
This commit is contained in:
parent
78e5b83c1d
commit
2ae781f6e3
6 changed files with 273 additions and 29 deletions
|
@ -96,15 +96,24 @@ class GetFlowsTest extends \PHPUnit\Framework\TestCase implements HeadlessInterf
|
|||
])
|
||||
->execute()->column('id');
|
||||
|
||||
// Create a contact
|
||||
$ctID = Contact::create(FALSE)
|
||||
->setValues([
|
||||
'contact_type' => 'Individual',
|
||||
'display_name' => 'Wilma',
|
||||
])->execute()->first()['id'];
|
||||
// print "xxxxx created ct $ctID\n";
|
||||
[$ctID, $ctID2] = Contact::save(FALSE)
|
||||
->setDefaults(['contact_type' => 'Individual'])
|
||||
->setRecords([
|
||||
['display_name' => 'Wilma'],
|
||||
['display_name' => 'Fred'],
|
||||
])->execute()->column('id');
|
||||
|
||||
// Create two activities.
|
||||
// Put them in meh category. This is not required for the test,
|
||||
// but makes the data realistic.
|
||||
$ccIDs = ContactCategory::save(FALSE)
|
||||
->setRecords([
|
||||
['id' => $ctID, 'category_definition_id' => $mehCatID],
|
||||
['id' => $ctID2, 'category_definition_id' => $mehCatID],
|
||||
])->execute()->column('id');
|
||||
$this->assertEquals([$ctID, $ctID2], $ccIDs);
|
||||
// print "ccs\n" . implode("\n", array_map('json_encode', CRM_Core_DAO::executeQuery("SELECT * from civicrm_contact_category cc")->fetchAll())) . "\n---\n";
|
||||
|
||||
// Create two activities for ct1 and just one for ct2
|
||||
$activityIDs = Activity::save(FALSE)
|
||||
->setDefaults([
|
||||
'activity_type_id:name' => 'changed_contact_category',
|
||||
|
@ -115,23 +124,33 @@ class GetFlowsTest extends \PHPUnit\Framework\TestCase implements HeadlessInterf
|
|||
[
|
||||
'activity_date_time' => '2025-01-01',
|
||||
'Category_changes.new_category_id' => $amazingCatID,
|
||||
'subject' => "Fake subject: $ctID change to amazing from nothing",
|
||||
],
|
||||
[
|
||||
'activity_date_time' => '2025-01-01',
|
||||
'Category_changes.new_category_id' => $mehCatID,
|
||||
'target_contact_id' => $ctID2,
|
||||
'subject' => "Fake subject: $ctID2 change to meh from nothing",
|
||||
],
|
||||
[
|
||||
'activity_date_time' => '2025-02-01',
|
||||
'Category_changes.new_category_id' => $mehCatID,
|
||||
'subject' => "Fake subject: $ctID change to meh from amazing",
|
||||
],
|
||||
])->execute()->column('id');
|
||||
|
||||
// $acts = Activity::get(FALSE)->addWhere('id', 'IN', $activityIDs)->execute()->getArrayCopy(); print_r($acts);
|
||||
|
||||
// FIXME: this is returning backwards.
|
||||
// ================
|
||||
// At 3 Jan, we had 1 amazing, 1 meh
|
||||
// Later, 1 amazing moved to meh.
|
||||
// Flows should return non-changes, too.
|
||||
$flows = ContactCategory::getFlows()
|
||||
->setStartDate('2025-01-03')
|
||||
->execute()->getArrayCopy();
|
||||
// print_r($flows);
|
||||
$this->assertEquals([
|
||||
['from_category_id' => $amazingCatID, 'to_category_id' => $mehCatID, 'contact_count' => 1],
|
||||
['from_category_id' => $mehCatID, 'to_category_id' => $mehCatID, 'contact_count' => 1],
|
||||
], $flows);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue