Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #843: Fixed bug when single inheritance keys contain special chars #847

Merged
merged 1 commit into from Mar 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion generator/lib/model/Inheritance.php
Expand Up @@ -34,7 +34,8 @@ class Inheritance extends XMLElement
*/
protected function setupObject()
{
$this->key = $this->getAttribute("key");
// Clean key from special characters not allowed in constant names
$this->key = rtrim(preg_replace('/(\W|_)+/', '_', $this->getAttribute("key")), '_');
$this->className = $this->getAttribute("class");
$this->pkg = $this->getAttribute("package");
$this->ancestor = $this->getAttribute("extends");
Expand Down
@@ -0,0 +1,90 @@
<?php
require_once dirname(__FILE__) . '/../../../../../generator/lib/util/PropelQuickBuilder.php';
require_once dirname(__FILE__) . '/../../../../../runtime/lib/adapter/DBAdapter.php';
require_once dirname(__FILE__) . '/../../../../../runtime/lib/adapter/DBSQLite.php';
require_once dirname(__FILE__) . '/../../../../../runtime/lib/connection/PropelPDO.php';
require_once dirname(__FILE__) . '/../../../../../runtime/lib/Propel.php';
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

/**
* Tests for generated constants' names.
*
* @author Boban Acimovic <boban.acimovic@gmail.com>
* @package generator.builder.om
*/
class GeneratedObjectConstantNameTest extends PHPUnit_Framework_TestCase
{
/**
* Test normal string as single inheritance key
*/
public function testSingleInheritanceKeyNormalString()
{
$schema = <<<XML
<database name="constant_name_test" namespace="ConstantNameTest1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd">
<table name="radcheck" phpName="UserCheck">
<column name="id" type="INTEGER" sqlType="int(11) unsigned" primaryKey="true" autoIncrement="true" required="true"/>
<column name="attribute" type="VARCHAR" size="64" required="true" inheritance="single">
<inheritance key="Expiration" class="UserCheckExpiration" extends="UserCheck"/>
</column>
</table>
</database>
XML;
$this->assertEmptyBuilderOutput($schema);
}

/**
* Test string with dashes as single inheritance key (original cause for this whole test)
*/

public function testSingleInheritanceKeyStringWithDashes()
{
$schema = <<<XML
<database name="constant_name_test" namespace="ConstantNameTest2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd">
<table name="radcheck" phpName="UserCheck2">
<column name="id" type="INTEGER" sqlType="int(11) unsigned" primaryKey="true" autoIncrement="true" required="true"/>
<column name="attribute" type="VARCHAR" size="64" required="true" inheritance="single">
<inheritance key="Calling-Station-Id" class="UserCheckMacAddress" extends="UserCheck2"/>
</column>
</table>
</database>
XML;
$this->assertEmptyBuilderOutput($schema);
}

/**
* Test string with special characters as single inheritance key
*/

public function testSingleInheritanceKeyStringWithSpecialChars()
{
$schema = <<<XML
<database name="constant_name_test" namespace="ConstantNameTest3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd">
<table name="radcheck" phpName="UserCheck3">
<column name="id" type="INTEGER" sqlType="int(11) unsigned" primaryKey="true" autoIncrement="true" required="true"/>
<column name="attribute" type="VARCHAR" size="64" required="true" inheritance="single">
<inheritance key="Key.-_:*" class="UserCheckMacAddress" extends="UserCheck3"/>
</column>
</table>
</database>
XML;
$this->assertEmptyBuilderOutput($schema);
}

protected function assertEmptyBuilderOutput($schema)
{
$builder = new PropelQuickBuilder();
$builder->setSchema($schema);

ob_start();
$builder->buildClasses();
$output = preg_replace('/[\r\n]/', '', ob_get_contents());
ob_end_clean();
$this->assertEquals('', $output);
}
}