Skip to content

Commit

Permalink
Updated tests env
Browse files Browse the repository at this point in the history
  • Loading branch information
eldadfux committed Sep 14, 2019
1 parent ddaa9c5 commit 1a73e19
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -15,8 +15,9 @@ services:
- docker

before_install:
- composer update --ignore-platform-reqs --optimize-autoloader --no-dev --no-plugins --no-scripts
- composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts
- sudo service mysql stop
- cp -r tests/resources/mock/db tests/resources/storage/db

install:
- docker-compose -f tests/resources/docker-compose.yml up -d
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Expand Up @@ -22,6 +22,9 @@
"Template\\": "src/Template"
}
},
"autoload-dev": {
"psr-4": {"Tests\\E2E\\": "tests/e2e"}
},
"require": {
"php": ">=7.3.0",
"ext-curl": "*",
Expand All @@ -37,6 +40,7 @@

"appwrite/sdk-generator": "master",
"appwrite/php-clamav": "master",
"appwrite/appwrite": "master",

"utopia-php/framework": "master",
"utopia-php/abuse": "master",
Expand Down
37 changes: 36 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpunit.xml
Expand Up @@ -10,7 +10,7 @@
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
<directory>./tests/e2e/</directory>
</testsuite>
</testsuites>
</phpunit>
110 changes: 110 additions & 0 deletions tests/e2e/ViewTest.php
@@ -0,0 +1,110 @@
<?php
/**
* Utopia PHP Framework
*
* @package Framework
* @subpackage Tests
*
* @link https://github.com/utopia-php/framework
* @author Eldad Fux <eldad@appwrite.io>
* @version 1.0 RC4
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/

namespace Tests\E2E;

use PHPUnit\Framework\TestCase;

class ViewTest extends TestCase
{
/**
* @var View
*/
protected $view = null;

public function setUp()
{
$this->view = new View(__DIR__ . '/mocks/View/template.phtml');
}

public function tearDown()
{
$this->view = null;
}

public function testSetParam()
{
$value = $this->view->setParam('key', 'value');

// Assertions
$this->assertInstanceOf('Utopia\View', $value);
}

public function testGetParam()
{
$this->view->setParam('key', 'value');

// Assertions
$this->assertEquals('value', $this->view->getParam('key', 'default'));
$this->assertEquals('default', $this->view->getParam('fake', 'default'));
}

public function testSetPath()
{
$value = $this->view->setPath('mocks/View/fake.phtml');

// Assertions
$this->assertInstanceOf('Utopia\View', $value);
}

public function testSetRendered()
{
$this->view->setRendered();

// Assertions
$this->assertEquals(true, $this->view->isRendered());
}

public function testIsRendered()
{
// Assertions
$this->view->setRendered(false);
$this->assertEquals(false, $this->view->isRendered());

// Assertions
$this->view->setRendered(true);
$this->assertEquals(true, $this->view->isRendered());
}

public function testRender()
{
// Assertions
$this->assertEquals('<div>Test template mock</div>', $this->view->render());

$this->view->setRendered();
$this->assertEquals('', $this->view->render());

try {
$this->view->setRendered(false);
$this->view->setPath('just-a-broken-string.phtml');
$this->view->render();
}
catch(\Exception $e) {
return;
}

$this->fail('An expected exception has not been raised.');
}

public function testEscape()
{
// Assertions
$this->assertEquals('&amp;&quot;', $this->view->print('&"', View::FILTER_ESCAPE));
}

public function testNl2p()
{
// Assertions
$this->assertEquals('<p>line1</p><p>line2</p>', $this->view->print("line1\n\nline2", View::FILTER_NL2P));
}
}
6 changes: 4 additions & 2 deletions tests/resources/docker-compose.yml
Expand Up @@ -5,6 +5,8 @@ services:
build: ../../
restart: unless-stopped
volumes:
- ./../../:/usr/share/nginx/html
- ./../../docker/nginx.conf:/etc/nginx/nginx.conf:rw
- ./storage:/storage:rw
ports:
- "80:80"
Expand All @@ -29,8 +31,8 @@ services:
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=password
#volumes:
#- ./storage/db:/var/lib/mysql:rw
volumes:
- ./storage/db:/var/lib/mysql:rw
ports:
- 3306:3306/tcp

Expand Down

0 comments on commit 1a73e19

Please sign in to comment.