FieldGroupTest.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. namespace Symfony\Tests\Component\Form;
  3. require_once __DIR__ . '/Fixtures/Author.php';
  4. require_once __DIR__ . '/Fixtures/TestField.php';
  5. require_once __DIR__ . '/Fixtures/TestFieldGroup.php';
  6. use Symfony\Component\Form\Field;
  7. use Symfony\Component\Form\FieldInterface;
  8. use Symfony\Component\Form\FieldGroup;
  9. use Symfony\Component\Form\PropertyPath;
  10. use Symfony\Tests\Component\Form\Fixtures\Author;
  11. use Symfony\Tests\Component\Form\Fixtures\TestField;
  12. use Symfony\Tests\Component\Form\Fixtures\TestFieldGroup;
  13. abstract class FieldGroupTest_Field extends TestField
  14. {
  15. public $locales = array();
  16. public function setLocale($locale)
  17. {
  18. $this->locales[] = $locale;
  19. }
  20. }
  21. class FieldGroupTest extends \PHPUnit_Framework_TestCase
  22. {
  23. public function testSupportsArrayAccess()
  24. {
  25. $group = new TestFieldGroup('author');
  26. $group->add($this->createMockField('firstName'));
  27. $this->assertEquals($group->get('firstName'), $group['firstName']);
  28. $this->assertTrue(isset($group['firstName']));
  29. }
  30. public function testSupportsUnset()
  31. {
  32. $group = new TestFieldGroup('author');
  33. $group->add($this->createMockField('firstName'));
  34. unset($group['firstName']);
  35. $this->assertFalse(isset($group['firstName']));
  36. }
  37. public function testDoesNotSupportAddingFields()
  38. {
  39. $group = new TestFieldGroup('author');
  40. $this->setExpectedException('LogicException');
  41. $group[] = $this->createMockField('lastName');
  42. }
  43. public function testSupportsCountable()
  44. {
  45. $group = new TestFieldGroup('group');
  46. $group->add($this->createMockField('firstName'));
  47. $group->add($this->createMockField('lastName'));
  48. $this->assertEquals(2, count($group));
  49. $group->add($this->createMockField('australian'));
  50. $this->assertEquals(3, count($group));
  51. }
  52. public function testSupportsIterable()
  53. {
  54. $group = new TestFieldGroup('group');
  55. $group->add($field1 = $this->createMockField('field1'));
  56. $group->add($field2 = $this->createMockField('field2'));
  57. $group->add($field3 = $this->createMockField('field3'));
  58. $expected = array(
  59. 'field1' => $field1,
  60. 'field2' => $field2,
  61. 'field3' => $field3,
  62. );
  63. $this->assertEquals($expected, iterator_to_array($group));
  64. }
  65. public function testIsBound()
  66. {
  67. $group = new TestFieldGroup('author');
  68. $this->assertFalse($group->isBound());
  69. $group->bind(array('firstName' => 'Bernhard'));
  70. $this->assertTrue($group->isBound());
  71. }
  72. public function testValidIfAllFieldsAreValid()
  73. {
  74. $group = new TestFieldGroup('author');
  75. $group->add($this->createValidMockField('firstName'));
  76. $group->add($this->createValidMockField('lastName'));
  77. $group->bind(array('firstName' => 'Bernhard', 'lastName' => 'Potencier'));
  78. $this->assertTrue($group->isValid());
  79. }
  80. public function testInvalidIfFieldIsInvalid()
  81. {
  82. $group = new TestFieldGroup('author');
  83. $group->add($this->createInvalidMockField('firstName'));
  84. $group->add($this->createValidMockField('lastName'));
  85. $group->bind(array('firstName' => 'Bernhard', 'lastName' => 'Potencier'));
  86. $this->assertFalse($group->isValid());
  87. }
  88. public function testInvalidIfBoundWithExtraFields()
  89. {
  90. $group = new TestFieldGroup('author');
  91. $group->add($this->createValidMockField('firstName'));
  92. $group->add($this->createValidMockField('lastName'));
  93. $group->bind(array('foo' => 'bar', 'firstName' => 'Bernhard', 'lastName' => 'Potencier'));
  94. $this->assertTrue($group->isBoundWithExtraFields());
  95. }
  96. public function testBindForwardsBoundValues()
  97. {
  98. $field = $this->createMockField('firstName');
  99. $field->expects($this->once())
  100. ->method('bind')
  101. ->with($this->equalTo('Bernhard'));
  102. $group = new TestFieldGroup('author');
  103. $group->add($field);
  104. $group->bind(array('firstName' => 'Bernhard'));
  105. }
  106. public function testBindForwardsNullIfValueIsMissing()
  107. {
  108. $field = $this->createMockField('firstName');
  109. $field->expects($this->once())
  110. ->method('bind')
  111. ->with($this->equalTo(null));
  112. $group = new TestFieldGroup('author');
  113. $group->add($field);
  114. $group->bind(array());
  115. }
  116. public function testAddErrorMapsFieldValidationErrorsOntoFields()
  117. {
  118. $field = $this->createMockField('firstName');
  119. $field->expects($this->once())
  120. ->method('addError')
  121. ->with($this->equalTo('Message'));
  122. $group = new TestFieldGroup('author');
  123. $group->add($field);
  124. $path = new PropertyPath('fields[firstName].data');
  125. $group->addError('Message', array(), $path->getIterator(), FieldGroup::FIELD_ERROR);
  126. }
  127. public function testAddErrorMapsFieldValidationErrorsOntoFieldsWithinNestedFieldGroups()
  128. {
  129. $field = $this->createMockField('firstName');
  130. $field->expects($this->once())
  131. ->method('addError')
  132. ->with($this->equalTo('Message'));
  133. $group = new TestFieldGroup('author');
  134. $innerGroup = new TestFieldGroup('names');
  135. $innerGroup->add($field);
  136. $group->add($innerGroup);
  137. $path = new PropertyPath('fields[names].fields[firstName].data');
  138. $group->addError('Message', array(), $path->getIterator(), FieldGroup::FIELD_ERROR);
  139. }
  140. public function testAddErrorKeepsFieldValidationErrorsIfFieldNotFound()
  141. {
  142. $field = $this->createMockField('foo');
  143. $field->expects($this->never())
  144. ->method('addError');
  145. $group = new TestFieldGroup('author');
  146. $group->add($field);
  147. $path = new PropertyPath('fields[bar].data');
  148. $group->addError('Message', array(), $path->getIterator(), FieldGroup::FIELD_ERROR);
  149. $this->assertEquals(array(array('Message', array())), $group->getErrors());
  150. }
  151. public function testAddErrorKeepsFieldValidationErrorsIfFieldIsHidden()
  152. {
  153. $field = $this->createMockField('firstName');
  154. $field->expects($this->any())
  155. ->method('isHidden')
  156. ->will($this->returnValue(true));
  157. $field->expects($this->never())
  158. ->method('addError');
  159. $group = new TestFieldGroup('author');
  160. $group->add($field);
  161. $path = new PropertyPath('fields[firstName].data');
  162. $group->addError('Message', array(), $path->getIterator(), FieldGroup::FIELD_ERROR);
  163. $this->assertEquals(array(array('Message', array())), $group->getErrors());
  164. }
  165. public function testAddErrorMapsDataValidationErrorsOntoFields()
  166. {
  167. // path is expected to point at "firstName"
  168. $expectedPath = new PropertyPath('firstName');
  169. $expectedPathIterator = $expectedPath->getIterator();
  170. $field = $this->createMockField('firstName');
  171. $field->expects($this->any())
  172. ->method('getPropertyPath')
  173. ->will($this->returnValue(new PropertyPath('firstName')));
  174. $field->expects($this->once())
  175. ->method('addError')
  176. ->with($this->equalTo('Message'), array(), $this->equalTo($expectedPathIterator), $this->equalTo(FieldGroup::DATA_ERROR));
  177. $group = new TestFieldGroup('author');
  178. $group->add($field);
  179. $path = new PropertyPath('firstName');
  180. $group->addError('Message', array(), $path->getIterator(), FieldGroup::DATA_ERROR);
  181. }
  182. public function testAddErrorKeepsDataValidationErrorsIfFieldNotFound()
  183. {
  184. $field = $this->createMockField('foo');
  185. $field->expects($this->any())
  186. ->method('getPropertyPath')
  187. ->will($this->returnValue(new PropertyPath('foo')));
  188. $field->expects($this->never())
  189. ->method('addError');
  190. $group = new TestFieldGroup('author');
  191. $group->add($field);
  192. $path = new PropertyPath('bar');
  193. $group->addError('Message', array(), $path->getIterator(), FieldGroup::DATA_ERROR);
  194. }
  195. public function testAddErrorKeepsDataValidationErrorsIfFieldIsHidden()
  196. {
  197. $field = $this->createMockField('firstName');
  198. $field->expects($this->any())
  199. ->method('isHidden')
  200. ->will($this->returnValue(true));
  201. $field->expects($this->any())
  202. ->method('getPropertyPath')
  203. ->will($this->returnValue(new PropertyPath('firstName')));
  204. $field->expects($this->never())
  205. ->method('addError');
  206. $group = new TestFieldGroup('author');
  207. $group->add($field);
  208. $path = new PropertyPath('firstName');
  209. $group->addError('Message', array(), $path->getIterator(), FieldGroup::DATA_ERROR);
  210. }
  211. public function testAddErrorMapsDataValidationErrorsOntoNestedFields()
  212. {
  213. // path is expected to point at "street"
  214. $expectedPath = new PropertyPath('address.street');
  215. $expectedPathIterator = $expectedPath->getIterator();
  216. $expectedPathIterator->next();
  217. $field = $this->createMockField('address');
  218. $field->expects($this->any())
  219. ->method('getPropertyPath')
  220. ->will($this->returnValue(new PropertyPath('address')));
  221. $field->expects($this->once())
  222. ->method('addError')
  223. ->with($this->equalTo('Message'), array(), $this->equalTo($expectedPathIterator), $this->equalTo(FieldGroup::DATA_ERROR));
  224. $group = new TestFieldGroup('author');
  225. $group->add($field);
  226. $path = new PropertyPath('address.street');
  227. $group->addError('Message', array(), $path->getIterator(), FieldGroup::DATA_ERROR);
  228. }
  229. public function testAddErrorMapsErrorsOntoFieldsInAnonymousGroups()
  230. {
  231. // path is expected to point at "address"
  232. $expectedPath = new PropertyPath('address');
  233. $expectedPathIterator = $expectedPath->getIterator();
  234. $field = $this->createMockField('address');
  235. $field->expects($this->any())
  236. ->method('getPropertyPath')
  237. ->will($this->returnValue(new PropertyPath('address')));
  238. $field->expects($this->once())
  239. ->method('addError')
  240. ->with($this->equalTo('Message'), array(), $this->equalTo($expectedPathIterator), $this->equalTo(FieldGroup::DATA_ERROR));
  241. $group = new TestFieldGroup('author');
  242. $group2 = new TestFieldGroup('anonymous', array('property_path' => null));
  243. $group2->add($field);
  244. $group->add($group2);
  245. $path = new PropertyPath('address');
  246. $group->addError('Message', array(), $path->getIterator(), FieldGroup::DATA_ERROR);
  247. }
  248. public function testAddThrowsExceptionIfAlreadyBound()
  249. {
  250. $group = new TestFieldGroup('author');
  251. $group->add($this->createMockField('firstName'));
  252. $group->bind(array('firstName' => 'Bernhard'));
  253. $this->setExpectedException('Symfony\Component\Form\Exception\AlreadyBoundException');
  254. $group->add($this->createMockField('lastName'));
  255. }
  256. public function testAddSetsFieldParent()
  257. {
  258. $group = new TestFieldGroup('author');
  259. $field = $this->createMockField('firstName');
  260. $field->expects($this->once())
  261. ->method('setParent');
  262. // PHPUnit fails to compare infinitely recursive objects
  263. //->with($this->equalTo($group));
  264. $group->add($field);
  265. }
  266. public function testRemoveUnsetsFieldParent()
  267. {
  268. $group = new TestFieldGroup('author');
  269. $field = $this->createMockField('firstName');
  270. $field->expects($this->exactly(2))
  271. ->method('setParent');
  272. // PHPUnit fails to compare subsequent method calls with different arguments
  273. $group->add($field);
  274. $group->remove('firstName');
  275. }
  276. public function testMergeAddsFieldsFromAnotherGroup()
  277. {
  278. $group1 = new TestFieldGroup('author');
  279. $group1->add($field1 = new TestField('firstName'));
  280. $group2 = new TestFieldGroup('publisher');
  281. $group2->add($field2 = new TestField('lastName'));
  282. $group1->merge($group2);
  283. $this->assertTrue($group1->has('lastName'));
  284. $this->assertEquals(new PropertyPath('publisher.lastName'), $group1->get('lastName')->getPropertyPath());
  285. }
  286. public function testMergeThrowsExceptionIfOtherGroupAlreadyBound()
  287. {
  288. $group1 = new TestFieldGroup('author');
  289. $group2 = new TestFieldGroup('publisher');
  290. $group2->add($this->createMockField('firstName'));
  291. $group2->bind(array('firstName' => 'Bernhard'));
  292. $this->setExpectedException('Symfony\Component\Form\Exception\AlreadyBoundException');
  293. $group1->merge($group2);
  294. }
  295. public function testAddUpdatesFieldFromTransformedData()
  296. {
  297. $originalAuthor = new Author();
  298. $transformedAuthor = new Author();
  299. // the authors should differ to make sure the test works
  300. $transformedAuthor->firstName = 'Foo';
  301. $group = new TestFieldGroup('author');
  302. $transformer = $this->createMockTransformer();
  303. $transformer->expects($this->once())
  304. ->method('transform')
  305. ->with($this->equalTo($originalAuthor))
  306. ->will($this->returnValue($transformedAuthor));
  307. $group->setValueTransformer($transformer);
  308. $group->setData($originalAuthor);
  309. $field = $this->createMockField('firstName');
  310. $field->expects($this->any())
  311. ->method('getPropertyPath')
  312. ->will($this->returnValue(new PropertyPath('firstName')));
  313. $field->expects($this->once())
  314. ->method('updateFromObject')
  315. ->with($this->equalTo($transformedAuthor));
  316. $group->add($field);
  317. }
  318. public function testAddDoesNotUpdateFieldsWithEmptyPropertyPath()
  319. {
  320. $group = new TestFieldGroup('author');
  321. $group->setData(new Author());
  322. $field = $this->createMockField('firstName');
  323. $field->expects($this->any())
  324. ->method('getPropertyPath')
  325. ->will($this->returnValue(null));
  326. $field->expects($this->never())
  327. ->method('updateFromObject');
  328. $group->add($field);
  329. }
  330. public function testAddDoesNotUpdateFieldIfTransformedDataIsEmpty()
  331. {
  332. $originalAuthor = new Author();
  333. $group = new TestFieldGroup('author');
  334. $transformer = $this->createMockTransformer();
  335. $transformer->expects($this->once())
  336. ->method('transform')
  337. ->with($this->equalTo($originalAuthor))
  338. ->will($this->returnValue(''));
  339. $group->setValueTransformer($transformer);
  340. $group->setData($originalAuthor);
  341. $field = $this->createMockField('firstName');
  342. $field->expects($this->never())
  343. ->method('updateFromObject');
  344. $group->add($field);
  345. }
  346. public function testSetDataUpdatesAllFieldsFromTransformedData()
  347. {
  348. $originalAuthor = new Author();
  349. $transformedAuthor = new Author();
  350. // the authors should differ to make sure the test works
  351. $transformedAuthor->firstName = 'Foo';
  352. $group = new TestFieldGroup('author');
  353. $transformer = $this->createMockTransformer();
  354. $transformer->expects($this->once())
  355. ->method('transform')
  356. ->with($this->equalTo($originalAuthor))
  357. ->will($this->returnValue($transformedAuthor));
  358. $group->setValueTransformer($transformer);
  359. $field = $this->createMockField('firstName');
  360. $field->expects($this->once())
  361. ->method('updateFromObject')
  362. ->with($this->equalTo($transformedAuthor));
  363. $group->add($field);
  364. $field = $this->createMockField('lastName');
  365. $field->expects($this->once())
  366. ->method('updateFromObject')
  367. ->with($this->equalTo($transformedAuthor));
  368. $group->add($field);
  369. $group->setData($originalAuthor);
  370. }
  371. public function testSetDataThrowsAnExceptionIfArgumentIsNotObjectOrArray()
  372. {
  373. $group = new TestFieldGroup('author');
  374. $this->setExpectedException('InvalidArgumentException');
  375. $group->setData('foobar');
  376. }
  377. public function testBindUpdatesTransformedDataFromAllFields()
  378. {
  379. $originalAuthor = new Author();
  380. $transformedAuthor = new Author();
  381. // the authors should differ to make sure the test works
  382. $transformedAuthor->firstName = 'Foo';
  383. $group = new TestFieldGroup('author');
  384. $transformer = $this->createMockTransformer();
  385. $transformer->expects($this->exactly(2))
  386. ->method('transform')
  387. // the method is first called with NULL, then
  388. // with $originalAuthor -> not testable by PHPUnit
  389. // ->with($this->equalTo(null))
  390. // ->with($this->equalTo($originalAuthor))
  391. ->will($this->returnValue($transformedAuthor));
  392. $group->setValueTransformer($transformer);
  393. $group->setData($originalAuthor);
  394. $field = $this->createMockField('firstName');
  395. $field->expects($this->once())
  396. ->method('updateObject')
  397. ->with($this->equalTo($transformedAuthor));
  398. $group->add($field);
  399. $field = $this->createMockField('lastName');
  400. $field->expects($this->once())
  401. ->method('updateObject')
  402. ->with($this->equalTo($transformedAuthor));
  403. $group->add($field);
  404. $group->bind(array()); // irrelevant
  405. }
  406. public function testGetDataReturnsObject()
  407. {
  408. $group = new TestFieldGroup('author');
  409. $object = new \stdClass();
  410. $group->setData($object);
  411. $this->assertEquals($object, $group->getData());
  412. }
  413. public function testGetDisplayedDataForwardsCall()
  414. {
  415. $field = $this->createValidMockField('firstName');
  416. $field->expects($this->atLeastOnce())
  417. ->method('getDisplayedData')
  418. ->will($this->returnValue('Bernhard'));
  419. $group = new TestFieldGroup('author');
  420. $group->add($field);
  421. $this->assertEquals(array('firstName' => 'Bernhard'), $group->getDisplayedData());
  422. }
  423. public function testIsMultipartIfAnyFieldIsMultipart()
  424. {
  425. $group = new TestFieldGroup('author');
  426. $group->add($this->createMultipartMockField('firstName'));
  427. $group->add($this->createNonMultipartMockField('lastName'));
  428. $this->assertTrue($group->isMultipart());
  429. }
  430. public function testIsNotMultipartIfNoFieldIsMultipart()
  431. {
  432. $group = new TestFieldGroup('author');
  433. $group->add($this->createNonMultipartMockField('firstName'));
  434. $group->add($this->createNonMultipartMockField('lastName'));
  435. $this->assertFalse($group->isMultipart());
  436. }
  437. public function testLocaleIsPassedToField_SetBeforeAddingTheField()
  438. {
  439. $field = $this->getMock('Symfony\Component\Form\Field', array(), array(), '', false, false);
  440. $field->expects($this->any())
  441. ->method('getKey')
  442. ->will($this->returnValue('firstName'));
  443. $field->expects($this->once())
  444. ->method('setLocale')
  445. ->with($this->equalTo('de_DE'));
  446. $group = new TestFieldGroup('author');
  447. $group->setLocale('de_DE');
  448. $group->add($field);
  449. }
  450. public function testLocaleIsPassedToField_SetAfterAddingTheField()
  451. {
  452. $field = $this->getMockForAbstractClass(__NAMESPACE__ . '\FieldGroupTest_Field', array(), '', false, false);
  453. $field->expects($this->any())
  454. ->method('getKey')
  455. ->will($this->returnValue('firstName'));
  456. // DOESN'T WORK!
  457. // $field = $this->getMock(__NAMESPACE__ . '\Fixtures\Field', array(), array(), '', false, false);
  458. // $field->expects($this->once())
  459. // ->method('setLocale')
  460. // ->with($this->equalTo('de_AT'));
  461. // $field->expects($this->once())
  462. // ->method('setLocale')
  463. // ->with($this->equalTo('de_DE'));
  464. $group = new TestFieldGroup('author');
  465. $group->add($field);
  466. $group->setLocale('de_DE');
  467. $this->assertEquals(array(class_exists('\Locale', false) ? \Locale::getDefault() : 'en', 'de_DE'), $field->locales);
  468. }
  469. public function testSupportsClone()
  470. {
  471. $group = new TestFieldGroup('author');
  472. $group->add($this->createMockField('firstName'));
  473. $clone = clone $group;
  474. $this->assertNotSame($clone['firstName'], $group['firstName']);
  475. }
  476. public function testBindWithoutPriorSetData()
  477. {
  478. return; // TODO
  479. $field = $this->createMockField('firstName');
  480. $field->expects($this->any())
  481. ->method('getData')
  482. ->will($this->returnValue('Bernhard'));
  483. $group = new TestFieldGroup('author');
  484. $group->add($field);
  485. $group->bind(array('firstName' => 'Bernhard'));
  486. $this->assertEquals(array('firstName' => 'Bernhard'), $group->getData());
  487. }
  488. public function testGetHiddenFieldsReturnsOnlyHiddenFields()
  489. {
  490. $group = $this->getGroupWithBothVisibleAndHiddenField();
  491. $hiddenFields = $group->getHiddenFields(true, false);
  492. $this->assertSame(array($group['hiddenField']), $hiddenFields);
  493. }
  494. public function testGetVisibleFieldsReturnsOnlyVisibleFields()
  495. {
  496. $group = $this->getGroupWithBothVisibleAndHiddenField();
  497. $visibleFields = $group->getVisibleFields(true, false);
  498. $this->assertSame(array($group['visibleField']), $visibleFields);
  499. }
  500. /**
  501. * Create a group containing two fields, "visibleField" and "hiddenField"
  502. *
  503. * @return FieldGroup
  504. */
  505. protected function getGroupWithBothVisibleAndHiddenField()
  506. {
  507. $group = new TestFieldGroup('testGroup');
  508. // add a visible field
  509. $visibleField = $this->createMockField('visibleField');
  510. $visibleField->expects($this->once())
  511. ->method('isHidden')
  512. ->will($this->returnValue(false));
  513. $group->add($visibleField);
  514. // add a hidden field
  515. $hiddenField = $this->createMockField('hiddenField');
  516. $hiddenField->expects($this->once())
  517. ->method('isHidden')
  518. ->will($this->returnValue(true));
  519. $group->add($hiddenField);
  520. return $group;
  521. }
  522. protected function createMockField($key)
  523. {
  524. $field = $this->getMock(
  525. 'Symfony\Component\Form\FieldInterface',
  526. array(),
  527. array(),
  528. '',
  529. false, // don't use constructor
  530. false // don't call parent::__clone
  531. );
  532. $field->expects($this->any())
  533. ->method('getKey')
  534. ->will($this->returnValue($key));
  535. return $field;
  536. }
  537. protected function createInvalidMockField($key)
  538. {
  539. $field = $this->createMockField($key);
  540. $field->expects($this->any())
  541. ->method('isValid')
  542. ->will($this->returnValue(false));
  543. return $field;
  544. }
  545. protected function createValidMockField($key)
  546. {
  547. $field = $this->createMockField($key);
  548. $field->expects($this->any())
  549. ->method('isValid')
  550. ->will($this->returnValue(true));
  551. return $field;
  552. }
  553. protected function createNonMultipartMockField($key)
  554. {
  555. $field = $this->createMockField($key);
  556. $field->expects($this->any())
  557. ->method('isMultipart')
  558. ->will($this->returnValue(false));
  559. return $field;
  560. }
  561. protected function createMultipartMockField($key)
  562. {
  563. $field = $this->createMockField($key);
  564. $field->expects($this->any())
  565. ->method('isMultipart')
  566. ->will($this->returnValue(true));
  567. return $field;
  568. }
  569. protected function createMockTransformer()
  570. {
  571. return $this->getMock('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface', array(), array(), '', false, false);
  572. }
  573. }