Example #1
0
	/**
	 * Make sure the hook in get sourceCollection is called
	 *
	 * @test
	 */
	public function getImageSourceCollectionHookCalled() {
		$this->subject = $this->getAccessibleMock(
			\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
			array('getResourceFactory', 'stdWrap', 'getImgResource')
		);
		$this->subject->start(array(), 'tt_content');

		// Avoid calling stdwrap and getImgResource
		$this->subject->expects($this->any())
			->method('stdWrap')
			->will($this->returnArgument(0));

		$this->subject->expects($this->any())
			->method('getImgResource')
			->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));

		$resourceFactory = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceFactory::class, array(), array(), '', FALSE);
		$this->subject->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));

		$className = $this->getUniqueId('tx_coretest_getImageSourceCollectionHookCalled');
		$getImageSourceCollectionHookMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectOneSourceCollectionHookInterface::class, array('getOneSourceCollection'), array(), $className);
		$GLOBALS['T3_VAR']['getUserObj'][$className] = $getImageSourceCollectionHookMock;
		$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'][] = $className;

		$getImageSourceCollectionHookMock
			->expects($this->exactly(1))
			->method('getOneSourceCollection')
			->will($this->returnCallback(array($this, 'isGetOneSourceCollectionCalledCallback')));

		$configuration = array(
			'layoutKey' => 'data',
			'layout.' => array (
				'data.' => array(
					'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
					'source' => 'data-###DATAKEY###="###SRC###"'
				)
			),
			'sourceCollection.' => array(
				'small.' => array(
					'width' => '200',
					'srcsetCandidate' => '600w',
					'mediaQuery' => '(max-device-width: 600px)',
					'dataKey' => 'small',
				),
			),
		);

		$result = $this->subject->getImageSourceCollection('data', $configuration, $this->getUniqueId('testImage-'));

		$this->assertSame($result, 'isGetOneSourceCollectionCalledCallback');
	}