Skip to content

Commit

Permalink
[#12379] - Corrections to the tag; Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Dec 11, 2018
1 parent 8dd2ad6 commit c3041d3
Show file tree
Hide file tree
Showing 17 changed files with 990 additions and 214 deletions.
289 changes: 268 additions & 21 deletions phalcon/html/tag.zep

Large diffs are not rendered by default.

173 changes: 92 additions & 81 deletions tests/_data/fixtures/Traits/TagHelperTrait.php
Expand Up @@ -42,91 +42,102 @@ public function tagField(UnitTester $I)
$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected);
$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected, true);
}
//
// /**
// * Tests Phalcon\Tag :: input*() - parameters and id in it
// *
// * @author Phalcon Team <team@phalconphp.com>
// * @since 2014-09-05
// */
// public function tagFieldParameterWithId(UnitTester $I)
// {
// $I->wantToTest(sprintf('Tag - %s() - parameters with id', $this->function));
// $tag = new Tag();
// $tag->setDI($this->container);
//
// $options = [
// 'name' => 'x_name',
// 'id' => 'x_id',
// 'class' => 'x_class',
// 'size' => '10',
// ];
// $expected = '<input type="' . $this->inputType . '" id="x_id" name="x_name" '
// . 'class="x_class" size="10"';
//
// $this->testFieldParameter($I, $tag, $this->function, $options, $expected);
// $this->testFieldParameter($I, $tag, $this->function, $options, $expected, true);
// }
//
// /**
// * Tests Phalcon\Tag :: input*() - setDefault
// *
// * @author Phalcon Team <team@phalconphp.com>
// * @since 2014-09-05
// */
// public function tagFieldWithSetDefault(UnitTester $I)
// {
// $I->wantToTest(sprintf('Tag - %s() - setDefault()', $this->function));
// $tag = new Tag();
// $tag->setDI($this->container);
//
// $options = [
// 'name' => 'x_name',
// 'class' => 'x_class',
// 'size' => '10',
// ];
// $expected = '<input type="' . $this->inputType . '" id="x_name" '
// . 'name="x_name" value="x_value" class="x_class" size="10"';
//
// $this->testFieldParameter($I, $tag, $this->function, $options, $expected, false, 'setDefault');
// $this->testFieldParameter($I, $tag, $this->function, $options, $expected, true, 'setDefault');
// }
//
// /**
// * Tests Phalcon\Tag :: input*() - setDefault and element not present
// *
// * @author Phalcon Team <team@phalconphp.com>
// * @since 2014-09-05
// */
// public function tagFieldWithSetDefaultElementNotPresent(UnitTester $I)
// {
// $I->wantToTest(sprintf('Tag - %s() - setDefault() element not present', $this->function));
// $tag = new Tag();
// $tag->setDI($this->container);
//
// $options = [
// 'name' => 'x_name',
// 'class' => 'x_class',
// 'size' => '10',
// ];
// $expected = '<input type="' . $this->inputType . '" id="x_name" '
// . 'name="x_name" value="x_value" class="x_class" '
// . 'size="10"';
//
// $this->testFieldParameter($I, $tag, $this->function, $options, $expected, false, 'setDefault');
// $this->testFieldParameter($I, $tag, $this->function, $options, $expected, true, 'setDefault');
// }

/**
* Tests Phalcon\Tag :: input*() - parameters and id in it
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2014-09-05
*/
public function tagFieldParameterWithId(UnitTester $I)
{
$I->wantToTest(sprintf('Tag - %s() - parameters with id', $this->function));
$tag = new Tag();
$tag->setDI($this->container);

$options = [
'name' => 'x_name',
'id' => 'x_id',
'class' => 'x_class',
'size' => '10',
];
$expected = '<input type="' . $this->inputType . '" id="x_id" name="x_name" '
. 'class="x_class" size="10"';

$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected);
$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected, true);
}

/**
* Tests Phalcon\Tag :: input*() - setAttribute
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2014-09-05
*/
public function tagFieldWithSetAttribute(UnitTester $I)
{
$I->wantToTest(sprintf('Tag - %s() - setAttribute()', $this->function));
$tag = new Tag();
$tag->setDI($this->container);

$options = [
'name' => 'x_name',
'class' => 'x_class',
'size' => '10',
];
$expected = '<input type="' . $this->inputType . '" id="x_name" '
. 'name="x_name" value="x_value" class="x_class" size="10"';

if ($this->inputType === 'radio' || $this->inputType === 'checkbox') {
$expected .= ' checked="checked"';
}

$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected, false, 'setAttribute');
$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected, true, 'setAttribute');
}

/**
* Tests Phalcon\Tag :: input*() - setAttribute and element not present
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2014-09-05
*/
public function tagFieldWithSetAttributeElementNotPresent(UnitTester $I)
{
$I->wantToTest(sprintf('Tag - %s() - setAttribute() element not present', $this->function));
$tag = new Tag();
$tag->setDI($this->container);

$options = [
'name' => 'x_name',
'class' => 'x_class',
'size' => '10',
];
$expected = '<input type="' . $this->inputType . '" id="x_name" '
. 'name="x_name" value="x_value" class="x_class" '
. 'size="10"';

if ($this->inputType === 'radio' || $this->inputType === 'checkbox') {
$expected .= ' checked="checked"';
}

$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected, false, 'setAttribute');
$this->testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected, true, 'setAttribute');
}

/**
* Runs the test for a Tag::$function with $options
*
* @param \UnitTester $I
* @param string $name
* @param string $function
* @param mixed $options
* @param string $expected
* @param boolean $xhtml
* @param string $set
* @param UnitTester $I
* @param Tag $tag
* @param string $name
* @param string $function
* @param $options
* @param string $expected
* @param bool $xhtml
* @param string $set
*
* @return mixed
*/
abstract protected function testFieldParameter(
UnitTester $I,
Expand Down
8 changes: 7 additions & 1 deletion tests/_data/fixtures/Traits/TagSetupTrait.php
Expand Up @@ -34,6 +34,7 @@ public function _before(UnitTester $I)
{
$this->newDi();
$this->setDiEscaper();
$this->setDiUrl();
}

/**
Expand All @@ -46,6 +47,11 @@ abstract protected function newDi();
*/
abstract protected function setDiEscaper();

/**
* @inheritdoc
*/
abstract protected function setDiUrl();

/**
* Runs the test for a Tag::$function with $options
*
Expand All @@ -68,7 +74,7 @@ protected function testFieldParameter(
bool $xhtml = false,
string $set = ''
) {
if ($xhtml) {
if ($xhtml && 'textArea' !== $function) {
$tag->setDocType(Tag::XHTML10_STRICT);
$expected .= ' />';
} else {
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/Html/Tag/ClearCest.php
Expand Up @@ -12,6 +12,7 @@

namespace Phalcon\Test\Unit\Html\Tag;

use Phalcon\Html\Tag;
use UnitTester;

/**
Expand All @@ -32,6 +33,15 @@ class ClearCest
public function htmlTagClear(UnitTester $I)
{
$I->wantToTest('Html\Tag - clear()');
$I->skipTest('Need implementation');
$tag = new Tag();

$tag->setAttribute('name', 'Phalcon');
$actual = $tag->hasValue('name');
$I->assertTrue($actual);

$tag->clear();

$actual = $tag->hasValue('name');
$I->assertFalse($actual);
}
}
51 changes: 50 additions & 1 deletion tests/unit/Html/Tag/GetValueCest.php
Expand Up @@ -12,6 +12,7 @@

namespace Phalcon\Test\Unit\Html\Tag;

use Phalcon\Html\Tag;
use UnitTester;

/**
Expand All @@ -32,6 +33,54 @@ class GetValueCest
public function htmlTagGetValue(UnitTester $I)
{
$I->wantToTest('Html\Tag - getValue()');
$I->skipTest('Need implementation');
$tag = new Tag();

$attributes = ['value' => 'Phalcon'];
$expected = 'Phalcon';
$actual = $tag->getValue('name', $attributes);
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Html\Tag :: getValue() - internal array
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function htmlTagGetValueInternal(UnitTester $I)
{
$I->wantToTest('Html\Tag - getValue() - internal array');
$tag = new Tag();

$tag->setAttribute('name', 'Phalcon');
$expected = 'Phalcon';
$actual = $tag->getValue('name');
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Html\Tag :: getValue() - POST
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function htmlTagGetValuePost(UnitTester $I)
{
$I->wantToTest('Html\Tag - getValue() - POST');
$tag = new Tag();

$oldPost = $_POST;
$_POST = [];
$_POST['name'] = 'Phalcon';

$expected = 'Phalcon';
$actual = $tag->getValue('name');
$I->assertEquals($expected, $actual);

$_POST = $oldPost;
}
}
31 changes: 30 additions & 1 deletion tests/unit/Html/Tag/HasValueCest.php
Expand Up @@ -12,6 +12,7 @@

namespace Phalcon\Test\Unit\Html\Tag;

use Phalcon\Html\Tag;
use UnitTester;

/**
Expand All @@ -32,6 +33,34 @@ class HasValueCest
public function htmlTagHasValue(UnitTester $I)
{
$I->wantToTest('Html\Tag - hasValue()');
$I->skipTest('Need implementation');
$tag = new Tag();

$tag->setAttribute('name', 'Phalcon');

$actual = $tag->hasValue('name');
$I->assertTrue($actual);
}

/**
* Tests Phalcon\Html\Tag :: hasValue() - POST
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function htmlTagHasValuePost(UnitTester $I)
{
$I->wantToTest('Html\Tag - hasValue() - POST');
$tag = new Tag();

$oldPost = $_POST;
$_POST = [];
$_POST['name'] = 'Phalcon';

$actual = $tag->hasValue('name');
$I->assertTrue($actual);

$_POST = $oldPost;
}
}
23 changes: 9 additions & 14 deletions tests/unit/Html/Tag/InputCheckboxCest.php
Expand Up @@ -12,7 +12,9 @@

namespace Phalcon\Test\Unit\Html\Tag;

use UnitTester;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Fixtures\Traits\TagHelperTrait;
use Phalcon\Test\Fixtures\Traits\TagSetupTrait;

/**
* Class InputCheckboxCest
Expand All @@ -21,17 +23,10 @@
*/
class InputCheckboxCest
{
/**
* Tests Phalcon\Html\Tag :: inputCheckbox()
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function htmlTagInputCheckbox(UnitTester $I)
{
$I->wantToTest('Html\Tag - inputCheckbox()');
$I->skipTest('Need implementation');
}
use DiTrait;
use TagSetupTrait;
use TagHelperTrait;

protected $function = 'inputCheckbox';
protected $inputType = 'checkbox';
}

0 comments on commit c3041d3

Please sign in to comment.