Merged in bugfix/PMC-1341 (pull request #7201)

PMC-1341 PMCORE-491

Approved-by: Paula Quispe <paula.quispe@processmaker.com>
This commit is contained in:
Julio Cesar Laura Avendaño
2020-01-07 13:22:07 +00:00
2 changed files with 122 additions and 2 deletions

View File

@@ -0,0 +1,120 @@
<?php
use Tests\TestCase;
class PhpNameGeneratorTest extends TestCase
{
/**
* @var PhpNameGenerator
*/
var $phpNameGenerator;
/**
* Set up the test class
*/
public function setUp()
{
// Call the setUp parent method
parent::setUp();
// Include class "PhpNameGenerator" from "thirdparty" folder, this class is not loaded with composer
require_once PATH_THIRDPARTY . 'propel-generator/classes/propel/engine/database/model/PhpNameGenerator.php';
// Instance class PhpNameGenerator
$this->phpNameGenerator = new PhpNameGenerator();
}
/**
* Test "underscoreMethod" using texts with and without underscores
*
* @test
* @covers PhpNameGenerator::underscoreMethod()
*/
public function it_should_test_underscore_method_through_generate_name()
{
// To force to use the protected method "underscoreMethod"
$method = PhpNameGenerator::CONV_METHOD_UNDERSCORE;
// Assert for bug PMC-1341
$string = 'q_10_0_0';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('Q1000', $convertedString);
// Assert for a text in lowercase without underscores
$string = 'example';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('Example', $convertedString);
// Assert for a text in uppercase without underscores
$string = 'EXAMPLE';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('Example', $convertedString);
// Assert for a capitalized text without underscores, should be return the same value
$string = 'Example';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals($string, $convertedString);
// Assert for a text in lowercase with underscore
$string = 'first_name';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('FirstName', $convertedString);
// Assert for a text in lowercase with underscores
$string = 'this_is_my_text';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('ThisIsMyText', $convertedString);
// Assert for a mixed text with underscores
$string = 'this_Is_the_Number_1_to_check';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('ThisIsTheNumber1ToCheck', $convertedString);
}
/**
* Test "phpnameMethod" using texts with and without underscores
*
* @test
* @covers PhpNameGenerator::phpnameMethod()
*/
public function it_should_test_php_name_method_through_generate_name()
{
// To force to use the protected method "underscoreMethod"
$method = PhpNameGenerator::CONV_METHOD_UNDERSCORE;
// Assert for bug PMC-1341
$string = 'q_10_0_0';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('Q1000', $convertedString);
// Assert for a text in lowercase without underscores
$string = 'example';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('Example', $convertedString);
// Assert for a text in uppercase without underscores
$string = 'EXAMPLE';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('Example', $convertedString);
// Assert for a capitalized text without underscores, should be return the same value
$string = 'Example';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals($string, $convertedString);
// Assert for a text in lowercase with underscore
$string = 'first_name';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('FirstName', $convertedString);
// Assert for a text in lowercase with underscores
$string = 'this_is_my_text';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('ThisIsMyText', $convertedString);
// Assert for a mixed text with underscores
$string = 'this_Is_the_Number_1_to_check';
$convertedString = $this->phpNameGenerator->generateName([$string, $method]);
$this->assertEquals('ThisIsTheNumber1ToCheck', $convertedString);
}
}

View File

@@ -87,7 +87,7 @@ class PhpNameGenerator implements NameGenerator {
{
$name = "";
$tok = strtok($schemaName, self::STD_SEPARATOR_CHAR);
while($tok) {
while($tok !== false) {
$name .= ucfirst(strtolower($tok));
$tok = strtok(self::STD_SEPARATOR_CHAR);
}
@@ -110,7 +110,7 @@ class PhpNameGenerator implements NameGenerator {
{
$name = "";
$tok = strtok($schemaName, self::STD_SEPARATOR_CHAR);
while($tok) {
while($tok !== false) {
$name .= ucfirst($tok);
$tok = strtok(self::STD_SEPARATOR_CHAR);
}