t('Branch class unit tests'), 'description' => t('Unit tests for the VersioncontrolBranch class.'), 'group' => t('Version Control API'), ); } /** * Implementation of setUp(). */ function setUp() { $this->useBackends = self::BACKENDS_TEST; parent::setUp(); } public function testCreation() { // Build and insert. $repo = $this->versioncontrolCreateRepository('test'); $data = array( 'name' => $this->randomName(), 'repository' => $repo, 'data' => array(), ); $branch = $this->testBackend->buildEntity('branch', $data); $branch->insert(); // Verify. $db_branch = db_select('versioncontrol_labels', 'l') ->fields('l') ->condition('label_id', $branch->label_id) ->execute() ->fetchObject(); foreach ($branch as $key => $val) { if ($key == 'data') { $db_branch->$key = unserialize($db_branch->$key); } //TODO remove this when #998684 gets in if ($key == 'action') { continue; } $this->assertEqual($val, $db_branch->$key, t('%key branch attribute is stored correctly', array('%key' => $key)), t('Creation')); } } public function testRead() { $controller = new VersioncontrolBranchController(); // no branch, test we get valid output $branches = $controller->load(array('')); $this->assertTrue(empty($branches), t('Make sure we get an empty array when trying to get a branch with empty label_id'), t('Read')); $branches = $controller->load(NULL); $this->assertTrue(empty($branches), t('Make sure we get an empty array when trying to get a branch with a NULL label_id'), t('Read')); $branches = $controller->load(array(1)); $this->assertTrue(empty($branches), t('Make sure we get an empty array when trying to get a branch which do not exist'), t('Read')); // create branch and test again $branch = $this->versioncontrolCreateBranch('test'); $db_branches = $controller->load(array($branch->label_id)); $this->assertEqual(count($db_branches), 1, t('Only one branch found'), t('Read')); $db_branch = reset($db_branches); $this->assertTrue(isset($db_branch) && is_a($db_branch, 'VersioncontrolBranch'), t('Make sure we get a valid return when passing a good label_id.'), t('Read')); $this->assertEqual($db_branch->label_id, $branch->label_id, t('Make sure we get the right branch.'), t('Read')); } public function testUpdate() { $branch = $this->versioncontrolCreateBranch('test'); $data = array( 'name' => $this->randomName(), ); $branch->name = $data['name']; $branch->update(); $db_branch = db_select('versioncontrol_labels', 'l') ->fields('l') ->condition('label_id', $branch->label_id) ->execute() ->fetchObject(); foreach ($branch as $key => $val) { if ($key == 'data') { $db_branch->$key = unserialize($db_branch->$key); } //TODO remove this when #998684 gets in if ($key == 'action') { continue; } $this->assertEqual($val, $db_branch->$key, t('%key branch attribute is updated correctly', array('%key' => $key)), t('Update')); } } public function testDelete() { $branch = $this->versioncontrolCreateBranch('test'); $branch->delete(); $result = db_select('versioncontrol_labels', 'l') ->fields('l') ->condition('label_id', $branch->label_id) ->execute(); foreach ($result as $db_branch) { $this->fail(t('The branch was not deleted correctly.'), t('Delete')); } } }