From 81c255e01b5c8d8bb61f695998030b16acd77950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Tue, 3 Sep 2019 13:35:27 -0400 Subject: [PATCH] PMC-1153 --- database/factories/WebEntryFactory.php | 33 ++++++ .../BusinessModel/WebEntryTest.php | 102 ++++++++++++++++++ .../src/ProcessMaker/Model/WebEntry.php | 15 +++ 3 files changed, 150 insertions(+) create mode 100644 database/factories/WebEntryFactory.php create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/WebEntryTest.php create mode 100644 workflow/engine/src/ProcessMaker/Model/WebEntry.php diff --git a/database/factories/WebEntryFactory.php b/database/factories/WebEntryFactory.php new file mode 100644 index 000000000..6161e2c4c --- /dev/null +++ b/database/factories/WebEntryFactory.php @@ -0,0 +1,33 @@ +define(\ProcessMaker\Model\WebEntry::class, function(Faker $faker) { + return [ + 'WE_UID' => G::generateUniqueID(), + 'PRO_UID' => G::generateUniqueID(), + 'TAS_UID' => G::generateUniqueID(), + 'DYN_UID' => G::generateUniqueID(), + 'USR_UID' => G::generateUniqueID(), + 'WE_METHOD' => $faker->randomElement(['WS', 'HTML']), + 'WE_INPUT_DOCUMENT_ACCESS' => $faker->randomElement([0, 1]), + 'WE_DATA' => G::generateUniqueID() . '.php', + 'WE_CREATE_USR_UID' => G::generateUniqueID(), + 'WE_UPDATE_USR_UID' => G::generateUniqueID(), + 'WE_CREATE_DATE' => $faker->date('Y-m-d H:i:s', 'now'), + 'WE_UPDATE_DATE' => $faker->date('Y-m-d H:i:s', 'now'), + 'WE_TYPE' => $faker->randomElement(['SINGLE', 'MULTIPLE']), + 'WE_CUSTOM_TITLE' => $faker->words(5, true), + 'WE_AUTHENTICATION' => $faker->randomElement(['LOGIN_REQUIRED', 'ANONYMOUS']), + 'WE_HIDE_INFORMATION_BAR' => $faker->randomElement(['0', '1']), + 'WE_CALLBACK' => $faker->randomElement(['PROCESSMAKER', 'CUSTOM', 'CUSTOM_CLEAR']), + 'WE_CALLBACK_URL' => $faker->url, + 'WE_LINK_GENERATION' => $faker->randomElement(['DEFAULT', 'ADVANCED']), + 'WE_LINK_SKIN' => 'classic', + 'WE_LINK_LANGUAGE' => 'en', + 'WE_LINK_DOMAIN' => $faker->domainName, + 'WE_SHOW_IN_NEW_CASE' => $faker->randomElement(['0', '1']) + ]; +}); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/WebEntryTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/WebEntryTest.php new file mode 100644 index 000000000..f3cf9fb9f --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/WebEntryTest.php @@ -0,0 +1,102 @@ +create(['WE_DATA' => $webEntryFilename . $phpExtension]); + + // Post file is from a valid Web Entry? + $isWebEntry = BmWebEntry::isWebEntry($webEntry->PRO_UID, $webEntryFilename . $postFileExtension); + $this->assertTrue($isWebEntry); + + // Information file is from a valid Web Entry? + $isWebEntry = BmWebEntry::isWebEntry($webEntry->PRO_UID, $webEntryFilename . $infoFileExtension); + $this->assertTrue($isWebEntry); + } + + /** + * Test if exist a Web Entry that uses a custom name like filename + * + * @test + * + * @covers \ProcessMaker\BusinessModel\WebEntry::isWebEntry() + */ + public function it_should_exist_web_entry_that_uses_custom_name_like_filename() { + // Initializing variables + $phpExtension = '.php'; + $postFileExtension = 'Post.php'; + $infoFileExtension = 'Info.php'; + $webEntryFilename = 'My_Custom_Form'; + + // Create a Web Entry + $webEntry = factory(WebEntry::class)->create(['WE_DATA' => $webEntryFilename . $phpExtension]); + + // Post file is from a valid Web Entry? + $isWebEntry = BmWebEntry::isWebEntry($webEntry->PRO_UID, $webEntryFilename . $postFileExtension); + $this->assertTrue($isWebEntry); + + // Information file is from a valid Web Entry? + $isWebEntry = BmWebEntry::isWebEntry($webEntry->PRO_UID, $webEntryFilename . $infoFileExtension); + $this->assertTrue($isWebEntry); + } + + /** + * Test if not exist a Web Entry + * + * @test + * + * @covers \ProcessMaker\BusinessModel\WebEntry::isWebEntry() + */ + public function it_should_not_exist_web_entry() { + // Initializing variables + $processThatNotExists = G::generateUniqueID(); + $webEntryThatNotExists = G::generateUniqueID() . '.php'; + + // File is from a valid Web Entry? + $isWebEntry = BmWebEntry::isWebEntry($processThatNotExists, $webEntryThatNotExists); + $this->assertFalse($isWebEntry); + } + + /** + * Test if is sent empty parameters to the method + * + * @test + * + * @covers \ProcessMaker\BusinessModel\WebEntry::isWebEntry() + */ + public function it_should_return_false_with_empty_parameters() { + // Initializing variables + $emptyProcess = ''; + $emptyFilePath = ''; + + // File is from a valid Web Entry? + $isWebEntry = BmWebEntry::isWebEntry($emptyProcess, $emptyFilePath); + $this->assertFalse($isWebEntry); + } +} diff --git a/workflow/engine/src/ProcessMaker/Model/WebEntry.php b/workflow/engine/src/ProcessMaker/Model/WebEntry.php new file mode 100644 index 000000000..eb141abaa --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/WebEntry.php @@ -0,0 +1,15 @@ +