public function testSaveVersions() { $versions = array(array('TestVersionTestOrganiser' => array('name' => 'Mr. Badger', Meshing_Database_Utils::COL_DECLARE_TOKEN => 'mr_badger'), 'TestVersionTestEvent' => array('name' => 'Expert Tunnelling In The Built Environment', 'description' => 'A fascinating presentation on how the modern badger can use human methods of construction for a long-lasting sett', 'location' => 'Birmingham Town Hall', 'nearest_city' => 'Birmingham, UK', 'start_time' => '2011-11-02 19:30:00', 'duration_mins' => 60, Meshing_Database_Utils::COL_FOREIGN_CLASS => 'TestVersionTestOrganiser', Meshing_Database_Utils::COL_FOREIGN_TOKEN => 'mr_badger', Meshing_Database_Utils::COL_DECLARE_TOKEN => 'daft_event')), array('TestVersionTestOrganiser' => array('email' => '*****@*****.**', Meshing_Database_Utils::COL_VERSION_TOKEN => 'mr_badger')), array('TestVersionTestOrganiser' => array('name' => 'Mr. Brian Furry', 'email' => '*****@*****.**', Meshing_Database_Utils::COL_VERSION_TOKEN => 'mr_badger'))); // Write this block of data $dbUtils = new Meshing_Database_Utils(); $ok = $dbUtils->writeVersionableData($versions, $this->node, $this->conNode); $this->assertTrue($ok, 'Write versionable data to the database'); /* * @var $organiser TestVersionTestOrganiser * @var $event TestVersionTestEvent */ $organiser = $dbUtils->getCachedObject('mr_badger'); $event = $dbUtils->getCachedObject('daft_event'); // Check the expected number of versions $this->assertEqual($event->countVersions($this->conNode), 1); $this->assertEqual($organiser->countVersions($this->conNode), 3); // Do some new/old counts from the peer $count = MeshingBasePeer::countNewVersions($event->getPrimaryKey(), $this->conNode, 'TestVersionTestEvent'); $this->assertEqual($count, 1, 'Checking counts of version rows are OK'); $count = MeshingBasePeer::countOldVersions($organiser->getPrimaryKey(), $this->conNode, 'TestVersionTestOrganiser'); $this->assertEqual($count, 2, 'Checking counts of version rows are OK'); // Check all versions have a timestamp $count1 = TestVersionTestEventVersionableQuery::create()->filterByTimeApplied(null, Criteria::ISNULL)->count($this->conNode); $count2 = TestVersionTestOrganiserVersionableQuery::create()->filterByTimeApplied(null, Criteria::ISNULL)->count($this->conNode); $this->assertTrue($count1 == 0 && $count2 == 0, 'Checking all versions have a timestamp'); // Check that the event has a non-null hash $this->assertNotNull($event->getHash($this->conNode), 'Check row hash is not null'); // Check that some previous versions have the correct old values $this->assertEqual($organiser->getNumberedVersion(1, $this->conNode)->getName(), 'Mr. Badger'); $this->assertEqual($organiser->getNumberedVersion(2, $this->conNode)->getName(), 'Mr. Badger'); $this->assertEqual($organiser->getNumberedVersion(3, $this->conNode)->getEmail(), '*****@*****.**'); $this->assertEqual($organiser->getNumberedVersion(2, $this->conNode)->getEmail(), '*****@*****.**'); }
/** * Testing syncing node 1 containing a few rows with node 2, which is empty */ public function testSimpleSync1() { // Set up data in node 1 $fixtures = $this->projectRoot . Meshing_Utils::getPaths()->getFixturesPath(); $data = (require_once $fixtures . '/simpleSync1.php'); $dbUtils = new Meshing_Database_Utils(); $dbUtils->writeVersionableData($data, $this->node1, $this->conNode); // @todo Sync data into node 2 here :) }