From 50ffa1b76e1ab8661933a05d1942463ef740f80f Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Wed, 15 Dec 2010 01:24:06 -0500
Subject: [PATCH] Basic CRUD tests for entities

- Basic CRUD tests for repository, branch, item revision, operation and
  tag entities.
- Add a way to add operations and item revisions on tests, asserting on
  them after creation.
---
 tests/VersioncontrolBackendTests.test              |    2 +
 tests/VersioncontrolBranchUnitTestingTestCase.test |  116 +++++++++++++++++
 tests/VersioncontrolItemUnitTestingTestCase.test   |  133 +++++++++++++++++++
 ...VersioncontrolOperationUnitTestingTestCase.test |  134 ++++++++++++++++++++
 ...ersioncontrolRepositoryUnitTestingTestCase.test |  113 +++++++++++++----
 tests/VersioncontrolTagUnitTestingTestCase.test    |  116 +++++++++++++++++
 tests/VersioncontrolTestCase.test                  |   83 ++++++++++++-
 7 files changed, 670 insertions(+), 27 deletions(-)
 create mode 100644 tests/VersioncontrolBranchUnitTestingTestCase.test
 create mode 100644 tests/VersioncontrolItemUnitTestingTestCase.test
 create mode 100644 tests/VersioncontrolOperationUnitTestingTestCase.test
 create mode 100644 tests/VersioncontrolTagUnitTestingTestCase.test

diff --git tests/VersioncontrolBackendTests.test tests/VersioncontrolBackendTests.test
index 20ed6e5..5d4e065 100644
--- tests/VersioncontrolBackendTests.test
+++ tests/VersioncontrolBackendTests.test
@@ -43,3 +43,5 @@ class VersioncontrolBackendBaseUnitTest extends VersioncontrolTestCase {
     }
   }
 }
+
+//TODO test backend methods on another test class with the test backend
diff --git tests/VersioncontrolBranchUnitTestingTestCase.test tests/VersioncontrolBranchUnitTestingTestCase.test
new file mode 100644
index 0000000..39db21c
--- /dev/null
+++ tests/VersioncontrolBranchUnitTestingTestCase.test
@@ -0,0 +1,116 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Unit tests for branch class.
+ */
+require_once drupal_get_path('module', 'versioncontrol') . '/tests/VersioncontrolTestCase.test';
+
+/**
+ * Unit tests for VersioncontrolBranch class.
+ */
+class VersioncontrolBranchUnitTestingTestCase extends VersioncontrolTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 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);
+      }
+      $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);
+      }
+      $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'));
+    }
+  }
+
+}
diff --git tests/VersioncontrolItemUnitTestingTestCase.test tests/VersioncontrolItemUnitTestingTestCase.test
new file mode 100644
index 0000000..55369a1
--- /dev/null
+++ tests/VersioncontrolItemUnitTestingTestCase.test
@@ -0,0 +1,133 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Unit tests for item class.
+ */
+require_once drupal_get_path('module', 'versioncontrol') . '/tests/VersioncontrolTestCase.test';
+
+/**
+ * Unit tests for VersioncontrolItem class.
+ */
+class VersioncontrolItemUnitTestingTestCase extends VersioncontrolTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('Item class unit tests'),
+      'description' => t('Unit tests for the VersioncontrolItem 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');
+    $operation = $this->versioncontrolCreateOperation('test');
+    $data = array(
+      'vc_op_id' => $operation->vc_op_id,
+      'path' => '/fake/path/to/file',
+      'revision' => $this->randomName(4),
+      'type' => VERSIONCONTROL_ITEM_FILE,
+      'source_item_revision_id' => 0,
+      'action' => VERSIONCONTROL_ACTION_ADDED,
+      'line_changes_added' => 10,
+      'line_changes_removed' => 0,
+      'repository' => $repo,
+    );
+    $item = $this->testBackend->buildEntity('item', $data);
+    $item->insert();
+
+    // Verify.
+    $db_item = db_select('versioncontrol_item_revisions', 'i')
+      ->fields('i')
+      ->condition('item_revision_id', $item->item_revision_id)
+      ->execute()
+      ->fetchObject();
+    foreach ($item as $key => $val) {
+      //TODO remove this when #319153 gets in
+      if ($key == 'deleted') {
+        continue;
+      }
+      $this->assertEqual($val, $db_item->$key, t('%key item attribute is stored correctly', array('%key' => $key)), t('Creation'));
+    }
+  }
+
+  public function testRead() {
+    $controller = new VersioncontrolItemController();
+    // no item, test we get valid output
+    $items = $controller->load(array(''));
+    $this->assertTrue(empty($items), t('Make sure we get an empty array when trying to get a item with empty item_revision_id'), t('Read'));
+
+    $items = $controller->load(NULL);
+    $this->assertTrue(empty($items), t('Make sure we get an empty array when trying to get a item with a NULL item_revision_id'), t('Read'));
+
+    $items = $controller->load(array(1));
+    $this->assertTrue(empty($items), t('Make sure we get an empty array when trying to get a item which do not exist'), t('Read'));
+
+    // create item and test again
+    $item = $this->versioncontrolCreateItem('test');
+    $db_items = $controller->load(array($item->item_revision_id));
+    $this->assertEqual(count($db_items), 1, t('Only one item found'), t('Read'));
+    $db_item = reset($db_items);
+    $this->assertTrue(isset($db_item) && is_a($db_item, 'VersioncontrolItem'), t('Make sure we get a valid return when passing a good item_revision_id.'), t('Read'));
+    $this->assertEqual($db_item->item_revision_id, $item->item_revision_id, t('Make sure we get the right item.'), t('Read'));
+  }
+
+  public function testUpdate() {
+    $item = $this->versioncontrolCreateItem('test');
+
+    $data = array(
+      'path' => '/fake/path/to/',
+      'revision' => $this->randomName(4),
+      'type' => VERSIONCONTROL_ITEM_DIRECTORY,
+      'source_item_revision_id' => 0,
+      'action' => VERSIONCONTROL_ACTION_ADDED,
+      'line_changes_added' => 0,
+      'line_changes_removed' => 0,
+    );
+
+    foreach ($data as $key => $value) {
+      $item->$key = $value;
+    }
+    $item->update();
+
+    $db_item = db_select('versioncontrol_item_revisions', 'i')
+      ->fields('i')
+      ->condition('item_revision_id', $item->item_revision_id)
+      ->execute()
+      ->fetchObject();
+    foreach ($item as $key => $val) {
+      //TODO remove this when #319153 gets in
+      if ($key == 'deleted') {
+        continue;
+      }
+      $this->assertEqual($val, $db_item->$key, t('%key item attribute is updated correctly', array('%key' => $key)), t('Update'));
+    }
+
+  }
+
+  public function testDelete() {
+    $item = $this->versioncontrolCreateItem('test');
+    $item->delete();
+
+    $result = db_select('versioncontrol_item_revisions', 'i')
+      ->fields('i')
+      ->condition('item_revision_id', $item->item_revision_id)
+      ->execute();
+    foreach ($result as $db_item) {
+      $this->fail(t('The item was not deleted correctly.'), t('Delete'));
+    }
+  }
+
+}
diff --git tests/VersioncontrolOperationUnitTestingTestCase.test tests/VersioncontrolOperationUnitTestingTestCase.test
new file mode 100644
index 0000000..b5a579e
--- /dev/null
+++ tests/VersioncontrolOperationUnitTestingTestCase.test
@@ -0,0 +1,134 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Unit tests for operation class.
+ */
+require_once drupal_get_path('module', 'versioncontrol') . '/tests/VersioncontrolTestCase.test';
+
+/**
+ * Unit tests for VersioncontrolOperation class.
+ */
+class VersioncontrolOperationUnitTestingTestCase extends VersioncontrolTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 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'));
+    }
+  }
+
+}
diff --git tests/VersioncontrolRepositoryUnitTestingTestCase.test tests/VersioncontrolRepositoryUnitTestingTestCase.test
index d1f222f..dc3d9f8 100644
--- tests/VersioncontrolRepositoryUnitTestingTestCase.test
+++ tests/VersioncontrolRepositoryUnitTestingTestCase.test
@@ -1,10 +1,10 @@
 <?php
 // $Id: VersioncontrolRepositoryUnitTestingTestCase.test,v 1.8 2010/12/14 20:34:39 marvil07 Exp $
-require_once drupal_get_path('module', 'versioncontrol') . '/tests/VersioncontrolTestCase.test';
 /**
  * @file
- * Unit tests for repository class
+ * Unit tests for repository class.
  */
+require_once drupal_get_path('module', 'versioncontrol') . '/tests/VersioncontrolTestCase.test';
 
 /**
  * Unit tests for VersioncontrolRepository class
@@ -16,7 +16,6 @@ class VersioncontrolRepositoryUnitTestingTestCase extends VersioncontrolTestCase
    */
   public static function getInfo() {
     return array(
-      // FIXME
       'name' => t('Repository class unit tests'),
       'description' => t('Unit tests for the VersioncontrolRepository class.'),
       'group' => t('Version Control API'),
@@ -31,30 +30,100 @@ class VersioncontrolRepositoryUnitTestingTestCase extends VersioncontrolTestCase
     parent::setUp();
   }
 
-  public function testBadLoadParams() {
-    $repository = $this->testBackend->loadEntities('repo', array(''));
-    $this->assertTrue(empty($repository), t('Make sure we get an empty array when trying to get a repository with empty repo_id'), 'controller');
+  public function testCreation() {
+    // Build and insert.
+    $data = array(
+      'name' => $this->randomName(),
+      'root' => '/fake/path/to/repo',
+      'update_method' => 0,
+      'updated' => 0,
+      'locked' => 0,
+      'data' => array(),
+      'plugins' => array('auth_handler' => 'ffa', 'author_mapper' => 'simple_name', 'committer_mapper' => 'simple_mail'),
+    );
+    $repo = $this->testBackend->buildEntity('repo', $data);
+    $repo->insert();
+
+    // Verify.
+    $db_repo = db_select('versioncontrol_repositories', 'r')
+      ->fields('r')
+      ->condition('repo_id', $repo->repo_id)
+      ->execute()
+      ->fetchObject();
+    foreach ($data as $key => $val) {
+      if ($key == 'data' || $key == 'plugins') {
+        $db_repo->$key = unserialize($db_repo->$key);
+      }
+      $this->assertEqual($val, $db_repo->$key, t('%key repository attribute is stored correctly', array('%key' => $key)), t('Creation'));
+    }
+  }
+
+  public function testRead() {
+    $controller = new VersioncontrolRepositoryController();
+    // no repo, test we get valid output
+    $repositories = $controller->load(array(''));
+    $this->assertTrue(empty($repositories), t('Make sure we get an empty array when trying to get a repository with empty repo_id'), t('Read'));
+
+    $repositories = $controller->load(NULL);
+    $this->assertTrue(empty($repositories), t('Make sure we get an empty array when trying to get a repository with a NULL repo_id'), t('Read'));
 
-    $repository = $this->testBackend->loadEntities('repo', NULL);
-    $this->assertTrue(empty($repository), t('Make sure we get an empty array when trying to get a repository with a NULL repo_id'), 'controller');
+    $repositories = $controller->load(array(1));
+    $this->assertTrue(empty($repositories), t('Make sure we get an empty array when trying to get a repository which do not exit'), t('Read'));
 
-    $repository = $this->testBackend->loadEntities('repo', array(1));
-    $this->assertTrue(empty($repository), t('Make sure we get an empty array when trying to get a repository which do not exit'), 'controller');
+    // create repo and test again
+    $repo = $this->versioncontrolCreateRepository('test');
+    $repositories = $controller->load(array($repo->repo_id));
+    $this->assertEqual(count($repositories), 1, t('Only one repository found'), t('Read'));
+    $repository = reset($repositories);
+    $this->assertTrue(isset($repository) && is_a($repository, 'VersioncontrolRepository'), t('Make sure we get a valid return when passing a good repo_id.'), t('Read'));
+    $this->assertEqual($repository->repo_id, $repo->repo_id, t('Make sure we get the right repository.'), t('Read'));
   }
 
-  public function testRepositoryLoadParams() {
-    $name = $this->randomName();
+  public function testUpdate() {
+    $repo = $this->versioncontrolCreateRepository('test');
+
     $data = array(
-      'name' => $name,
-      'vcs' => 'test',
-      'backend' => $this->testBackend,
-      'root' => '/fake/path/to/repo',
+      'name' => $this->randomName(),
+      'root' => '/updated/path',
+      'updated' => time(),
+      //TODO $repo->update_method
+      'locked' => TRUE,
+      'plugins' => array('auth_handler' => 'account') + $repo['plugins'],
     );
-    $repo = $this->testBackend->buildEntity('repo', $data);
-    $repo->insert();
-    $this->assertTrue(isset($repo->repo_id) && is_numeric($repo->repo_id), t('VersioncontrolRepository::insert() properly populates a new repository object with an integer repo_id.'));
-    $repositories = $this->testBackend->loadEntities('repo', array($repo->repo_id));
-    $this->assertTrue(isset($repositories[$repo->repo_id]) && is_a($repositories[$repo->repo_id], 'VersioncontrolRepository'), t('Make sure we get a valid return when passing a good repo_id.'));
-    $this->assertEqual($repositories[$repo->repo_id]->repo_id, $repo->repo_id, t('Make sure we get the right repository.'), 'controller');
+
+    $repo->name = $data['name'];
+    $repo->root = $data['root'];
+    $repo->updated = $data['updated'];
+    //TODO $repo->update_method
+    $repo->locked = $data['locked'];
+    $repo->plugins = $data['plugins'];
+    $repo->update();
+
+    $db_repo = db_select('versioncontrol_repositories', 'r')
+      ->fields('r')
+      ->condition('repo_id', $repo->repo_id)
+      ->execute()
+      ->fetchObject();
+    foreach ($data as $key => $val) {
+      if ($key == 'data' || $key == 'plugins') {
+        $db_repo->$key = unserialize($db_repo->$key);
+      }
+      $this->assertEqual($val, $db_repo->$key, t('%key repository attribute is updated correctly', array('%key' => $key)), t('Update'));
+    }
+
   }
+
+  public function testDelete() {
+    $repo = $this->versioncontrolCreateRepository('test');
+    $repo->delete();
+
+    $result = db_select('versioncontrol_repositories', 'r')
+      ->fields('r')
+      ->condition('repo_id', $repo->repo_id)
+      ->execute();
+    foreach ($result as $db_repo) {
+      $this->fail(t('The repository was not deleted correctly.'), t('Delete'));
+    }
+  }
+
 }
diff --git tests/VersioncontrolTagUnitTestingTestCase.test tests/VersioncontrolTagUnitTestingTestCase.test
new file mode 100644
index 0000000..745c8b3
--- /dev/null
+++ tests/VersioncontrolTagUnitTestingTestCase.test
@@ -0,0 +1,116 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Unit tests for tag class.
+ */
+require_once drupal_get_path('module', 'versioncontrol') . '/tests/VersioncontrolTestCase.test';
+
+/**
+ * Unit tests for VersioncontrolTag class.
+ */
+class VersioncontrolTagUnitTestingTestCase extends VersioncontrolTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('Tag class unit tests'),
+      'description' => t('Unit tests for the VersioncontrolTag 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(),
+    );
+    $tag = $this->testBackend->buildEntity('tag', $data);
+    $tag->insert();
+
+    // Verify.
+    $db_tag = db_select('versioncontrol_labels', 'l')
+      ->fields('l')
+      ->condition('label_id', $tag->label_id)
+      ->execute()
+      ->fetchObject();
+    foreach ($tag as $key => $val) {
+      if ($key == 'data') {
+        $db_tag->$key = unserialize($db_tag->$key);
+      }
+      $this->assertEqual($val, $db_tag->$key, t('%key tag attribute is stored correctly', array('%key' => $key)), t('Creation'));
+    }
+  }
+
+  public function testRead() {
+    $controller = new VersioncontrolTagController();
+    // no tag, test we get valid output
+    $tags = $controller->load(array(''));
+    $this->assertTrue(empty($tags), t('Make sure we get an empty array when trying to get a tag with empty label_id'), t('Read'));
+
+    $tags = $controller->load(NULL);
+    $this->assertTrue(empty($tags), t('Make sure we get an empty array when trying to get a tag with a NULL label_id'), t('Read'));
+
+    $tags = $controller->load(array(1));
+    $this->assertTrue(empty($tags), t('Make sure we get an empty array when trying to get a tag which do not exist'), t('Read'));
+
+    // create tag and test again
+    $tag = $this->versioncontrolCreateTag('test');
+    $db_tags = $controller->load(array($tag->label_id));
+    $this->assertEqual(count($db_tags), 1, t('Only one tag found'), t('Read'));
+    $db_tag = reset($db_tags);
+    $this->assertTrue(isset($db_tag) && is_a($db_tag, 'VersioncontrolTag'), t('Make sure we get a valid return when passing a good label_id.'), t('Read'));
+    $this->assertEqual($db_tag->label_id, $tag->label_id, t('Make sure we get the right tag.'), t('Read'));
+  }
+
+  public function testUpdate() {
+    $tag = $this->versioncontrolCreateTag('test');
+
+    $data = array(
+      'name' => $this->randomName(),
+    );
+
+    $tag->name = $data['name'];
+    $tag->update();
+
+    $db_tag = db_select('versioncontrol_labels', 'l')
+      ->fields('l')
+      ->condition('label_id', $tag->label_id)
+      ->execute()
+      ->fetchObject();
+    foreach ($tag as $key => $val) {
+      if ($key == 'data') {
+        $db_tag->$key = unserialize($db_tag->$key);
+      }
+      $this->assertEqual($val, $db_tag->$key, t('%key tag attribute is updated correctly', array('%key' => $key)), t('Update'));
+    }
+
+  }
+
+  public function testDelete() {
+    $tag = $this->versioncontrolCreateTag('test');
+    $tag->delete();
+
+    $result = db_select('versioncontrol_labels', 'l')
+      ->fields('l')
+      ->condition('label_id', $tag->label_id)
+      ->execute();
+    foreach ($result as $db_tag) {
+      $this->fail(t('The tag was not deleted correctly.'), t('Delete'));
+    }
+  }
+
+}
diff --git tests/VersioncontrolTestCase.test tests/VersioncontrolTestCase.test
index 7eba0cc..8d409e6 100644
--- tests/VersioncontrolTestCase.test
+++ tests/VersioncontrolTestCase.test
@@ -138,14 +138,17 @@ abstract class VersioncontrolTestCase extends DrupalWebTestCase {
       'name' => 'test_repo_' . ++$i,
       'vcs' => $backend_name,
       'root' => '/fake/path/to/repo',
-      'update_method' => 0,
+      'authorization_method' => 'versioncontrol_admin',
       'updated' => 0,
+      'update_method' => 0,
       'locked' => 0,
       'data' => array(),
       'plugins' => array(),
     );
     $default_plugins = array(
       'auth_handler' => 'ffa',
+      'author_mapper' => 'simple_mail',
+      'committer_mapper' => 'simple_mail',
     );
 
     $data += $default_data;
@@ -157,6 +160,7 @@ abstract class VersioncontrolTestCase extends DrupalWebTestCase {
     $backend = $this->backends[$backend_name];
     $repo = $backend->buildEntity('repo', $data);
     $repo->insert();
+    $this->assertTrue(isset($repo->repo_id) && is_numeric($repo->repo_id), t('VersioncontrolRepository::insert() properly populates a new repository object with an integer repo_id.'));
 
     return $repo;
   }
@@ -164,13 +168,16 @@ abstract class VersioncontrolTestCase extends DrupalWebTestCase {
   public function versioncontrolCreateLabel($type, $backend_name = 'test', $data = array()) {
     $default_data = array(
       'name' => $this->randomName(32),
+      'data' => array(),
     );
     $data += $default_data;
 
     $backend = $this->backends[$backend_name];
     if (!isset($data['repo_id'])) {
-      $repo = $this->versioncontrolCreateRepository($backend_name);
-      $data['repo_id'] = $repo->repo_id;
+      if (!isset($data['repository']) || !is_subclass_of($data['repository'], 'VersioncontrolRepository')) {
+        $repo = $this->versioncontrolCreateRepository($backend_name);
+        $data['repo_id'] = $repo->repo_id;
+      }
     }
     $label = $backend->buildEntity($type, $data);
     $label->insert();
@@ -179,11 +186,77 @@ abstract class VersioncontrolTestCase extends DrupalWebTestCase {
   }
 
   public function versioncontrolCreateBranch($backend_name = 'test', $data = array()) {
-    return $this->versioncontrolCreateLabel('branch', $backend_name, $data);
+    $label = $this->versioncontrolCreateLabel('branch', $backend_name, $data);
+    $this->assertTrue(isset($label->label_id) && is_numeric($label->label_id), t('VersioncontrolBranch::insert() properly populates a new repository object with an integer label_id.'));
+    return $label;
   }
 
   public function versioncontrolCreateTag($backend_name = 'test', $data = array()) {
-    return $this->versioncontrolCreateLabel('tag', $backend_name, $data);
+    $label = $this->versioncontrolCreateLabel('tag', $backend_name, $data);
+    $this->assertTrue(isset($label->label_id) && is_numeric($label->label_id), t('VersioncontrolTag::insert() properly populates a new repository object with an integer label_id.'));
+    return $label;
+  }
+
+  public function versioncontrolCreateOperation($backend_name = 'test', $data = array()) {
+    static $i = 0;
+    $name = $this->randomName(7);
+    $default_data = array(
+      'type' => VERSIONCONTROL_OPERATION_COMMIT,
+      'date' => time(),
+      'author' => $name,
+      'author_uid' => 0,
+      'committer' => $name,
+      'committer_uid' => 0,
+      'revision' => ++$i,
+      'message' => $this->randomString(20),
+      'labels' => array(),
+      'itemRevisions' => array(),
+    );
+    $data += $default_data;
+
+    $backend = $this->backends[$backend_name];
+    if (!isset($data['repo_id'])) {
+      if (!isset($data['repository']) || !is_subclass_of($data['repository'], 'VersioncontrolRepository')) {
+        $repo = $this->versioncontrolCreateRepository($backend_name);
+        $data['repo_id'] = $repo->repo_id;
+      }
+    }
+    $operation = $backend->buildEntity('operation', $data);
+    $operation->insert();
+    $this->assertTrue(isset($operation->vc_op_id) && is_numeric($operation->vc_op_id), t('VersioncontrolOperation::insert() properly populates a new repository object with an integer vc_op_id.'));
+
+    return $operation;
+  }
+
+  public function versioncontrolCreateItem($backend_name = 'test', $data = array()) {
+    static $i = 0;
+    $default_data = array(
+      'path' => sprintf('/%s/%s.inc', $this->randomName(4), $this->randomName(4)),
+      'revision' => ++$i,
+      'type' => VERSIONCONTROL_ITEM_FILE,
+      'source_item_revision_id' => 0,
+      'action' => VERSIONCONTROL_ACTION_ADDED,
+      'line_changes_added' => 0,
+      'line_changes_removed' => 0,
+    );
+    $data += $default_data;
+
+    $backend = $this->backends[$backend_name];
+    if (!isset($data['repo_id'])) {
+      if (!isset($data['repository']) || !is_subclass_of($data['repository'], 'VersioncontrolRepository')) {
+        $repo = $this->versioncontrolCreateRepository($backend_name);
+        $data['repo_id'] = $repo->repo_id;
+      }
+    }
+    if (!isset($data['vc_op_id'])) {
+      $operation = $this->versioncontrolCreateOperation('test', array('repo_id' => $data['repo_id']));
+      $data['vc_op_id'] = $operation->vc_op_id;
+    }
+    $item = $backend->buildEntity('item', $data);
+    $item->insert();
+    $this->assertTrue(isset($item->item_revision_id) && is_numeric($item->item_revision_id), t('VersioncontrolItem::insert() properly populates a new repository object with an integer item_revision_id.'));
+
+    return $item;
   }
 
 }
-- 
1.7.2.3

