t('Operation class unit tests'), 'description' => t('Unit tests for the VersioncontrolOperation 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( 'type' => VERSIONCONTROL_OPERATION_COMMIT, 'date' => time(), 'author' => $this->randomName(7), 'author_uid' => 0, 'committer' => $this->randomName(7), 'committer_uid' => 0, 'revision' => $this->randomName(4), 'message' => $this->randomString(20), 'repository' => $repo, 'labels' => array(), 'itemRevisions' => array(), ); $operation = $this->testBackend->buildEntity('operation', $data); $operation->insert(); // Verify. $db_operation = db_select('versioncontrol_operations', 'o') ->fields('o') ->condition('vc_op_id', $operation->vc_op_id) ->execute() ->fetchObject(); foreach ($operation as $key => $val) { // labels and itemRevisions are not real DB fields if ($key == 'labels' || $key == 'itemRevisions') { continue; } $this->assertEqual($val, $db_operation->$key, t('%key operation attribute is stored correctly', array('%key' => $key)), t('Creation')); } } public function testRead() { $controller = new VersioncontrolOperationController(); // no operation, test we get valid output $operations = $controller->load(array('')); $this->assertTrue(empty($operations), t('Make sure we get an empty array when trying to get a operation with empty vc_op_id'), t('Read')); $operations = $controller->load(NULL); $this->assertTrue(empty($operations), t('Make sure we get an empty array when trying to get a operation with a NULL vc_op_id'), t('Read')); $operations = $controller->load(array(1)); $this->assertTrue(empty($operations), t('Make sure we get an empty array when trying to get a operation which do not exit'), t('Read')); // create operation and test again $operation = $this->versioncontrolCreateOperation('test'); $db_operations = $controller->load(array($operation->vc_op_id)); $this->assertEqual(count($db_operations), 1, t('Only one operation found'), t('Read')); $db_operation = reset($db_operations); $this->assertTrue(isset($db_operation) && is_a($db_operation, 'VersioncontrolOperation'), t('Make sure we get a valid return when passing a good vc_op_id.'), t('Read')); $this->assertEqual($db_operation->vc_op_id, $operation->vc_op_id, t('Make sure we get the right operation.'), t('Read')); } public function testUpdate() { $operation = $this->versioncontrolCreateOperation('test'); $data = array( 'date' => time(), 'author' => $this->randomName(7), 'author_uid' => 0, 'committer' => $this->randomName(7), 'committer_uid' => 0, 'revision' => $this->randomName(4), 'message' => $this->randomString(20), ); foreach ($data as $key => $val) { $operation->$key = $val; } $operation->update(); $db_operation = db_select('versioncontrol_operations', 'o') ->fields('o') ->condition('vc_op_id', $operation->vc_op_id) ->execute() ->fetchObject(); foreach ($operation as $key => $val) { // labels and itemRevisions are not real DB fields if ($key == 'labels' || $key == 'itemRevisions') { continue; } $this->assertEqual($val, $db_operation->$key, t('%key operation attribute is updated correctly', array('%key' => $key)), t('Update')); } } public function testDelete() { $operation = $this->versioncontrolCreateOperation('test'); $operation->delete(); $result = db_select('versioncontrol_operations', 'o') ->fields('o') ->condition('vc_op_id', $operation->vc_op_id) ->execute(); foreach ($result as $db_operation) { $this->fail(t('The operation was not deleted correctly.'), t('Delete')); } } }