Skip to content

Commit

Permalink
Add more methods to the AdminInterface, Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Nov 14, 2011
1 parent c7ec444 commit f1fb569
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 2 deletions.
151 changes: 150 additions & 1 deletion Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
use Sonata\AdminBundle\Builder\FormContractorInterface;
use Sonata\AdminBundle\Builder\ListBuilderInterface;
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
use Sonata\AdminBundle\Builder\RouteBuilderInterface;
use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;

use Knp\Menu\FactoryInterface as MenuFactoryInterface;

use Symfony\Component\Validator\ValidatorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Request;

interface AdminInterface
{

/**
* @abstract
* @param \Sonata\AdminBundle\Builder\FormContractorInterface $formContractor
Expand Down Expand Up @@ -199,4 +204,148 @@ function addFilterFieldDescription($name, FieldDescriptionInterface $fieldDescri
* @return \Sonata\AdminBundle\Admin\FieldDescriptionCollection
*/
function getList();

/**
* @param \Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface $securityHandler
* @return void
*/
function setSecurityHandler(SecurityHandlerInterface $securityHandler);

/**
* @return \Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface|null
*/
function getSecurityHandler();

/**
* @param string $name
* @param object|null $object
* @return boolean
*/
function isGranted($name, $object = null);

/**
* @abstract
* @param $entity
*/
function getNormalizedIdentifier($entity);

/**
* Shorthand method for templating
*
* @param object $entity
* @return mixed
*/
function id($entity);

/**
* @param \Symfony\Component\Validator\ValidatorInterface $validator
* @return void
*/
function setValidator(ValidatorInterface $validator);

/**
* @return \Symfony\Component\Validator\ValidatorInterface
*/
function getValidator();

/**
* @return array
*/
function getShow();

/**
* @param array $formTheme
* @return void
*/
function setFormTheme(array $formTheme);

/**
* @return array
*/
function getFormTheme();

/**
* @param array $filterTheme
* @return void
*/
function setFilterTheme(array $filterTheme);

/**
* @return array
*/
function getFilterTheme();

/**
* @param AdminExtensionInterface $extension
* @return void
*/
function addExtension(AdminExtensionInterface $extension);

/**
* @param \Knp\Menu\FactoryInterface $menuFactory
* @return void
*/
function setMenuFactory(MenuFactoryInterface $menuFactory);

/**
* @return \Knp\Menu\FactoryInterface
*/
function getMenuFactory();

/**
* @param \Sonata\AdminBundle\Builder\RouteBuilderInterface $routeBuilder
*/
function setRouteBuilder(RouteBuilderInterface $routeBuilder);

/**
* @return \Sonata\AdminBundle\Builder\RouteBuilderInterface
*/
function getRouteBuilder();

/**
* @param $object
* @return string
*/
function toString($object);

/**
* @param \Sonata\Adminbundle\Translator\LabelTranslatorStrategyInterface $labelTranslatorStrategy
*/
function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy);

/**
* @return \Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface
*/
function getLabelTranslatorStrategy();

/**
* add an Admin child to the current one
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $child
* @return void
*/
function addChild(AdminInterface $child);

/**
* Returns true or false if an Admin child exists for the given $code
*
* @param string $code Admin code
* @return bool True if child exist, false otherwise
*/
function hasChild($code);

/**
* Returns an collection of admin children
*
* @return array list of Admin children
*/
function getChildren();

/**
* Returns an admin child with the given $code
*
* @param string $code
* @return array|null
*/
function getChild($code);
}
2 changes: 1 addition & 1 deletion Tests/Admin/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testGetAdminByAdminCode()

public function testGetAdminByAdminCodeForChildClass()
{
$adminMock = $this->getMockBuilder('Sonata\AdminBundle\Admin\Admin')
$adminMock = $this->getMockBuilder('Sonata\AdminBundle\Admin\AdminInterface')
->disableOriginalConstructor()
->getMock();
$adminMock->expects($this->any())
Expand Down
24 changes: 24 additions & 0 deletions Tests/Translator/FormLabelTranslatorStrategyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Tests\Translator;

use Sonata\AdminBundle\Translator\FormLabelTranslatorStrategy;

class FormLabelTranslatorStrategyTest extends \PHPUnit_Framework_TestCase
{
public function testLabel()
{
$strategy = new FormLabelTranslatorStrategy;

$this->assertEquals('Isvalid', $strategy->getLabel('isValid'));
$this->assertEquals('Plainpassword', $strategy->getLabel('plainPassword'));
}
}
24 changes: 24 additions & 0 deletions Translator/FormLabelTranslatorStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of sonata-project.
*
* (c) 2010 Thomas Rabaix
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Translator;

class FormLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
{
/**
* @param string $label
* @return string
*/
public function getLabel($label)
{
return ucfirst(strtolower($label));
}
}

0 comments on commit f1fb569

Please sign in to comment.