/** * Super mass update firstName and lastName for fixture records */ public function testSuperExecute() { X2List::model()->deleteAllByAttributes(array('name' => 'test')); $_SESSION = array(); $newList = new NewListFromSelection(); TestingAuxLib::suLogin('admin'); Yii::app()->user; // initializes $_SESSION superglobal Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null)); // perform super mass actions in batches, ensuring that after each batch, the id queue // in the session matches the remaining records to be updated $_POST['modelType'] = 'Contacts'; $_POST['listName'] = 'test'; $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['SERVER_NAME'] = 'localhost'; $idChecksum = SmartActiveDataProvider::calculateChecksumFromIds(Yii::app()->db->createCommand("\n SELECT id\n FROM x2_contacts\n ORDER BY lastUpdated DESC, id DESC\n ")->queryColumn()); $updated = 0; $uid = null; while (true) { $this->obStart(); $newList->superExecute($uid, 24, $idChecksum); $retVal = CJSON::decode(ob_get_contents()); $this->obEndClean(); $this->assertTrue(!isset($retVal['errorCode'])); $uid = $retVal['uid']; // get ids of contacts not in new list $remainingIds = Yii::app()->db->createCommand(' SELECT t.id FROM x2_contacts AS t WHERE t.id NOT IN ( SELECT contactId FROM x2_list_items AS t2 JOIN x2_lists AS t3 ON t3.id = t2.listId WHERE t.id = t2.contactId AND t3.name="test" ) ')->queryColumn(); $storedIds = $_SESSION[MassAction::SESSION_KEY_PREFIX . $uid]; sort($storedIds); $this->assertEquals($remainingIds, $storedIds); // new list from selection mass action should only ever get run on the first batch. // subsequent batches get added to the list (mass action swapping is handled // client-side) break; } }
/** * Test new list + add to list super mass actions */ public function testSuperExecute() { X2List::model()->deleteAllByAttributes(array('name' => 'test')); $_SESSION = array(); $newList = new NewListFromSelection(); $addToList = new MassAddToList(); TestingAuxLib::suLogin('admin'); Yii::app()->user; // initializes $_SESSION superglobal Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null)); $idChecksum = SmartActiveDataProvider::calculateChecksumFromIds(Yii::app()->db->createCommand("\n SELECT id\n FROM x2_contacts\n ORDER BY lastUpdated DESC, id DESC\n ")->queryColumn()); // perform super mass actions in batches, ensuring that after each batch, the id queue // in the session matches the remaining records to be updated. Call the new list from // selection mass action on the first batch and the mass add to list on all subsequent // batches to simulate behavior of grid view $_POST['modelType'] = 'Contacts'; $_POST['listName'] = 'test'; $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['SERVER_NAME'] = 'localhost'; $updated = 0; $uid = null; $listId = null; while (true) { ob_start(); if (!isset($listId)) { $newList->superExecute($uid, 24, $idChecksum); } else { $_POST['listId'] = $listId; $addToList->superExecute($uid, 24, $idChecksum); } $retVal = CJSON::decode(ob_get_contents()); ob_clean(); $this->assertTrue(!isset($retVal['errorCode'])); $uid = $retVal['uid']; if (isset($retVal['listId'])) { $listId = $retVal['listId']; } // get ids of contacts not in new list $remainingIds = Yii::app()->db->createCommand(' SELECT t.id FROM x2_contacts AS t WHERE t.id NOT IN ( SELECT contactId FROM x2_list_items AS t2 JOIN x2_lists AS t3 ON t3.id = t2.listId WHERE t.id = t2.contactId AND t3.name="test" ) ')->queryColumn(); if (isset($retVal['complete'])) { $this->assertEquals(0, count($remainingIds)); $this->assertTrue(!isset($_SESSION[MassAction::SESSION_KEY_PREFIX . $uid])); break; } else { $storedIds = $_SESSION[MassAction::SESSION_KEY_PREFIX . $uid]; sort($storedIds); $this->assertEquals($remainingIds, $storedIds); } } }