diff --git a/test/unitTests/app/notification/DiffusionTypesControllerTest.php b/test/unitTests/app/notification/DiffusionTypesControllerTest.php index a6b6b80bd9cd2e7c594f11f596dd61286b9ee05d..d1d801a82a3bffce16029767291203cd9286839e 100755 --- a/test/unitTests/app/notification/DiffusionTypesControllerTest.php +++ b/test/unitTests/app/notification/DiffusionTypesControllerTest.php @@ -110,7 +110,7 @@ class DiffusionTypesControllerTest extends TestCase } } - public function testGetRecipientsByDestEntity() + public function testGetRecipientsByDestUser() { $diffusionTypesController = new \Notification\controllers\DiffusionTypesController(); @@ -192,4 +192,173 @@ class DiffusionTypesControllerTest extends TestCase $this->assertEmpty($response); } } + + public function testGetRecipientsByDestEntity() + { + $diffusionTypesController = new \Notification\controllers\DiffusionTypesController(); + + foreach ($GLOBALS['resources'] as $resId) { + $args = [ + 'notification' => [ + 'diffusion_type' => 'dest_entity' + ], + 'request' => 'recipients', + 'event' => [ + 'record_id' => $resId + ] + ]; + + $response = $diffusionTypesController->getItemsToNotify($args); + foreach ($response as $entity) { + $this->assertSame('PJS', $entity['entity_id']); + $this->assertSame('Y', $entity['enabled']); + $this->assertSame('support@maarch.fr', $entity['mail']); + } + } + + foreach ($GLOBALS['resources'] as $resId) { + $args = [ + 'notification' => [ + 'diffusion_type' => 'dest_entity', + 'diffusion_properties' => 'NEW,COU,CLO,END,ATT,VAL,INIT' + ], + 'request' => 'res_id', + 'event' => [ + 'record_id' => $resId, + 'table_name' => 'res_letterbox' + ] + ]; + + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertSame($resId, $response); + + $args['event']['table_name'] = 'notes'; + $args['event']['record_id'] = 1; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertEmpty($response); + + $args['event']['table_name'] = 'listinstance'; + $args['event']['user_id'] = 19; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertEmpty($response); + } + } + + public function testGetRecipientsByDestUserSign() + { + $diffusionTypesController = new \Notification\controllers\DiffusionTypesController(); + + foreach ($GLOBALS['resources'] as $resId) { + $args = [ + 'notification' => [ + 'diffusion_type' => 'dest_user_sign', + 'diffusion_properties' => 'NEW,COU,CLO,END,ATT,VAL,INIT,ESIG,EVIS' + ], + 'request' => 'recipients', + 'event' => [ + 'record_id' => $resId, + 'table_name' => 'res_letterbox' + ] + ]; + + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertIsArray($response); + + $args['event']['table_name'] = 'notes'; + $args['event']['record_id'] = 1; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertIsArray($response); + + $args['event']['table_name'] = 'listinstance'; + $args['event']['user_id'] = 19; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertIsArray($response); + } + + foreach ($GLOBALS['resources'] as $resId) { + $args = [ + 'notification' => [ + 'diffusion_type' => 'dest_user_sign', + 'diffusion_properties' => 'NEW,COU,CLO,END,ATT,VAL,INIT' + ], + 'request' => 'res_id', + 'event' => [ + 'record_id' => $resId, + 'table_name' => 'res_letterbox' + ] + ]; + + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertSame($resId, $response); + + $args['event']['table_name'] = 'notes'; + $args['event']['record_id'] = 1; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertEmpty($response); + + $args['event']['table_name'] = 'listinstance'; + $args['event']['user_id'] = 19; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertEmpty($response); + } + } + + public function testGetRecipientsByDestUserVisa() + { + $diffusionTypesController = new \Notification\controllers\DiffusionTypesController(); + + foreach ($GLOBALS['resources'] as $resId) { + $args = [ + 'notification' => [ + 'diffusion_type' => 'dest_user_visa', + 'diffusion_properties' => 'NEW,COU,CLO,END,ATT,VAL,INIT,ESIG,EVIS' + ], + 'request' => 'recipients', + 'event' => [ + 'record_id' => $resId, + 'table_name' => 'res_letterbox' + ] + ]; + + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertIsArray($response); + + $args['event']['table_name'] = 'notes'; + $args['event']['record_id'] = 1; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertIsArray($response); + + $args['event']['table_name'] = 'listinstance'; + $args['event']['user_id'] = 19; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertIsArray($response); + } + + foreach ($GLOBALS['resources'] as $resId) { + $args = [ + 'notification' => [ + 'diffusion_type' => 'dest_user_visa', + 'diffusion_properties' => 'NEW,COU,CLO,END,ATT,VAL,INIT' + ], + 'request' => 'res_id', + 'event' => [ + 'record_id' => $resId, + 'table_name' => 'res_letterbox' + ] + ]; + + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertSame($resId, $response); + + $args['event']['table_name'] = 'notes'; + $args['event']['record_id'] = 1; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertEmpty($response); + + $args['event']['table_name'] = 'listinstance'; + $args['event']['user_id'] = 19; + $response = $diffusionTypesController->getItemsToNotify($args); + $this->assertEmpty($response); + } + } }