/**
  * @test
  */
 public function addDataThrowsExceptionIfDatabaseFetchingReturnsInvalidRowResultData()
 {
     $input = ['tableName' => 'tt_content', 'command' => 'edit', 'vanillaUid' => 10];
     $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
     $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn('invalid result data');
     $this->setExpectedException(\UnexpectedValueException::class, '', 1437656323);
     $this->subject->addData($input);
 }
 /**
  * @test
  */
 public function addDataSetsParentPageRowOnParentIfCommandIsEdit()
 {
     $input = ['tableName' => 'tt_content', 'command' => 'edit', 'vanillaUid' => 123, 'databaseRow' => ['uid' => 123, 'pid' => 321]];
     $parentPageRow = ['uid' => 321, 'pid' => 456];
     $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
     $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=321')->willReturn($parentPageRow);
     $result = $this->subject->addData($input);
     $this->assertSame($parentPageRow, $result['parentPageRow']);
 }
 /**
  * @test
  */
 public function addDataSetsTypeValueFromNestedTcaGroupField()
 {
     $input = ['processedTca' => ['ctrl' => ['type' => 'uid_local:type'], 'columns' => ['uid_local' => ['config' => ['type' => 'group', 'internal_type' => 'db', 'size' => 1, 'maxitems' => 1, 'minitems' => 0, 'allowed' => 'sys_file']]], 'types' => ['2' => 'foo']], 'databaseRow' => ['uid_local' => 'sys_file_222|my_test.jpg']];
     $foreignRecordResult = ['type' => 2];
     // Required for BackendUtility::getRecord
     $GLOBALS['TCA']['sys_file'] = array('foo');
     $this->dbProphecy->exec_SELECTgetSingleRow('type', 'sys_file', 'uid=222')->shouldBeCalled()->willReturn($foreignRecordResult);
     $expected = $input;
     $expected['recordTypeValue'] = '2';
     $this->assertSame($expected, $this->subject->addData($input));
 }
 /**
  * @test
  */
 public function addDataResolvesLanguageIsocodeFromStaticInfoTable()
 {
     if (ExtensionManagementUtility::isLoaded('static_info_tables') === false) {
         $this->markTestSkipped('no ext:static_info_tables available');
     }
     $dbRows = [['uid' => 3, 'title' => 'french', 'language_isocode' => '', 'static_lang_isocode' => 42, 'flag' => 'fr']];
     $this->dbProphecy->exec_SELECTgetRows('uid,title,language_isocode,static_lang_isocode,flag', 'sys_language', 'pid=0')->shouldBeCalled()->willReturn($dbRows);
     // Needed for backendUtility::getRecord()
     $GLOBALS['TCA']['static_languages'] = ['foo'];
     $this->dbProphecy->exec_SELECTgetSingleRow('lg_iso_2', 'static_languages', 'uid=42')->shouldBeCalled()->willReturn(['lg_iso_2' => 'FR']);
     $expected = ['systemLanguageRows' => [-1 => ['uid' => -1, 'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages', 'iso' => 'DEF', 'flagIconIdentifier' => 'flags-multiple'], 0 => ['uid' => 0, 'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage', 'iso' => 'DEF', 'flagIconIdentifier' => 'empty-empty'], 3 => ['uid' => 3, 'title' => 'french', 'flagIconIdentifier' => 'flags-fr', 'iso' => 'FR']]];
     $this->assertSame($expected, $this->subject->addData([]));
 }
 /**
  * @test
  */
 public function addDataSetsDoesNotAddHandledRowAsAdditionalLanguageRows()
 {
     $input = ['tableName' => 'tt_content', 'databaseRow' => ['uid' => 42, 'text' => 'localized text', 'sys_language_uid' => 2, 'l10n_parent' => 23], 'processedTca' => ['ctrl' => ['languageField' => 'sys_language_uid', 'transOrigPointerField' => 'l10n_parent']], 'userTsConfig' => ['options.' => ['additionalPreviewLanguages' => '2,3']], 'systemLanguageRows' => [0 => ['uid' => 0, 'title' => 'Default Language', 'iso' => 'DEV'], 2 => ['uid' => 2, 'title' => 'dansk', 'iso' => 'dk,'], 3 => ['uid' => 3, 'title' => 'french', 'iso' => 'fr']], 'defaultLanguageRow' => null, 'additionalLanguageRows' => []];
     $translationResult = ['translations' => [3 => ['uid' => 43]]];
     // For BackendUtility::getRecord()
     $GLOBALS['TCA']['tt_content'] = array('foo');
     $recordWsolResult = ['uid' => 43, 'text' => 'localized text in french'];
     $defaultLanguageRow = ['uid' => 23, 'text' => 'default language text', 'sys_language_uid' => 0];
     // Needed for BackendUtility::getRecord
     $GLOBALS['TCA']['tt_content'] = array('foo');
     $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
     /** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
     $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
     GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
     $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
     $translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled();
     // This is the real check: The "additional overlay" should be fetched
     $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult);
     $expected = $input;
     $expected['defaultLanguageRow'] = $defaultLanguageRow;
     $expected['additionalLanguageRows'] = [3 => ['uid' => 43, 'text' => 'localized text in french']];
     $this->assertEquals($expected, $this->subject->addData($input));
 }