diff --git a/tests/_data/fixtures/Traits/BeanstalkTrait.php b/tests/_data/fixtures/Traits/BeanstalkTrait.php index d355e3c4783..f18ad5e71a9 100644 --- a/tests/_data/fixtures/Traits/BeanstalkTrait.php +++ b/tests/_data/fixtures/Traits/BeanstalkTrait.php @@ -1,4 +1,5 @@ + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +namespace Phalcon\Test\Fixtures\Traits; + +use Phalcon\Html\Tag; +use UnitTester; + +/** + * Trait TagSetupTrait + * + * @package Phalcon\Test\Fixtures\Traits + */ +trait TagHelperTrait +{ + /** + * Tests Phalcon\Tag :: input*() + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagField(UnitTester $I) + { + $I->wantToTest(sprintf('Tag - %s() - parameters', $this->function)); + $tag = new Tag(); + $tag->setDI($this->container); + + $options = [ + 'class' => 'x_class', + ]; + $expected = '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 +// * @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 = 'testFieldParameter($I, $tag, $this->function, $options, $expected); +// $this->testFieldParameter($I, $tag, $this->function, $options, $expected, true); +// } +// +// /** +// * Tests Phalcon\Tag :: input*() - setDefault +// * +// * @author Phalcon Team +// * @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 = '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 +// * @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 = 'testFieldParameter($I, $tag, $this->function, $options, $expected, false, 'setDefault'); +// $this->testFieldParameter($I, $tag, $this->function, $options, $expected, true, 'setDefault'); +// } + + /** + * 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 + */ + abstract protected function testFieldParameter( + UnitTester $I, + Tag $tag, + string $name, + string $function, + $options, + string $expected, + bool $xhtml = false, + string $set = '' + ); +} diff --git a/tests/_data/fixtures/Traits/TagSetupTrait.php b/tests/_data/fixtures/Traits/TagSetupTrait.php new file mode 100644 index 00000000000..50115168879 --- /dev/null +++ b/tests/_data/fixtures/Traits/TagSetupTrait.php @@ -0,0 +1,86 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +namespace Phalcon\Test\Fixtures\Traits; + +use Phalcon\Html\Tag; +use UnitTester; + +/** + * Trait TagSetupTrait + * + * @package Phalcon\Test\Fixtures\Traits + */ +trait TagSetupTrait +{ + /** + * Constructor + * + * @param UnitTester $I + * + * @author Phalcon Team + * @since 2018-10-26 + */ + public function _before(UnitTester $I) + { + $this->newDi(); + $this->setDiEscaper(); + } + + /** + * @inheritdoc + */ + abstract protected function newDi(); + + /** + * @inheritdoc + */ + abstract protected function setDiEscaper(); + + /** + * Runs the test for a Tag::$function with $options + * + * @param UnitTester $I + * @param Tag $tag + * @param string $name + * @param string $function + * @param $options + * @param string $expected + * @param bool $xhtml + * @param string $set + */ + protected function testFieldParameter( + UnitTester $I, + Tag $tag, + string $name, + string $function, + $options, + string $expected, + bool $xhtml = false, + string $set = '' + ) { + if ($xhtml) { + $tag->setDocType(Tag::XHTML10_STRICT); + $expected .= ' />'; + } else { + $tag->setDocType(Tag::HTML5); + $expected .= '>'; + } + + if ($set) { + $tag->{$set}('x_name', 'x_value'); + } + + $actual = $tag->$function($name, $options); + $I->assertEquals($expected, $actual); + } +} diff --git a/tests/_data/fixtures/Traits/TranslateTrait.php b/tests/_data/fixtures/Traits/TranslateTrait.php index 6cdc34dbd08..9043d1e3cb1 100644 --- a/tests/_data/fixtures/Traits/TranslateTrait.php +++ b/tests/_data/fixtures/Traits/TranslateTrait.php @@ -1,4 +1,5 @@