Skip to content

Commit

Permalink
Rename Table button Twig extension functions
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Aug 2, 2018
1 parent 1c23050 commit 4d6e8b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
30 changes: 15 additions & 15 deletions Tests/Twig/Extension/Utility/TableButtonTwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ public function testGetFunctions() {
$this->assertCount(3, $res);

$this->assertInstanceOf(Twig_SimpleFunction::class, $res[0]);
$this->assertEquals("bootstrapDefaultRowButtons", $res[0]->getName());
$this->assertEquals([$obj, "bootstrapDefaultRowButtonsFunction"], $res[0]->getCallable());
$this->assertEquals("bootstrapRowButtonDefault", $res[0]->getName());
$this->assertEquals([$obj, "bootstrapRowButtonDefaultFunction"], $res[0]->getCallable());
$this->assertEquals(["html"], $res[0]->getSafe(new Twig_Node()));

$this->assertInstanceOf(Twig_SimpleFunction::class, $res[1]);
$this->assertEquals("bootstrapDeleteRowButton", $res[1]->getName());
$this->assertEquals([$obj, "bootstrapDeleteRowButtonFunction"], $res[1]->getCallable());
$this->assertEquals("bootstrapRowButtonDelete", $res[1]->getName());
$this->assertEquals([$obj, "bootstrapRowButtonDeleteFunction"], $res[1]->getCallable());
$this->assertEquals(["html"], $res[1]->getSafe(new Twig_Node()));

$this->assertInstanceOf(Twig_SimpleFunction::class, $res[2]);
$this->assertEquals("bootstrapEditRowButton", $res[2]->getName());
$this->assertEquals([$obj, "bootstrapEditRowButtonFunction"], $res[2]->getCallable());
$this->assertEquals("bootstrapRowButtonEdit", $res[2]->getName());
$this->assertEquals([$obj, "bootstrapRowButtonEditFunction"], $res[2]->getCallable());
$this->assertEquals(["html"], $res[2]->getSafe(new Twig_Node()));
}

/**
* Tests the bootstrapDefaultRowButtonsFunction() method.
* Tests the bootstrapRowButtonDefaultFunction() method.
*
* @return void
* @depends testGetFunctions
*/
public function testBootstrapDefaultRowButtonsFunction() {
public function testBootstrapRowButtonDefaultFunction() {

$obj = new TableButtonTwigExtension($this->translator, new ButtonTwigExtension());

Expand All @@ -82,38 +82,38 @@ public function testBootstrapDefaultRowButtonsFunction() {

$arg = ["edit_href" => "https://github.com/", "delete_href" => "https://github.com/"];
$res = $edt . " " . $dlt;
$this->assertEquals($res, $obj->bootstrapDefaultRowButtonsFunction($arg));
$this->assertEquals($res, $obj->bootstrapRowButtonDefaultFunction($arg));
}

/**
* Tests the bootstrapDeleteRowButtonFunction() method.
* Tests the bootstrapRowButtonDeleteFunction() method.
*
* @return void
* @depends testGetFunctions
*/
public function testBootstrapDeleteRowButtonFunction() {
public function testBootstrapRowButtonDeleteFunction() {

$obj = new TableButtonTwigExtension($this->translator, new ButtonTwigExtension());

$arg = ["href" => "https://github.com/"];
$res = '<a class="btn btn-danger" title="label.delete" href="https://github.com/" data-toggle="tooltip" data-placement="top"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>';
$this->assertEquals($res, $obj->bootstrapDeleteRowButtonFunction($arg));
$this->assertEquals($res, $obj->bootstrapRowButtonDeleteFunction($arg));
}

/**
* Tests the bootstrapEditRowButtonFunction() method.
* Tests the bootstrapRowButtonEditFunction() method.
*
* @return void
* @depends testGetFunctions
*/
public function testBootstrapEditRowButtonFunction() {
public function testBootstrapRowButtonEditFunction() {


$obj = new TableButtonTwigExtension($this->translator, new ButtonTwigExtension());

$arg = ["href" => "https://github.com/"];
$res = '<a class="btn btn-default" title="label.edit" href="https://github.com/" data-toggle="tooltip" data-placement="top"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>';
$this->assertEquals($res, $obj->bootstrapEditRowButtonFunction($arg));
$this->assertEquals($res, $obj->bootstrapRowButtonEditFunction($arg));
}

}
28 changes: 14 additions & 14 deletions Twig/Extension/Utility/TableButtonTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ public function __construct(TranslatorInterface $translator, ButtonTwigExtension
}

/**
* Displays a Bootstrap default row buttons.
* Displays a Bootstrap row button "Default".
*
* @param array $args The arguments.
* @return string Returns the Bootstrap default form buttons.
* @return string Returns the Bootstrap form button "Default".
*/
public function bootstrapDefaultRowButtonsFunction(array $args = []) {
public function bootstrapRowButtonDefaultFunction(array $args = []) {

// Initialize the buttons.
$editButton = $this->bootstrapEditRowButtonFunction(["href" => ArrayUtility::get($args, "edit_href")]);
$deleteButton = $this->bootstrapDeleteRowButtonFunction(["href" => ArrayUtility::get($args, "delete_href")]);
$editButton = $this->bootstrapRowButtonEditFunction(["href" => ArrayUtility::get($args, "edit_href")]);
$deleteButton = $this->bootstrapRowButtonDeleteFunction(["href" => ArrayUtility::get($args, "delete_href")]);

// Return the HTML.
return implode(" ", [$editButton, $deleteButton]);
}

/**
* Displays a Bootstrap delete row button.
* Displays a Bootstrap row button "Delete".
*
* @param array $args The arguments.
* @return string Returns the Bootstrap delete row button.
* @return string Returns the Bootstrap row button "Delete".
*/
public function bootstrapDeleteRowButtonFunction(array $args = []) {
public function bootstrapRowButtonDeleteFunction(array $args = []) {

// Translate the label.
$txt = $this->getTranslator()->trans("label.delete", [], "BootstrapBundle");
Expand All @@ -84,12 +84,12 @@ public function bootstrapDeleteRowButtonFunction(array $args = []) {
}

/**
* Displays a Bootstrap edit row button.
* Displays a Bootstrap row button "Edit".
*
* @param array $args The arguments.
* @return string Returns the Bootstrap edit row button.
* @return string Returns the Bootstrap row button "Edit".
*/
public function bootstrapEditRowButtonFunction(array $args = []) {
public function bootstrapRowButtonEditFunction(array $args = []) {

// Translate the label.
$txt = $this->getTranslator()->trans("label.edit", [], "BootstrapBundle");
Expand Down Expand Up @@ -117,9 +117,9 @@ public function getExtension() {
*/
public function getFunctions() {
return [
new Twig_SimpleFunction("bootstrapDefaultRowButtons", [$this, "bootstrapDefaultRowButtonsFunction"], ["is_safe" => ["html"]]),
new Twig_SimpleFunction("bootstrapDeleteRowButton", [$this, "bootstrapDeleteRowButtonFunction"], ["is_safe" => ["html"]]),
new Twig_SimpleFunction("bootstrapEditRowButton", [$this, "bootstrapEditRowButtonFunction"], ["is_safe" => ["html"]]),
new Twig_SimpleFunction("bootstrapRowButtonDefault", [$this, "bootstrapRowButtonDefaultFunction"], ["is_safe" => ["html"]]),
new Twig_SimpleFunction("bootstrapRowButtonDelete", [$this, "bootstrapRowButtonDeleteFunction"], ["is_safe" => ["html"]]),
new Twig_SimpleFunction("bootstrapRowButtonEdit", [$this, "bootstrapRowButtonEditFunction"], ["is_safe" => ["html"]]),
];
}

Expand Down

0 comments on commit 4d6e8b0

Please sign in to comment.