Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/SimpleChoiceListTest.php
Строк: 77
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentFormTestsExtensionCoreChoiceList;

use 
SymfonyComponentFormExtensionCoreChoiceListSimpleChoiceList;
use 
SymfonyComponentFormExtensionCoreViewChoiceView;

class 
SimpleChoiceListTest extends AbstractChoiceListTest
{
    public function 
testInitArray()
    {
        
$choices = array('a' => 'A''b' => 'B''c' => 'C');
        
$this->list = new SimpleChoiceList($choices, array('b'));

        
$this->assertSame(array(=> 'a'=> 'b'=> 'c'), $this->list->getChoices());
        
$this->assertSame(array(=> 'a'=> 'b'=> 'c'), $this->list->getValues());
        
$this->assertEquals(array(=> new ChoiceView('b''b''B')), $this->list->getPreferredViews());
        
$this->assertEquals(array(=> new ChoiceView('a''a''A'), => new ChoiceView('c''c''C')), $this->list->getRemainingViews());
    }

    public function 
testInitNestedArray()
    {
        
$this->assertSame(array(=> 'a'=> 'b'=> 'c'=> 'd'), $this->list->getChoices());
        
$this->assertSame(array(=> 'a'=> 'b'=> 'c'=> 'd'), $this->list->getValues());
        
$this->assertEquals(array(
            
'Group 1' => array(=> new ChoiceView('b''b''B')),
            
'Group 2' => array(=> new ChoiceView('c''c''C')),
        ), 
$this->list->getPreferredViews());
        
$this->assertEquals(array(
            
'Group 1' => array(=> new ChoiceView('a''a''A')),
            
'Group 2' => array(=> new ChoiceView('d''d''D')),
        ), 
$this->list->getRemainingViews());
    }

    
/**
     * @dataProvider dirtyValuesProvider
     */
    
public function testGetValuesForChoicesDealsWithDirtyValues($choice$value)
    {
        
$choices = array(
            
'0' => 'Zero',
            
'1' => 'One',
            
'' => 'Empty',
            
'1.23' => 'Float',
            
'foo' => 'Foo',
            
'foo10' => 'Foo 10',
        );

        
$this->list = new SimpleChoiceList($choices, array());

        
$this->assertSame(array($value), $this->list->getValuesForChoices(array($choice)));
    }

    public function 
dirtyValuesProvider()
    {
        return array(
            array(
0'0'),
            array(
'0''0'),
            array(
'1''1'),
            array(
false'0'),
            array(
true'1'),
            array(
''''),
            array(
null''),
            array(
'1.23''1.23'),
            array(
'foo''foo'),
            array(
'foo10''foo10'),
        );
    }

    
/**
     * @return SymfonyComponentFormExtensionCoreChoiceListChoiceListInterface
     */
    
protected function createChoiceList()
    {
        return new 
SimpleChoiceList(array(
            
'Group 1' => array('a' => 'A''b' => 'B'),
            
'Group 2' => array('c' => 'C''d' => 'D'),
        ), array(
'b''c'));
    }

    protected function 
getChoices()
    {
        return array(
=> 'a'=> 'b'=> 'c'=> 'd');
    }

    protected function 
getLabels()
    {
        return array(
=> 'A'=> 'B'=> 'C'=> 'D');
    }

    protected function 
getValues()
    {
        return array(
=> 'a'=> 'b'=> 'c'=> 'd');
    }

    protected function 
getIndices()
    {
        return array(
0123);
    }
}
Онлайн: 2
Реклама