From 4c5e27bc13ce1f5132bd14af3c77bde758ae3a24 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 5 Nov 2014 15:23:59 +0100 Subject: first integration test --- tests/integration/bootstrap.php | 46 +++++++++++++++++++++++++++++++++ tests/integration/db/ItemMapperTest.php | 34 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/integration/bootstrap.php create mode 100644 tests/integration/db/ItemMapperTest.php (limited to 'tests') diff --git a/tests/integration/bootstrap.php b/tests/integration/bootstrap.php new file mode 100644 index 000000000..b57e14e58 --- /dev/null +++ b/tests/integration/bootstrap.php @@ -0,0 +1,46 @@ +getDb(); + $sql = [ + 'DELETE FROM *PREFIX*news_items WHERE feed_id IN ' . + '(SELECT id FROM *PREFIX*news_feeds WHERE user_id = ?)', + 'DELETE FROM *PREFIX*news_feeds WHERE user_id = ?', + 'DELETE FROM *PREFIX*news_folders WHERE user_id = ?' + ]; + + foreach ($sql as $query) { + $db->prepareQuery($query)->execute($user); + } + } + + + protected function setupUser($user='test') { + $userManager = \OC::$server->getUserManager(); + + if ($userManager->userExists($user)) { + $userManager->delete($user); + } + + $userManager->createUser('test', 'test'); + + $session = \OC::$server->getUserSession(); + $session->setUser($userManager->get($user)); + } + + + protected function setUp($user='test') { + $this->setupUser($user); + $this->setupNewsDatabase($user); + } + + +} \ No newline at end of file diff --git a/tests/integration/db/ItemMapperTest.php b/tests/integration/db/ItemMapperTest.php new file mode 100644 index 000000000..d0013f631 --- /dev/null +++ b/tests/integration/db/ItemMapperTest.php @@ -0,0 +1,34 @@ +container = $app->getContainer(); + $this->itemMapper = $this->container->query('ItemMapper'); + } + + + public function testInsert() { + $item = new Item(); + $item->setTitle('my title'); + + $created = $this->itemMapper->insert($item); + + $fetched = $this->itemMapper->find($created->getId(), $this->userId); + + $this->assertEquals($item->getTitle(), $fetched->getTitle()); + } + +} \ No newline at end of file -- cgit v1.2.3