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); } //TODO remove this when #998684 gets in if ($key == 'action') { continue; } $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); } //TODO remove this when #998684 gets in if ($key == 'action') { continue; } $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')); } } }