<?php

namespace Tests\unit\workflow\engine\classes\PmFunctions;

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\TaskUser;
use ProcessMaker\Model\User;
use Tests\TestCase;

/**
 * Test the PMFTaskList() function
 *
 * @link https://wiki.processmaker.com/3.2/ProcessMaker_Functions/Task_Functions#PMFTaskList.28.29
 */
class PMFTaskListTest extends TestCase
{
    use DatabaseTransactions;

    /**
     * This tests if the "PMFTaskList"
     * @test
     */
    public function it_return_pending_tasks()
    {
        // Create task
        $task = Task::factory()->create();
        // Create user
        $user = User::factory()->create();
        // Assign a user in the task
        TaskUser::factory()->create([
            'TAS_UID' => $task->TAS_UID,
            'USR_UID' => $user->USR_UID,
            'TU_RELATION' => 1, //Related to the user
            'TU_TYPE' => 1
        ]);
        DB::commit();
        $result = PMFTaskList($user->USR_UID);
        $this->assertNotEmpty($result);
    }
}
