Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Jul 19, 2015
1 parent cd2b770 commit a0edb9c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/EasyAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private function processEntityTemplates(array $backendConfiguration)
// template name should not contain the .html.twig extension
// however, for usability reasons, we silently fix this issue if needed
if ('.html.twig' === substr($templateName, -10)) {
$templateName = substr($templateName, 0, 10);
$templateName = substr($templateName, 0, -10);
}

// 1st level priority: app/Resources/views/easy_admin/<entityName>/<templateName>.html.twig
Expand Down
20 changes: 20 additions & 0 deletions Tests/Controller/CustomFieldTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function testListViewCustomFieldTemplate()

$this->assertContains('Custom template for "name" field in the "list" view.', $crawler->filter('#main table td[data-label="Name"]')->eq(0)->text());
$this->assertContains('The value of the custom option is "custom_list_value".', $crawler->filter('#main table td[data-label="Name"]')->eq(0)->text());

$parsedConfiguration = $this->client->getKernel()->getContainer()->getParameter('easyadmin.config');
$this->assertEquals('easy_admin/custom_field_template.html.twig', $parsedConfiguration['entities']['Category']['list']['fields']['name']['template']);
}

public function testShowViewCustomFieldTemplate()
Expand All @@ -39,6 +42,23 @@ public function testShowViewCustomFieldTemplate()
$this->assertContains('The value of the custom option is "custom_show_value".', $crawler->filter('#main .form-control')->eq(0)->text());
}

public function testListViewCustomFieldTemplateWrongName()
{
$crawler = $this->requestListView();

$this->assertContains('Custom template for "id" field in the "list" view.', $crawler->filter('#main table td[data-label="ID"]')->eq(0)->text());

$parsedConfiguration = $this->client->getKernel()->getContainer()->getParameter('easyadmin.config');
$this->assertEquals('easy_admin/custom_field_template.html.twig', $parsedConfiguration['entities']['Category']['list']['fields']['id']['template']);
}

public function testShowViewCustomFieldTemplateWrongName()
{
$crawler = $this->requestShowView();

$this->assertContains('Custom template for "id" field in the "show" view.', $crawler->filter('#main .form-control')->eq(1)->text());
}

/**
* @return Crawler
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Custom template for "{{ field_options.property }}" field in the "{{ view }}" view.

The value of the custom option is "{{ field_options.custom_option }}".
The value of the custom option is "{{ field_options.custom_option|default('null') }}".
7 changes: 7 additions & 0 deletions Tests/Fixtures/App/config/config_custom_field_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ easy_admin:
list:
fields:
- { property: 'name', template: 'custom_field_template', custom_option: 'custom_list_value' }
# Template name should NOT contain the .html.twig suffix. However, the
# application should silently fix this error and work as expected
- { property: 'id', template: 'custom_field_template.html.twig' }

show:
fields:
- { property: 'name', template: 'custom_field_template', custom_option: 'custom_show_value' }
# Template name should NOT contain the .html.twig suffix. However, the
# application should silently fix this error and work as expected
- { property: 'id', template: 'custom_field_template.html.twig' }

0 comments on commit a0edb9c

Please sign in to comment.