public function test_tcemain_moveUp_bug2154()
 {
     global $TYPO3_DB, $BE_USER;
     $BE_USER->setWorkspace(0);
     $tce = t3lib_div::makeInstance('t3lib_TCEmain');
     $tce->stripslashes_values = 0;
     $this->fixture_createTestPage();
     $this->fixture_createTestPageDSTO('twocolumns');
     // Create 3 new content elements in the main area and 3 in the right bar:
     $elementUids = array();
     for ($i = 0; $i < 3; $i++) {
         $row = $this->fixture_getContentElementRow_TEXT();
         $row['bodytext'] = 'move test element #' . ($i + 1);
         $destinationPointer = array('table' => 'pages', 'uid' => $this->testPageUID, 'sheet' => 'sDEF', 'sLang' => 'lDEF', 'field' => 'field_content', 'vLang' => 'vDEF', 'position' => $i);
         $elementUids[$i + 1] = $this->apiObj->insertElement($destinationPointer, $row);
     }
     for ($i = 3; $i < 6; $i++) {
         $row = $this->fixture_getContentElementRow_TEXT();
         $row['bodytext'] = 'move test element (right bar) #' . ($i + 1);
         $destinationPointer = array('table' => 'pages', 'uid' => $this->testPageUID, 'sheet' => 'sDEF', 'sLang' => 'lDEF', 'field' => 'field_rightbar', 'vLang' => 'vDEF', 'position' => $i - 3);
         $elementUids[$i + 1] = $this->apiObj->insertElement($destinationPointer, $row);
     }
     // Main area: move the third element to after the first element via TCEmain:
     $cmdMap = array('tt_content' => array($elementUids[3] => array('move' => '-' . $elementUids[1])));
     $tce->start(array(), $cmdMap);
     $tce->process_cmdmap();
     // ... and then move it one more up (exposes the bug 2154):
     $cmdMap = array('tt_content' => array($elementUids[3] => array('move' => '-' . $elementUids[1])));
     $tce->start(array(), $cmdMap);
     $tce->process_cmdmap();
     // Check if the elements are in the right columns in the right order:
     $testPageRecord = t3lib_beFunc::getRecordRaw('pages', 'uid=' . $this->testPageUID, 'tx_templavoila_flex');
     $flexform = simplexml_load_string($testPageRecord['tx_templavoila_flex']);
     $fieldContent_xpathResArr = $flexform->xpath("//data/sheet[@index='sDEF']/language[@index='lDEF']/field[@index='field_content']/value[@index='vDEF']");
     $fieldRightBar_xpathResArr = $flexform->xpath("//data/sheet[@index='sDEF']/language[@index='lDEF']/field[@index='field_rightbar']/value[@index='vDEF']");
     $everythingIsFine = (string) $fieldContent_xpathResArr[0] === $elementUids[3] . ',' . $elementUids[1] . ',' . $elementUids[2] && (string) $fieldRightBar_xpathResArr[0] === $elementUids[4] . ',' . $elementUids[5] . ',' . $elementUids[6];
     self::assertTrue($everythingIsFine, 'The reference list is not as expected after moving the third element up two times in the left column!');
     // ... and then move the now second element one up again, measured by the sorting field! (also exposes the bug 2154):
     $elementsBySortingFieldArr = $TYPO3_DB->exec_SELECTgetRows('uid', 'tt_content', 'pid=' . intval($this->testPageUID), '', 'sorting');
     $positionOfElement1 = NULL;
     foreach ($elementsBySortingFieldArr as $index => $row) {
         if ($elementUids[1] == $row['uid']) {
             $positionOfElement1 = $index;
         }
     }
     $cmdMap = array('tt_content' => array($elementUids[1] => array('move' => '-' . $elementsBySortingFieldArr[$positionOfElement1 - 1]['uid'])));
     $tce->start(array(), $cmdMap);
     $tce->process_cmdmap();
     // Check again if the elements are in the right columns in the right order:
     $testPageRecord = t3lib_beFunc::getRecordRaw('pages', 'uid=' . $this->testPageUID, 'tx_templavoila_flex');
     $flexform = simplexml_load_string($testPageRecord['tx_templavoila_flex']);
     $fieldContent_xpathResArr = $flexform->xpath("//data/sheet[@index='sDEF']/language[@index='lDEF']/field[@index='field_content']/value[@index='vDEF']");
     $fieldRightBar_xpathResArr = $flexform->xpath("//data/sheet[@index='sDEF']/language[@index='lDEF']/field[@index='field_rightbar']/value[@index='vDEF']");
     $everythingIsFine = (string) $fieldContent_xpathResArr[0] === $elementUids[1] . ',' . $elementUids[3] . ',' . $elementUids[2] && (string) $fieldRightBar_xpathResArr[0] === $elementUids[4] . ',' . $elementUids[5] . ',' . $elementUids[6];
     self::assertTrue($everythingIsFine, 'The reference list is not as expected after moving the second element up and choosing the destination by the sorting field!');
 }