Commit 29a1747d authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fix PHP Unit Tests

parent 57a4e6b9
......@@ -95,7 +95,6 @@ class BuildFormTable extends AbstractBuildForm {
/**
* @param $htmlFormElementName
* @param $formElement
* @param $value
*
* @return string
*/
......
......@@ -7,6 +7,7 @@ require_once(__DIR__ . '/AbstractDatabaseTest.php');
require_once(__DIR__ . '/../../qfq/database/Database.php');
require_once(__DIR__ . '/../../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/../../qfq/helper/Support.php');
class BuildFormPlainTest extends AbstractDatabaseTest {
......@@ -322,113 +323,116 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$json = array();
$this->templateFormNFormElement($form, $formElement);
$formElement = \qfq\Support::setFeDefaults($formElement);
// CheckType
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
// id: 1, firstName: John, name: Doe
$formElement['sql1'] = $this->db->sql('SELECT id, name, firstName FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tr class="record" ><td>1</td><td>Doe</td><td>John</td></tr><tr class="record" ><td>2</td><td>Smith</td><td>Jane</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tr class="record" ><td>1</td><td>Doe</td><td>John</td></tr><tr class="record" ><td>2</td><td>Smith</td><td>Jane</td></tr></table>', $result);
// _id: 1, name: Doe,
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>name</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
// _id: 1, name: Doe,title=''
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "title=" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th></th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
// _id: 1, name: Doe, column: _Person
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "unused|width=2|title=_Person", firstName FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>firstName</th></tr></thead><tr class="record" ><td>John</td></tr><tr class="record" ><td>Jane</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>firstName</th></tr></thead><tr class="record" ><td>John</td></tr><tr class="record" ><td>Jane</td></tr></table>', $result);
// _id: 1, name: Doe, title: PERSON
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>PERSON</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PERSON</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
// _id: 1, "This is a much longer text than necessary": Default max:20
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "This is a much longer text than necessary" FROM Person ORDER BY id LIMIT 1');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>This is a much longe</th></tr></thead><tr class="record" ><td>This is a much longe</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>This is a much longe</th></tr></thead><tr class="record" ><td>This is a much longe</td></tr></table>', $result);
// _id: 1, name: Jo (width:2)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "2" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th></th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
// _id: 1, name: Jo (width:2)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "2|PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>PE</th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PE</th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
// _id: 1, name: Doe ('width':3)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "Name|width=3" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>Nam</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Nam</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></table>', $result);
// _id: 1, name: Doe (width:3, title:PERSON)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "3|title=PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>PER</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PER</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></table>', $result);
// _id: 1, name: <b>Doe</b>
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>Name</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
// _id: 1, name: <b>Doe</b>, width=2
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|2" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>Na</th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Na</th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
// _id: 1, name: <b>Doe</b> , nostrip
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|nostrip" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>Name</th></tr></thead><tr class="record" ><td><b>Doe</b></td></tr><tr class="record" ><td><b>Smith</b></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tr class="record" ><td><b>Doe</b></td></tr><tr class="record" ><td><b>Smith</b></td></tr></table>', $result);
// _id: 1, icon: bullet-green.gif
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "bullet-green.gif" AS "Status|icon" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>Status</th></tr></thead><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Status</th></tr></thead><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr></table>', $result);
// _id: 1, mailto: john@doe.com
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "john@doe.com" AS "EMail|mailto" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>EMail</th></tr></thead><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>EMail</th></tr></thead><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr></table>', $result);
// _id: 1, url: www.uzh.ch
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "www.uzh.ch" AS "URL|url" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>URL</th></tr></thead><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>URL</th></tr></thead><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr></table>', $result);
// _id: 1, name: Doe, _rowclass (text)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, IF(id=1,"text-warning", "text-danger") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>name</th></tr></thead><tr class="record text-warning" ><td>Doe</td></tr><tr class="record text-danger" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record text-warning" ><td>Doe</td></tr><tr class="record text-danger" ><td>Smith</td></tr></table>', $result);
// _id: 1, name: Doe, _rowClass (text & background)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, IF(id=1,"text-warning active", "text-danger success") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>name</th></tr></thead><tr class="record text-warning active" ><td>Doe</td></tr><tr class="record text-danger success" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record text-warning active" ><td>Doe</td></tr><tr class="record text-danger success" ><td>Smith</td></tr></table>', $result);
// _id: 1, name: Doe, _rowTitle
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, firstName AS _rowTitle FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>name</th></tr></thead><tr class="record" title="John" ><td>Doe</td></tr><tr class="record" title="Jane" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record" title="John" ><td>Doe</td></tr><tr class="record" title="Jane" ><td>Smith</td></tr></table>', $result);
// _id: 1, name: Doe, title, width, nostrip
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, "<b>This again is a very long text</b>" AS "title=Important|width=10|nostrip" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>name</th><th>Important</th></tr></thead><tr class="record" ><td>Doe</td><td><b>This again is a very long text</b></td></tr><tr class="record" ><td>Smith</td><td><b>This again is a very long text</b></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th>Important</th></tr></thead><tr class="record" ><td>Doe</td><td><b>This again is a very long text</b></td></tr><tr class="record" ><td>Smith</td><td><b>This again is a very long text</b></td></tr></table>', $result);
// _id: 1, name: Doe, link
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, CONCAT("s:1|p:form&form=person&r=" , id , "|t:", name) AS "link" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class=\'table table-hover\'><thead><tr><th>name</th><th></th></tr></thead><tr class="record" ><td>Doe</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Doe</a></td></tr><tr class="record" ><td>Smith</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Smith</a></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th></th></tr></thead><tr class="record" ><td>Doe</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Doe</a></td></tr><tr class="record" ><td>Smith</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Smith</a></td></tr></table>', $result);
}
/**
......@@ -467,6 +471,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
FE_NAME => 'name',
FE_LABEL => 'Name',
FE_MODE => 'show',
FE_MODE_SQL => '',
'class' => 'native',
FE_TYPE => 'input',
'value' => '',
......
......@@ -20,7 +20,6 @@ class FakeTSFE {
class SupportTest extends \PHPUnit_Framework_TestCase {
/**
* @var Store
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment