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 $aid = 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'];
39 $this->assertEquals(1, $this->getRecentItemCount(['type' => 'Activity', 'id' => $aid]));
41 $this->assertStringContainsString('Hello recent!', \CRM_Utils_Recent
::get()[0]['title']);
43 Activity
::delete(FALSE)->addWhere('id', '=', $aid)->execute();
45 $this->assertEquals(0, $this->getRecentItemCount(['type' => 'Activity', 'id' => $aid]));
48 private function getRecentItemCount($props) {
50 foreach (\CRM_Utils_Recent
::get() as $item) {
51 foreach ($props as $key => $val) {
52 if (($item[$key] ??
NULL) != $val) {