[TASK] Add simple functional tests for import/export 07/26907/8
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Fri, 17 Jan 2014 17:39:42 +0000 (18:39 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 31 Jan 2014 23:08:38 +0000 (00:08 +0100)
This patch adds some tests for a simple import and export
scenario for pages and a tt_content element.

Resolves: #55100
Releases: 6.2
Change-Id: Ia4b9a8990c7b757d25f18500def6ddd060426c2f
Reviewed-on: https://review.typo3.org/26907
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Build/FunctionalTests.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/Database/pages.xml [new file with mode: 0644]
typo3/sysext/impexp/Tests/Functional/Fixtures/Database/tt_content.xml [new file with mode: 0644]
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExport/pages-and-ttcontent.xml [new file with mode: 0644]
typo3/sysext/impexp/Tests/Functional/ImportExport/ExportSimpleTest.php [new file with mode: 0644]
typo3/sysext/impexp/Tests/Functional/ImportExport/ImportSimpleTest.php [new file with mode: 0644]

index ec76c62..8c966e9 100644 (file)
@@ -27,6 +27,9 @@
                <testsuite name="EXT:core tests">
                        <directory>../../../../typo3/sysext/core/Tests/Functional/</directory>
                </testsuite>
+               <testsuite name="EXT:impexp tests">
+                       <directory>../../../../typo3/sysext/impexp/Tests/Functional/</directory>
+               </testsuite>
                <testsuite name="EXT:workspaces tests">
                        <directory>../../../../typo3/sysext/workspaces/Tests/Functional/</directory>
                </testsuite>
diff --git a/typo3/sysext/impexp/Tests/Functional/Fixtures/Database/pages.xml b/typo3/sysext/impexp/Tests/Functional/Fixtures/Database/pages.xml
new file mode 100644 (file)
index 0000000..b2f6e23
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dataset>
+       <pages>
+               <uid>1</uid>
+               <pid>0</pid>
+               <title>Root</title>
+               <deleted>0</deleted>
+               <perms_everybody>15</perms_everybody>
+       </pages>
+       <pages>
+               <uid>2</uid>
+               <pid>1</pid>
+               <title>Dummy 1-2</title>
+               <deleted>0</deleted>
+               <perms_everybody>15</perms_everybody>
+       </pages>
+</dataset>
\ No newline at end of file
diff --git a/typo3/sysext/impexp/Tests/Functional/Fixtures/Database/tt_content.xml b/typo3/sysext/impexp/Tests/Functional/Fixtures/Database/tt_content.xml
new file mode 100644 (file)
index 0000000..49ceb10
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dataset>
+    <tt_content>
+        <uid>1</uid>
+        <pid>1</pid>
+        <header>Test content</header>
+        <deleted>0</deleted>
+        <t3ver_oid>0</t3ver_oid>
+        <t3ver_wsid>0</t3ver_wsid>
+    </tt_content>
+</dataset>
\ No newline at end of file
diff --git a/typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExport/pages-and-ttcontent.xml b/typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExport/pages-and-ttcontent.xml
new file mode 100644 (file)
index 0000000..42d6cbb
--- /dev/null
@@ -0,0 +1,301 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<T3RecordDocument>
+       <header type="array">
+               <records type="array">
+                       <table index="pages" type="array">
+                               <rec index="1" type="array">
+                                       <uid>1</uid>
+                                       <pid>0</pid>
+                                       <title>Root</title>
+                                       <size>1649</size>
+                                       <relations index="rels" type="array">
+                                       </relations>
+                                       <softrefs type="array">
+                                       </softrefs>
+                               </rec>
+                               <rec index="2" type="array">
+                                       <uid>2</uid>
+                                       <pid>1</pid>
+                                       <title>Dummy 1-2</title>
+                                       <size>1654</size>
+                                       <relations index="rels" type="array">
+                                       </relations>
+                                       <softrefs type="array">
+                                       </softrefs>
+                               </rec>
+                       </table>
+                       <table index="tt_content" type="array">
+                               <rec index="1" type="array">
+                                       <uid>1</uid>
+                                       <pid>1</pid>
+                                       <title>Test content</title>
+                                       <size>2042</size>
+                                       <relations index="rels" type="array">
+                                       </relations>
+                                       <softrefs type="array">
+                                       </softrefs>
+                               </rec>
+                       </table>
+               </records>
+               <pid_lookup type="array">
+                       <page_contents index="0" type="array">
+                               <table index="pages" type="array">
+                                       <item index="1">1</item>
+                               </table>
+                       </page_contents>
+                       <page_contents index="1" type="array">
+                               <table index="pages" type="array">
+                                       <item index="2">1</item>
+                               </table>
+                               <table index="tt_content" type="array">
+                                       <item index="1">1</item>
+                               </table>
+                       </page_contents>
+               </pid_lookup>
+               <pagetree type="array">
+                       <node index="1" type="array">
+                               <uid>1</uid>
+                               <node index="subrow" type="array">
+                                       <node index="2" type="array">
+                                               <uid>2</uid>
+                                       </node>
+                               </node>
+                       </node>
+               </pagetree>
+       </header>
+       <records type="array">
+               <tablerow index="pages:1" type="array">
+                       <fieldlist index="data" type="array">
+                               <field index="uid">1</field>
+                               <field index="pid">0</field>
+                               <field index="t3ver_oid">0</field>
+                               <field index="t3ver_id">0</field>
+                               <field index="t3ver_wsid">0</field>
+                               <field index="t3ver_label"></field>
+                               <field index="t3ver_state">0</field>
+                               <field index="t3ver_stage">0</field>
+                               <field index="t3ver_count">0</field>
+                               <field index="t3ver_tstamp">0</field>
+                               <field index="t3ver_move_id">0</field>
+                               <field index="t3_origuid">0</field>
+                               <field index="tstamp">0</field>
+                               <field index="sorting">0</field>
+                               <field index="deleted">0</field>
+                               <field index="perms_userid">0</field>
+                               <field index="perms_groupid">0</field>
+                               <field index="perms_user">0</field>
+                               <field index="perms_group">0</field>
+                               <field index="perms_everybody">15</field>
+                               <field index="editlock">0</field>
+                               <field index="crdate">0</field>
+                               <field index="cruser_id">0</field>
+                               <field index="hidden">0</field>
+                               <field index="title">Root</field>
+                               <field index="doktype">0</field>
+                               <field index="TSconfig" type="NULL"></field>
+                               <field index="storage_pid">0</field>
+                               <field index="is_siteroot">0</field>
+                               <field index="php_tree_stop">0</field>
+                               <field index="tx_impexp_origuid">0</field>
+                               <field index="url"></field>
+                               <field index="starttime">0</field>
+                               <field index="endtime">0</field>
+                               <field index="urltype">0</field>
+                               <field index="shortcut">0</field>
+                               <field index="shortcut_mode">0</field>
+                               <field index="no_cache">0</field>
+                               <field index="fe_group">0</field>
+                               <field index="subtitle"></field>
+                               <field index="layout">0</field>
+                               <field index="url_scheme">0</field>
+                               <field index="target"></field>
+                               <field index="media" type="NULL"></field>
+                               <field index="lastUpdated">0</field>
+                               <field index="keywords" type="NULL"></field>
+                               <field index="cache_timeout">0</field>
+                               <field index="cache_tags"></field>
+                               <field index="newUntil">0</field>
+                               <field index="description" type="NULL"></field>
+                               <field index="no_search">0</field>
+                               <field index="SYS_LASTCHANGED">0</field>
+                               <field index="abstract" type="NULL"></field>
+                               <field index="module"></field>
+                               <field index="extendToSubpages">0</field>
+                               <field index="author"></field>
+                               <field index="author_email"></field>
+                               <field index="nav_title"></field>
+                               <field index="nav_hide">0</field>
+                               <field index="content_from_pid">0</field>
+                               <field index="mount_pid">0</field>
+                               <field index="mount_pid_ol">0</field>
+                               <field index="alias"></field>
+                               <field index="l18n_cfg">0</field>
+                               <field index="fe_login_mode">0</field>
+                               <field index="backend_layout"></field>
+                               <field index="backend_layout_next_level"></field>
+                       </fieldlist>
+                       <related index="rels" type="array">
+                       </related>
+               </tablerow>
+               <tablerow index="pages:2" type="array">
+                       <fieldlist index="data" type="array">
+                               <field index="uid">2</field>
+                               <field index="pid">1</field>
+                               <field index="t3ver_oid">0</field>
+                               <field index="t3ver_id">0</field>
+                               <field index="t3ver_wsid">0</field>
+                               <field index="t3ver_label"></field>
+                               <field index="t3ver_state">0</field>
+                               <field index="t3ver_stage">0</field>
+                               <field index="t3ver_count">0</field>
+                               <field index="t3ver_tstamp">0</field>
+                               <field index="t3ver_move_id">0</field>
+                               <field index="t3_origuid">0</field>
+                               <field index="tstamp">0</field>
+                               <field index="sorting">0</field>
+                               <field index="deleted">0</field>
+                               <field index="perms_userid">0</field>
+                               <field index="perms_groupid">0</field>
+                               <field index="perms_user">0</field>
+                               <field index="perms_group">0</field>
+                               <field index="perms_everybody">15</field>
+                               <field index="editlock">0</field>
+                               <field index="crdate">0</field>
+                               <field index="cruser_id">0</field>
+                               <field index="hidden">0</field>
+                               <field index="title">Dummy 1-2</field>
+                               <field index="doktype">0</field>
+                               <field index="TSconfig" type="NULL"></field>
+                               <field index="storage_pid">0</field>
+                               <field index="is_siteroot">0</field>
+                               <field index="php_tree_stop">0</field>
+                               <field index="tx_impexp_origuid">0</field>
+                               <field index="url"></field>
+                               <field index="starttime">0</field>
+                               <field index="endtime">0</field>
+                               <field index="urltype">0</field>
+                               <field index="shortcut">0</field>
+                               <field index="shortcut_mode">0</field>
+                               <field index="no_cache">0</field>
+                               <field index="fe_group">0</field>
+                               <field index="subtitle"></field>
+                               <field index="layout">0</field>
+                               <field index="url_scheme">0</field>
+                               <field index="target"></field>
+                               <field index="media" type="NULL"></field>
+                               <field index="lastUpdated">0</field>
+                               <field index="keywords" type="NULL"></field>
+                               <field index="cache_timeout">0</field>
+                               <field index="cache_tags"></field>
+                               <field index="newUntil">0</field>
+                               <field index="description" type="NULL"></field>
+                               <field index="no_search">0</field>
+                               <field index="SYS_LASTCHANGED">0</field>
+                               <field index="abstract" type="NULL"></field>
+                               <field index="module"></field>
+                               <field index="extendToSubpages">0</field>
+                               <field index="author"></field>
+                               <field index="author_email"></field>
+                               <field index="nav_title"></field>
+                               <field index="nav_hide">0</field>
+                               <field index="content_from_pid">0</field>
+                               <field index="mount_pid">0</field>
+                               <field index="mount_pid_ol">0</field>
+                               <field index="alias"></field>
+                               <field index="l18n_cfg">0</field>
+                               <field index="fe_login_mode">0</field>
+                               <field index="backend_layout"></field>
+                               <field index="backend_layout_next_level"></field>
+                       </fieldlist>
+                       <related index="rels" type="array">
+                       </related>
+               </tablerow>
+               <tablerow index="tt_content:1" type="array">
+                       <fieldlist index="data" type="array">
+                               <field index="uid">1</field>
+                               <field index="pid">1</field>
+                               <field index="t3ver_oid">0</field>
+                               <field index="t3ver_id">0</field>
+                               <field index="t3ver_wsid">0</field>
+                               <field index="t3ver_label"></field>
+                               <field index="t3ver_state">0</field>
+                               <field index="t3ver_stage">0</field>
+                               <field index="t3ver_count">0</field>
+                               <field index="t3ver_tstamp">0</field>
+                               <field index="t3ver_move_id">0</field>
+                               <field index="t3_origuid">0</field>
+                               <field index="tstamp">0</field>
+                               <field index="crdate">0</field>
+                               <field index="cruser_id">0</field>
+                               <field index="hidden">0</field>
+                               <field index="sorting">0</field>
+                               <field index="CType" />
+                               <field index="header">Test content</field>
+                               <field index="header_position"></field>
+                               <field index="bodytext" type="NULL"></field>
+                               <field index="image" type="NULL"></field>
+                               <field index="imagewidth">0</field>
+                               <field index="imageorient">0</field>
+                               <field index="imagecaption" type="NULL"></field>
+                               <field index="imagecols">0</field>
+                               <field index="imageborder">0</field>
+                               <field index="media" type="NULL"></field>
+                               <field index="layout">0</field>
+                               <field index="deleted">0</field>
+                               <field index="cols">0</field>
+                               <field index="records" type="NULL"></field>
+                               <field index="pages" type="NULL"></field>
+                               <field index="starttime">0</field>
+                               <field index="endtime">0</field>
+                               <field index="colPos">0</field>
+                               <field index="subheader"></field>
+                               <field index="spaceBefore">0</field>
+                               <field index="spaceAfter">0</field>
+                               <field index="fe_group">0</field>
+                               <field index="header_link"></field>
+                               <field index="imagecaption_position"></field>
+                               <field index="image_link" type="NULL"></field>
+                               <field index="image_zoom">0</field>
+                               <field index="image_noRows">0</field>
+                               <field index="image_effects">0</field>
+                               <field index="image_compression">0</field>
+                               <field index="altText" type="NULL"></field>
+                               <field index="titleText" type="NULL"></field>
+                               <field index="longdescURL" type="NULL"></field>
+                               <field index="header_layout">0</field>
+                               <field index="menu_type">0</field>
+                               <field index="list_type">0</field>
+                               <field index="table_border">0</field>
+                               <field index="table_cellspacing">0</field>
+                               <field index="table_cellpadding">0</field>
+                               <field index="table_bgColor">0</field>
+                               <field index="select_key"></field>
+                               <field index="sectionIndex">0</field>
+                               <field index="linkToTop">0</field>
+                               <field index="file_collections" type="NULL"></field>
+                               <field index="filelink_size">0</field>
+                               <field index="filelink_sorting"></field>
+                               <field index="target"></field>
+                               <field index="section_frame">0</field>
+                               <field index="date">0</field>
+                               <field index="multimedia" type="NULL"></field>
+                               <field index="image_frames">0</field>
+                               <field index="recursive">0</field>
+                               <field index="imageheight">0</field>
+                               <field index="rte_enabled">0</field>
+                               <field index="sys_language_uid">0</field>
+                               <field index="tx_impexp_origuid">0</field>
+                               <field index="pi_flexform" type="NULL"></field>
+                               <field index="accessibility_title"></field>
+                               <field index="accessibility_bypass">0</field>
+                               <field index="accessibility_bypass_text"></field>
+                               <field index="l18n_parent">0</field>
+                               <field index="l18n_diffsource" type="NULL"></field>
+                               <field index="selected_categories" type="NULL"></field>
+                               <field index="category_field"></field>
+                       </fieldlist>
+                       <related index="rels" type="array">
+                       </related>
+               </tablerow>
+       </records>
+</T3RecordDocument>
\ No newline at end of file
diff --git a/typo3/sysext/impexp/Tests/Functional/ImportExport/ExportSimpleTest.php b/typo3/sysext/impexp/Tests/Functional/ImportExport/ExportSimpleTest.php
new file mode 100644 (file)
index 0000000..08f609e
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+namespace TYPO3\CMS\Impexp\Tests\Functional\ImportExport;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2014 Marc Bastian Heinrichs <typo3@mbh-software.de>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+
+/**
+ * Functional test for the ImportExport
+ */
+class ExportSimpleTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
+
+       /**
+        * @var array
+        */
+       protected $coreExtensionsToLoad = array('impexp');
+
+       public function setUp() {
+               parent::setUp();
+               $this->setUpBackendUserFromFixture(1);
+
+               $this->importDataSet(__DIR__ . '/../Fixtures/Database/pages.xml');
+               $this->importDataSet(__DIR__ . '/../Fixtures/Database/tt_content.xml');
+       }
+
+       /**
+        * @test
+        */
+       public function canExportSimplePagesAndRelatedTtContent() {
+               $permsClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
+
+               /** @var $export \TYPO3\CMS\Impexp\ImportExport */
+               $export = GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
+               $export->init();
+
+               $export->export_addRecord('pages', BackendUtility::getRecord('pages', 1));
+               $export->export_addRecord('pages', BackendUtility::getRecord('pages', 2));
+               $export->export_addRecord('tt_content', BackendUtility::getRecord('tt_content', 1));
+
+               $pidToStart = 1;
+               /** @var $tree \TYPO3\CMS\Backend\Tree\View\PageTreeView */
+               $tree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
+               $tree->init('AND ' . $permsClause);
+               $tree->tree[] = array('row' => $pidToStart);
+               $tree->buffer_idH = array();
+               $tree->getTree(1, 1, '');
+
+               $idH = array();
+               $idH[$pidToStart]['uid'] = $pidToStart;
+               if (count($tree->buffer_idH)) {
+                       $idH[$pidToStart]['subrow'] = $tree->buffer_idH;
+               }
+               $export->setPageTree($idH);
+
+               // After adding ALL records we set relations:
+               for ($a = 0; $a < 10; $a++) {
+                       $addR = $export->export_addDBRelations($a);
+                       if (!count($addR)) {
+                               break;
+                       }
+               }
+
+               $export->export_addFilesFromRelations();
+
+               $out = $export->compileMemoryToFileContent('xml');
+
+               $this->assertXmlStringEqualsXmlFile(__DIR__ . '/../Fixtures/ImportExport/pages-and-ttcontent.xml', $out);
+       }
+
+}
\ No newline at end of file
diff --git a/typo3/sysext/impexp/Tests/Functional/ImportExport/ImportSimpleTest.php b/typo3/sysext/impexp/Tests/Functional/ImportExport/ImportSimpleTest.php
new file mode 100644 (file)
index 0000000..995a721
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+namespace TYPO3\CMS\Impexp\Tests\Functional\ImportExport;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2014 Marc Bastian Heinrichs <typo3@mbh-software.de>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+
+/**
+ * Functional test for the ImportExport
+ */
+class ImportSimpleTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
+
+       /**
+        * @var array
+        */
+       protected $coreExtensionsToLoad = array('impexp');
+
+       public function setUp() {
+               parent::setUp();
+               $this->setUpBackendUserFromFixture(1);
+               \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
+       }
+
+       /**
+        * @test
+        */
+       public function canImportSimplePagesAndRelatedTtContent() {
+               /** @var $import \TYPO3\CMS\Impexp\ImportExport */
+               $import = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
+               $import->init(0, 'import');
+               $import->loadFile(__DIR__ . '/../Fixtures/ImportExport/pages-and-ttcontent.xml', 1);
+               $import->importData(0);
+
+               $database = $this->getDatabase();
+
+               $row = $database->exec_SELECTgetSingleRow('*', 'pages', 'uid = 1');
+               $this->assertNotEmpty($row);
+               $this->assertEquals(0, $row['pid']);
+               $this->assertEquals('Root', $row['title']);
+
+               $row = $database->exec_SELECTgetSingleRow('*', 'pages', 'uid = 2');
+               $this->assertNotEmpty($row);
+               $this->assertEquals(1, $row['pid']);
+               $this->assertEquals('Dummy 1-2', $row['title']);
+
+               $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = 1');
+               $this->assertNotEmpty($row);
+               $this->assertEquals(1, $row['pid']);
+               $this->assertEquals('Test content', $row['header']);
+       }
+
+}
\ No newline at end of file