Merged in bugfix/PMC-1153 (pull request #7063)

PMC-1153

Approved-by: Paula Quispe <paula.quispe@processmaker.com>
Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Julio Cesar Laura Avendaño
2019-09-10 12:03:38 +00:00
3 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
/**
* Model factory for web entries
*/
use Faker\Generator as Faker;
$factory->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'])
];
});

View File

@@ -0,0 +1,102 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel;
use G;
use ProcessMaker\BusinessModel\WebEntry as BmWebEntry;
use ProcessMaker\Model\WebEntry;
use Tests\TestCase;
/**
* Class WebEntryTest
*
* @coversDefaultClass \ProcessMaker\BusinessModel\WebEntry
*/
class WebEntryTest extends TestCase
{
/**
* Test if exist a Web Entry that uses a Uid like filename
*
* @test
*
* @covers \ProcessMaker\BusinessModel\WebEntry::isWebEntry()
*/
public function it_should_exist_web_entry_that_uses_uid_like_filename() {
// Initializing variables
$phpExtension = '.php';
$postFileExtension = 'Post.php';
$infoFileExtension = 'Info.php';
$webEntryFilename = G::generateUniqueID();
// 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 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);
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class WebEntry extends Model
{
// Set our table name
protected $table = 'WEB_ENTRY';
protected $primaryKey = 'WE_UID';
// We do not have create/update timestamps for this table
public $timestamps = false;
}