4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 namespace api\v
4\Action
;
22 use api\v
4\UnitTestCase
;
23 use Civi\Api4\Activity
;
28 class RecentItemsTest
extends UnitTestCase
{
30 public function testAddDeleteActivity(): void
{
31 $cid = $this->createLoggedInUser();
33 $aid1 = Activity
::create(FALSE)
34 ->addValue('activity_type_id:name', 'Meeting')
35 ->addValue('source_contact_id', $cid)
36 ->addValue('subject', 'Hello recent!')
37 ->execute()->first()['id'];
38 $this->assertEquals(1, $this->getRecentItemCount(['type' => 'Activity', 'id' => $aid1]));
39 $this->assertStringContainsString('Hello recent!', \CRM_Utils_Recent
::get()[0]['title']);
41 $aid2 = Activity
::create(FALSE)
42 ->addValue('activity_type_id:name', 'Meeting')
43 ->addValue('source_contact_id', $cid)
44 ->addValue('subject', 'Goodbye recent!')
45 ->execute()->first()['id'];
46 $this->assertEquals(1, $this->getRecentItemCount(['type' => 'Activity', 'id' => $aid2]));
47 $this->assertStringContainsString('Goodbye recent!', \CRM_Utils_Recent
::get()[0]['title']);
49 Activity
::delete(FALSE)->addWhere('id', '=', $aid1)->execute();
51 $this->assertEquals(0, $this->getRecentItemCount(['type' => 'Activity', 'id' => $aid1]));
52 $this->assertEquals(1, $this->getRecentItemCount(['type' => 'Activity', 'id' => $aid2]));
59 private function getRecentItemCount($props) {
61 foreach (\CRM_Utils_Recent
::get() as $item) {
62 foreach ($props as $key => $val) {
63 if (($item[$key] ??
NULL) != $val) {