first commit
This commit is contained in:
		
							
								
								
									
										29
									
								
								tests/Integration/AppTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tests/Integration/AppTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace OCA\MyWiki\Tests\Integration\Controller;
 | 
			
		||||
 | 
			
		||||
use OCP\AppFramework\App;
 | 
			
		||||
use Test\TestCase;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This test shows how to make a small Integration Test. Query your class
 | 
			
		||||
 * directly from the container, only pass in mocks if needed and run your tests
 | 
			
		||||
 * against the database
 | 
			
		||||
 */
 | 
			
		||||
class AppTest extends TestCase {
 | 
			
		||||
 | 
			
		||||
    private $container;
 | 
			
		||||
 | 
			
		||||
	protected function setUp(): void {
 | 
			
		||||
        parent::setUp();
 | 
			
		||||
        $app = new App('mywiki');
 | 
			
		||||
        $this->container = $app->getContainer();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAppInstalled() {
 | 
			
		||||
        $appManager = $this->container->query('OCP\App\IAppManager');
 | 
			
		||||
        $this->assertTrue($appManager->isInstalled('mywiki'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										72
									
								
								tests/Integration/MyWikiIntegrationTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								tests/Integration/MyWikiIntegrationTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,72 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace OCA\MyWiki\Tests\Integration\Controller;
 | 
			
		||||
 | 
			
		||||
use OCP\AppFramework\Http\DataResponse;
 | 
			
		||||
use OCP\AppFramework\App;
 | 
			
		||||
use Test\TestCase;
 | 
			
		||||
 | 
			
		||||
use OCA\MyWiki\Db\Wiki;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @group DB
 | 
			
		||||
 */
 | 
			
		||||
class MyWikiIntegrationTest extends TestCase {
 | 
			
		||||
 | 
			
		||||
    private $controller;
 | 
			
		||||
    private $mapper;
 | 
			
		||||
    private $userId = 'john';
 | 
			
		||||
 | 
			
		||||
	protected function setUp(): void {
 | 
			
		||||
        parent::setUp();
 | 
			
		||||
        $app = new App('mywiki');
 | 
			
		||||
        $container = $app->getContainer();
 | 
			
		||||
 | 
			
		||||
        // only replace the user id
 | 
			
		||||
        $container->registerService('UserId', function($c) {
 | 
			
		||||
            return $this->userId;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->controller = $container->query(
 | 
			
		||||
            'OCA\MyWiki\Controller\WikiController'
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->mapper = $container->query(
 | 
			
		||||
            'OCA\MyWiki\Db\WikiMapper'
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function e($x) { echo "\n>>>$x<<<"; }
 | 
			
		||||
 | 
			
		||||
    public function testJDG() {
 | 
			
		||||
 | 
			
		||||
        $x = \OC\Files\Filesystem::getLocalFolder('\\');
 | 
			
		||||
 | 
			
		||||
        $this->e(print_r($x,true));
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    public function testUpdate() {
 | 
			
		||||
        // create a new note that should be updated
 | 
			
		||||
        $wiki = new Wiki();
 | 
			
		||||
        $wiki->setTitle('old_title');
 | 
			
		||||
        $wiki->setFileId(4321);
 | 
			
		||||
        $wiki->setUserId($this->userId);
 | 
			
		||||
 | 
			
		||||
        $id = $this->mapper->insert($wiki)->getId();
 | 
			
		||||
 | 
			
		||||
        // fromRow does not set the fields as updated
 | 
			
		||||
        $updatedWiki = Wiki::fromRow([
 | 
			
		||||
            'id' => $id,
 | 
			
		||||
            'user_id' => $this->userId
 | 
			
		||||
        ]);
 | 
			
		||||
        $updatedWiki->setTitle('title');
 | 
			
		||||
        $updatedWiki->setFileId(1234);
 | 
			
		||||
 | 
			
		||||
        $result = $this->controller->update($id, 'title', 'file_id');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($updatedWiki, $result->getData());
 | 
			
		||||
 | 
			
		||||
        // clean up
 | 
			
		||||
        $this->mapper->delete($result->getData());
 | 
			
		||||
    }
 | 
			
		||||
*/
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								tests/Unit/Controller/PageControllerTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								tests/Unit/Controller/PageControllerTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace OCA\MyWiki\Tests\Unit\Controller;
 | 
			
		||||
 | 
			
		||||
use PHPUnit_Framework_TestCase;
 | 
			
		||||
 | 
			
		||||
use OCP\AppFramework\Http\TemplateResponse;
 | 
			
		||||
 | 
			
		||||
use OCA\MyWiki\Controller\PageController;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PageControllerTest extends PHPUnit_Framework_TestCase {
 | 
			
		||||
	private $controller;
 | 
			
		||||
	private $userId = 'john';
 | 
			
		||||
 | 
			
		||||
	public function setUp() {
 | 
			
		||||
		$request = $this->getMockBuilder('OCP\IRequest')->getMock();
 | 
			
		||||
 | 
			
		||||
		$this->controller = new PageController(
 | 
			
		||||
			'mywiki', $request, $this->userId
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function testIndex() {
 | 
			
		||||
		$result = $this->controller->index();
 | 
			
		||||
 | 
			
		||||
		$this->assertEquals('index', $result->getTemplateName());
 | 
			
		||||
		$this->assertTrue($result instanceof TemplateResponse);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								tests/bootstrap.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/bootstrap.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
if (!defined('PHPUNIT_RUN')) {
 | 
			
		||||
    define('PHPUNIT_RUN', 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
require_once __DIR__.'/../../../lib/base.php';
 | 
			
		||||
 | 
			
		||||
// Fix for "Autoload path not allowed: .../tests/lib/testcase.php"
 | 
			
		||||
\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests');
 | 
			
		||||
 | 
			
		||||
// Fix for "Autoload path not allowed: .../mywiki/tests/testcase.php"
 | 
			
		||||
\OC_App::loadApp('mywiki');
 | 
			
		||||
 | 
			
		||||
if(!class_exists('PHPUnit_Framework_TestCase')) {
 | 
			
		||||
    require_once('PHPUnit/Autoload.php');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
OC_Hook::clear();
 | 
			
		||||
		Reference in New Issue
	
	Block a user