示例#1
0
 /**
  * @test
  */
 public function renderCorrectlySetsTypeNameAndValueAttributes()
 {
     $mockTagBuilder = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\TagBuilder', array('addAttribute', 'setContent', 'render'), array(), '', FALSE);
     $mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('type', 'file');
     $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('name', 'someName');
     $this->viewHelper->expects($this->at(0))->method('registerFieldNameForFormTokenGeneration')->with('someName[name]');
     $this->viewHelper->expects($this->at(1))->method('registerFieldNameForFormTokenGeneration')->with('someName[type]');
     $this->viewHelper->expects($this->at(2))->method('registerFieldNameForFormTokenGeneration')->with('someName[tmp_name]');
     $this->viewHelper->expects($this->at(3))->method('registerFieldNameForFormTokenGeneration')->with('someName[error]');
     $this->viewHelper->expects($this->at(4))->method('registerFieldNameForFormTokenGeneration')->with('someName[size]');
     $mockTagBuilder->expects($this->once())->method('render');
     $this->viewHelper->injectTagBuilder($mockTagBuilder);
     $arguments = array('name' => 'someName');
     $this->viewHelper->setArguments($arguments);
     $this->viewHelper->setViewHelperNode(new \TYPO3\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
     $this->viewHelper->initialize();
     $this->viewHelper->render();
 }
 /**
  * @test
  */
 public function hiddenFieldsContainDataOfAPreviouslyUploadedResource()
 {
     $mockResource = $this->getMock('TYPO3\\Flow\\Resource\\Resource');
     $mockResource->expects($this->any())->method('getFilename')->will($this->returnValue('theResourceFilename'));
     $mockResource->expects($this->any())->method('getResourcePointer')->will($this->returnValue('theResourcePointer'));
     $resourceData = array('error' => \UPLOAD_ERR_NO_FILE, 'submittedFile' => array('filename' => 'theResourceFilename', 'resourcePointer' => 'theResourcePointer'));
     $this->mockPropertyMapper->expects($this->atLeastOnce())->method('convert')->with($resourceData, 'TYPO3\\Flow\\Resource\\Resource')->will($this->returnValue($mockResource));
     $this->viewHelper->expects($this->atLeastOnce())->method('getValue')->will($this->returnValue($resourceData));
     $expectedResult = '<input type="hidden" name="[submittedFile][filename]" value="theResourceFilename" /><input type="hidden" name="[submittedFile][resourcePointer]" value="theResourcePointer" />';
     $this->viewHelper->initialize();
     $actualResult = $this->viewHelper->render();
     $this->assertSame($expectedResult, $actualResult);
 }
 /**
  * @test
  */
 public function hiddenFieldContainsDataOfAPreviouslyUploadedResource()
 {
     $mockResourceUuid = '79ecda60-1a27-69ca-17bf-a5d9e80e6c39';
     $submittedData = array('foo' => array('bar' => array('name' => 'someFilename.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/some/tmp/name', 'error' => 0, 'size' => 123)));
     /** @var Result|\PHPUnit_Framework_MockObject_MockObject $mockValidationResults */
     $mockValidationResults = $this->getMockBuilder(\TYPO3\Flow\Error\Result::class)->disableOriginalConstructor()->getMock();
     $mockValidationResults->expects($this->atLeastOnce())->method('hasErrors')->will($this->returnValue(true));
     $this->request->expects($this->at(0))->method('getInternalArgument')->with('__submittedArgumentValidationResults')->will($this->returnValue($mockValidationResults));
     $this->request->expects($this->at(1))->method('getInternalArgument')->with('__submittedArguments')->will($this->returnValue($submittedData));
     /** @var Resource|\PHPUnit_Framework_MockObject_MockObject $mockResource */
     $mockResource = $this->getMockBuilder(\TYPO3\Flow\Resource\Resource::class)->disableOriginalConstructor()->getMock();
     $mockPersistenceManager = $this->createMock(\TYPO3\Flow\Persistence\PersistenceManagerInterface::class);
     $mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($mockResource)->will($this->returnValue($mockResourceUuid));
     $this->inject($this->viewHelper, 'persistenceManager', $mockPersistenceManager);
     $this->mockPropertyMapper->expects($this->atLeastOnce())->method('convert')->with($submittedData['foo']['bar'], \TYPO3\Flow\Resource\Resource::class)->will($this->returnValue($mockResource));
     $mockValueResource = $this->getMockBuilder(\TYPO3\Flow\Resource\Resource::class)->disableOriginalConstructor()->getMock();
     $this->viewHelper->setArguments(array('name' => 'foo[bar]', 'value' => $mockValueResource));
     $expectedResult = '<input type="hidden" name="foo[bar][originallySubmittedResource][__identity]" value="' . $mockResourceUuid . '" />';
     $this->viewHelper->initialize();
     $actualResult = $this->viewHelper->render();
     $this->assertSame($expectedResult, $actualResult);
 }