Esempio n. 1
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('system:register');
        $answers = ['y', '/import', '1'];
        $helper = $command->getHelper('question');
        $helper->setInputStream($this->getInputStream(implode("\n", $answers) . "\n"));
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName(), 'class' => 'Fusio\\Impl\\Tests\\Adapter\\TestAdapter']);
        $display = $commandTester->getDisplay();
        $this->assertRegExp('/Registration successful/', $display, $display);
        // check action class
        $actionId = $this->connection->fetchColumn('SELECT id FROM fusio_action_class WHERE class = :class', ['class' => 'Fusio\\Impl\\Tests\\Adapter\\Test\\VoidAction']);
        $this->assertEquals(4, $actionId);
        // check connection class
        $connectionId = $this->connection->fetchColumn('SELECT id FROM fusio_connection_class WHERE class = :class', ['class' => 'Fusio\\Impl\\Tests\\Adapter\\Test\\VoidConnection']);
        $this->assertEquals(3, $connectionId);
        // check connection
        $connection = $this->connection->fetchAssoc('SELECT id, class, config FROM fusio_connection WHERE name = :name', ['name' => 'Adapter-Connection']);
        $this->assertEquals(2, $connection['id']);
        $this->assertEquals('Fusio\\Impl\\Tests\\Adapter\\Test\\VoidConnection', $connection['class']);
        $this->assertEquals(69, strlen($connection['config']));
        // check schema
        $schema = $this->connection->fetchAssoc('SELECT id, source, cache FROM fusio_schema WHERE name = :name', ['name' => 'Adapter-Schema']);
        $source = <<<JSON
{
    "id": "http://fusio-project.org",
    "title": "process",
    "type": "object",
    "properties": {
        "logId": {
            "type": "integer"
        },
        "title": {
            "type": "string"
        },
        "content": {
            "type": "string"
        }
    }
}
JSON;
        $this->assertEquals(3, $schema['id']);
        $this->assertJsonStringEqualsJsonString($source, $schema['source']);
        $this->assertInstanceOf('PSX\\Schema\\Schema', unserialize($schema['cache']));
        // check action
        $action = $this->connection->fetchAssoc('SELECT id, class, config FROM fusio_action WHERE name = :name', ['name' => 'Void-Action']);
        $this->assertEquals(4, $action['id']);
        $this->assertEquals('Fusio\\Impl\\Tests\\Adapter\\Test\\VoidAction', $action['class']);
        $this->assertEquals(['foo' => 'bar', 'connection' => '2'], unserialize($action['config']));
        // check routes
        $route = $this->connection->fetchAssoc('SELECT id, status, methods, controller FROM fusio_routes WHERE path = :path', ['path' => '/import/void']);
        $this->assertEquals(62, $route['id']);
        $this->assertEquals(1, $route['status']);
        $this->assertEquals('GET|POST|PUT|DELETE', $route['methods']);
        $this->assertEquals('Fusio\\Impl\\Controller\\SchemaApiController', $route['controller']);
        // check methods
        $methods = $this->connection->fetchAll('SELECT routeId, method, version, status, active, public, request, response, action FROM fusio_routes_method WHERE routeId = :routeId', ['routeId' => $route['id']]);
        $this->assertEquals(1, count($methods));
        $this->assertEquals(['routeId' => 62, 'method' => 'GET', 'version' => 1, 'status' => Resource::STATUS_DEVELOPMENT, 'active' => 1, 'public' => 1, 'request' => 3, 'response' => 1, 'action' => 4], $methods[0]);
    }
Esempio n. 2
0
 protected function setUp()
 {
     if (!class_exists('MongoDB')) {
         $this->markTestSkipped('MongoDB extension not available');
     }
     if (!self::$hasConnection) {
         $this->markTestSkipped('MongoDB connection not available');
     }
     parent::setUp();
     try {
         $this->mongodb = Environment::getService('connector')->getConnection(3);
     } catch (MongoConnectionException $e) {
         self::$hasConnection = false;
         $this->markTestSkipped('MongoDB connection not available');
     }
     $this->collection = $this->mongodb->createCollection('app_news');
     $table = $this->getDataSet()->getTable('app_news');
     $columns = $table->getTableMetaData()->getColumns();
     for ($i = 0; $i < $table->getRowCount(); $i++) {
         $row = array();
         foreach ($columns as $name) {
             $row[$name] = $table->getValue($i, $name);
         }
         $this->collection->insert($row);
     }
 }
Esempio n. 3
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('schema:export');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName(), 'name' => 'Foo-Schema']);
        $actual = $commandTester->getDisplay();
        $expect = <<<'JSON'
{
    "$schema": "http:\/\/json-schema.org\/draft-04\/schema#",
    "id": "urn:schema.phpsx.org#",
    "definitions": {
        "ref11328c18443d238942720184135b4d00": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "title": {
                    "type": "string"
                },
                "content": {
                    "type": "string"
                },
                "date": {
                    "type": "string",
                    "format": "date-time"
                }
            },
            "additionalProperties": false
        }
    },
    "title": "test",
    "type": "object",
    "properties": {
        "totalResults": {
            "type": "integer"
        },
        "itemsPerPage": {
            "type": "integer"
        },
        "startIndex": {
            "type": "integer"
        },
        "entry": {
            "type": "array",
            "items": {
                "$ref": "#\/definitions\/ref11328c18443d238942720184135b4d00"
            }
        }
    },
    "additionalProperties": false
}
JSON;
        $this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
    }
Esempio n. 4
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('system:import');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName(), 'file' => __DIR__ . '/import.json']);
        $display = $commandTester->getDisplay();
        $this->assertRegExp('/Import successful!/', $display, $display);
        // check connection
        $connection = $this->connection->fetchAssoc('SELECT id, class, config FROM fusio_connection WHERE name = :name', ['name' => 'New-Connection']);
        $this->assertEquals(2, $connection['id']);
        $this->assertEquals('Fusio\\Adapter\\Sql\\Connection\\DBAL', $connection['class']);
        $this->assertEquals(177, strlen($connection['config']));
        // check schema
        $schema = $this->connection->fetchAssoc('SELECT id, source, cache FROM fusio_schema WHERE name = :name', ['name' => 'New-Schema']);
        $source = <<<JSON
{
    "id": "http://phpsx.org#",
    "title": "test",
    "type": "object",
    "properties": {
        "title": {
            "type": "string"
        },
        "content": {
            "type": "string"
        },
        "date": {
            "type": "string",
            "format": "date-time"
        }
    }
}
JSON;
        $this->assertEquals(3, $schema['id']);
        $this->assertJsonStringEqualsJsonString($source, $schema['source']);
        $this->assertInstanceOf('PSX\\Schema\\Schema', unserialize($schema['cache']));
        // check action
        $action = $this->connection->fetchAssoc('SELECT id, class, config FROM fusio_action WHERE name = :name', ['name' => 'Test-Action']);
        $this->assertEquals(4, $action['id']);
        $this->assertEquals('Fusio\\Adapter\\Util\\Action\\UtilStaticResponse', $action['class']);
        $this->assertEquals(['response' => '{"foo": "bar"}'], unserialize($action['config']));
        // check routes
        $route = $this->connection->fetchAssoc('SELECT id, status, methods, controller FROM fusio_routes WHERE path = :path', ['path' => '/bar']);
        $this->assertEquals(62, $route['id']);
        $this->assertEquals(1, $route['status']);
        $this->assertEquals('GET|POST|PUT|DELETE', $route['methods']);
        $this->assertEquals('Fusio\\Impl\\Controller\\SchemaApiController', $route['controller']);
        // check methods
        $methods = $this->connection->fetchAll('SELECT routeId, method, version, status, active, public, request, response, action FROM fusio_routes_method WHERE routeId = :routeId', ['routeId' => $route['id']]);
        $this->assertEquals(1, count($methods));
        $this->assertEquals(['routeId' => 62, 'method' => 'GET', 'version' => 1, 'status' => Resource::STATUS_DEVELOPMENT, 'active' => 1, 'public' => 1, 'request' => null, 'response' => 3, 'action' => 4], $methods[0]);
    }
Esempio n. 5
0
 public function getConnection()
 {
     if (!Environment::hasConnection()) {
         $this->markTestSkipped('No database connection available');
     }
     if (self::$con === null) {
         self::$con = Environment::getService('connection');
     }
     if ($this->connection === null) {
         $this->connection = self::$con;
     }
     return $this->createDefaultDBConnection($this->connection->getWrappedConnection(), Environment::getService('config')->get('psx_sql_db'));
 }
Esempio n. 6
0
 public function testCommand()
 {
     $command = Environment::getService('console')->find('system:token');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'appId' => 1, 'userId' => 1, 'scopes' => 'backend,authorization', 'expire' => 'P1M']);
     $actual = $commandTester->getDisplay();
     $data = Yaml::parse($actual);
     $this->assertEquals('Backend', $data['App']);
     $this->assertEquals('Administrator', $data['User']);
     $this->assertNotEmpty($data['Token']);
     $this->assertEquals(date('Y-m-d', strtotime('+1 month')), $data['Expires']);
     $this->assertEquals('backend,authorization', $data['Scope']);
 }
Esempio n. 7
0
 public function testCommand()
 {
     $command = Environment::getService('console')->find('connection:add');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'name' => 'foobar', 'class' => 'Fusio\\Adapter\\Sql\\Connection\\DBALAdvanced', 'config' => 'url=sqlite:///:memory:']);
     $actual = $commandTester->getDisplay();
     $this->assertEquals('Connection successful created', trim($actual));
     // check connection
     $connection = $this->connection->fetchAssoc('SELECT id, name, class, config FROM fusio_connection ORDER BY id DESC');
     $this->assertEquals(2, $connection['id']);
     $this->assertEquals('foobar', $connection['name']);
     $this->assertEquals('Fusio\\Adapter\\Sql\\Connection\\DBALAdvanced', $connection['class']);
     $this->assertNotEmpty($connection['config']);
 }
Esempio n. 8
0
 public function testCommand()
 {
     $command = Environment::getService('console')->find('schema:add');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'name' => 'bar', 'file' => __DIR__ . '/schema.json']);
     $actual = $commandTester->getDisplay();
     $this->assertEquals('Schema successful created', trim($actual));
     // check schema
     $schema = $this->connection->fetchAssoc('SELECT id, status, name, source, cache FROM fusio_schema ORDER BY id DESC');
     $this->assertEquals(3, $schema['id']);
     $this->assertEquals(1, $schema['status']);
     $this->assertEquals('bar', $schema['name']);
     $this->assertJsonStringEqualsJsonString(file_get_contents(__DIR__ . '/schema.json'), $schema['source']);
     $this->assertInstanceOf(Schema::class, unserialize($schema['cache']));
 }
Esempio n. 9
0
 public function testCommand()
 {
     $command = Environment::getService('console')->find('action:add');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'name' => 'foobar', 'class' => 'Fusio\\Adapter\\Util\\Action\\UtilStaticResponse', 'config' => 'response={"foo":"bar"}']);
     $actual = $commandTester->getDisplay();
     $this->assertEquals('Action successful created', trim($actual));
     // check action
     $action = $this->connection->fetchAssoc('SELECT id, status, name, class, config FROM fusio_action ORDER BY id DESC');
     $this->assertEquals(4, $action['id']);
     $this->assertEquals(1, $action['status']);
     $this->assertEquals('foobar', $action['name']);
     $this->assertEquals('Fusio\\Adapter\\Util\\Action\\UtilStaticResponse', $action['class']);
     $this->assertEquals('a:1:{s:8:"response";s:13:"{"foo":"bar"}";}', $action['config']);
 }
Esempio n. 10
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('connection:list');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName()]);
        $actual = $commandTester->getDisplay();
        $expect = <<<TEXT
+----+--------+
| ID | Name   |
+----+--------+
| 1  | Native |
+----+--------+

TEXT;
        Assert::assertEqualsIgnoreWhitespace($expect, $actual);
    }
Esempio n. 11
0
    public function testPut()
    {
        $response = $this->sendRequest('http://127.0.0.1/consumer/account/change_password', 'PUT', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer 1b8fca875fc81c78538d541b3ed0557a34e33feaf71c2ecdc2b9ebd40aade51b'), json_encode(['oldPassword' => 'qf2vX10Ec3wFZHx0K1eL', 'newPassword' => 'qf2vX10Ec4wFZHx0K1eL', 'verifyPassword' => 'qf2vX10Ec4wFZHx0K1eL']));
        $body = (string) $response->getBody();
        $expect = <<<JSON
{
    "success": true,
    "message": "Password successful changed"
}
JSON;
        $this->assertEquals(200, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database password
        $sql = Environment::getService('connection')->createQueryBuilder()->select('password')->from('fusio_user')->where('id = :id')->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql, ['id' => 2]);
        $this->assertTrue(password_verify('qf2vX10Ec4wFZHx0K1eL', $row['password']));
    }
Esempio n. 12
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('connection:class');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName()]);
        $actual = $commandTester->getDisplay();
        $expect = <<<TEXT
+---------------------------+-------------------------------------------+
| Name                      | Class                                     |
+---------------------------+-------------------------------------------+
| SQL-Connection            | Fusio\\Adapter\\Sql\\Connection\\DBAL         |
| SQL-Connection (advanced) | Fusio\\Adapter\\Sql\\Connection\\DBALAdvanced |
+---------------------------+-------------------------------------------+

TEXT;
        Assert::assertEqualsIgnoreWhitespace($expect, $actual);
    }
Esempio n. 13
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('action:detail');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName(), 'class' => 'Fusio\\Adapter\\Util\\Action\\UtilStaticResponse']);
        $actual = $commandTester->getDisplay();
        $expect = <<<TEXT
+------------+----------+----------------------------------------+
| Name       | Type     | Details                                |
+------------+----------+----------------------------------------+
| statusCode | Select   | 100: Continue, 101: Switching Pr [...] |
| response   | TextArea | json                                   |
+------------+----------+----------------------------------------+

TEXT;
        Assert::assertEqualsIgnoreWhitespace($expect, $actual);
    }
Esempio n. 14
0
    public function testPut()
    {
        $response = $this->sendRequest('http://127.0.0.1/backend/account/change_password', 'PUT', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer e4a4d21e8ca88b215572b4d8635c492d8877fd8d3de6b98ba7c08d282adfb94f'), json_encode(['oldPassword' => 'qf2vX10Ec3wFZHx0K1eL', 'newPassword' => 'qf2vX10Ec4wFZHx0K1eL', 'verifyPassword' => 'qf2vX10Ec4wFZHx0K1eL']));
        $body = (string) $response->getBody();
        $expect = <<<JSON
{
    "success": true,
    "message": "Password successful changed"
}
JSON;
        $this->assertEquals(200, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database password
        $sql = Environment::getService('connection')->createQueryBuilder()->select('password')->from('fusio_user')->where('id = :id')->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql, ['id' => 4]);
        $this->assertTrue(password_verify('qf2vX10Ec4wFZHx0K1eL', $row['password']));
    }
Esempio n. 15
0
 public function testPost()
 {
     $response = $this->sendRequest('http://127.0.0.1/consumer/register', 'POST', array('User-Agent' => 'Fusio TestCase'), json_encode(['name' => 'baz', 'email' => '*****@*****.**', 'password' => 'foobar!123']));
     $body = (string) $response->getBody();
     $data = json_decode($body);
     $this->assertEquals(200, $response->getStatusCode(), $body);
     $this->assertEquals(true, $data->success);
     $this->assertEquals('Registration successful', $data->message);
     // check database user
     $sql = Environment::getService('connection')->createQueryBuilder()->select('provider', 'status', 'remoteId', 'name', 'email')->from('fusio_user')->orderBy('id', 'DESC')->setFirstResult(0)->setMaxResults(1)->getSQL();
     $row = Environment::getService('connection')->fetchAssoc($sql);
     $this->assertEquals(1, $row['provider']);
     $this->assertEquals(2, $row['status']);
     $this->assertEquals('', $row['remoteId']);
     $this->assertEquals('baz', $row['name']);
     $this->assertEquals('*****@*****.**', $row['email']);
 }
Esempio n. 16
0
 public function testCommand()
 {
     $command = Environment::getService('console')->find('user:add');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), '--status' => '1', '--username' => 'bar', '--email' => '*****@*****.**', '--password' => 'test1234!']);
     $actual = $commandTester->getDisplay();
     $this->assertContains('Created user bar successful', $actual);
     // check user
     $user = $this->connection->fetchAssoc('SELECT id, provider, status, remoteId, name, email, password FROM fusio_user ORDER BY id DESC');
     $this->assertEquals(6, $user['id']);
     $this->assertEquals(1, $user['provider']);
     $this->assertEquals(1, $user['status']);
     $this->assertEquals(null, $user['remoteId']);
     $this->assertEquals('bar', $user['name']);
     $this->assertEquals('*****@*****.**', $user['email']);
     $this->assertNotEmpty($user['password']);
 }
Esempio n. 17
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('action:class');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName()]);
        $actual = $commandTester->getDisplay();
        $expect = <<<TEXT
+----------------------+----------------------------------------------+
| Name                 | Class                                        |
+----------------------+----------------------------------------------+
| SQL-Table            | Fusio\\Adapter\\Sql\\Action\\SqlTable            |
| Util-Static-Response | Fusio\\Adapter\\Util\\Action\\UtilStaticResponse |
| V8-Processor         | Fusio\\Adapter\\V8\\Action\\V8Processor          |
+----------------------+----------------------------------------------+

TEXT;
        Assert::assertEqualsIgnoreWhitespace($expect, $actual);
    }
Esempio n. 18
0
 public function testCommand()
 {
     $command = Environment::getService('console')->find('app:add');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'userId' => 1, 'status' => 1, 'name' => 'Bar-App', 'url' => 'http://google.com', 'parameters' => 'foo=bar&bar=foo', 'scopes' => 'backend,authorization']);
     $actual = $commandTester->getDisplay();
     $this->assertEquals('App successful created', trim($actual));
     // check app
     $connection = $this->connection->fetchAssoc('SELECT id, userId, status, name, url, parameters, appKey, appSecret FROM fusio_app ORDER BY id DESC');
     $this->assertEquals(6, $connection['id']);
     $this->assertEquals(1, $connection['userId']);
     $this->assertEquals(1, $connection['status']);
     $this->assertEquals('Bar-App', $connection['name']);
     $this->assertEquals('http://google.com', $connection['url']);
     $this->assertEquals('foo=bar&bar=foo', $connection['parameters']);
     $this->assertNotEmpty($connection['appKey']);
     $this->assertNotEmpty($connection['appSecret']);
 }
Esempio n. 19
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('user:list');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName()]);
        $actual = $commandTester->getDisplay();
        $expect = <<<TEXT
+----+---------------+
| ID | Name          |
+----+---------------+
| 4  | Developer     |
| 3  | Disabled      |
| 2  | Consumer      |
| 1  | Administrator |
+----+---------------+

TEXT;
        Assert::assertEqualsIgnoreWhitespace($expect, $actual);
    }
Esempio n. 20
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('app:list');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName()]);
        $actual = $commandTester->getDisplay();
        $expect = <<<TEXT
+----+----------+
| ID | Name     |
+----+----------+
| 4  | Pending  |
| 3  | Foo-App  |
| 2  | Consumer |
| 1  | Backend  |
+----+----------+

TEXT;
        Assert::assertEqualsIgnoreWhitespace($expect, $actual);
    }
Esempio n. 21
0
    public function testPost()
    {
        $response = $this->sendRequest('http://127.0.0.1/backend/connection', 'POST', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer da250526d583edabca8ac2f99e37ee39aa02a3c076c0edc6929095e20ca18dcf'), json_encode(['name' => 'Foo', 'class' => 'Fusio\\Adapter\\Sql\\Connection\\DBAL', 'config' => ['type' => 'pdo_mysql', 'host' => '127.0.0.1', 'username' => 'root', 'password' => 'foo', 'database' => 'bar']]));
        $body = (string) $response->getBody();
        $expect = <<<'JSON'
{
    "success": true,
    "message": "Connection successful created"
}
JSON;
        $this->assertEquals(201, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database
        $sql = Environment::getService('connection')->createQueryBuilder()->select('id', 'name', 'class', 'config')->from('fusio_connection')->orderBy('id', 'DESC')->setFirstResult(0)->setMaxResults(1)->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql);
        $this->assertEquals(2, $row['id']);
        $this->assertEquals('Foo', $row['name']);
        $this->assertEquals('Fusio\\Adapter\\Sql\\Connection\\DBAL', $row['class']);
        $this->assertEquals(217, strlen($row['config']));
    }
Esempio n. 22
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('connection:detail');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName(), 'class' => 'Fusio\\Adapter\\Sql\\Connection\\DBAL']);
        $actual = $commandTester->getDisplay();
        $expect = <<<TEXT
+----------+--------+----------------------------------------+
| Name     | Type   | Details                                |
+----------+--------+----------------------------------------+
| type     | Select | pdo_mysql: MySQL, pdo_pgsql: Pos [...] |
| host     | Input  | text                                   |
| username | Input  | text                                   |
| password | Input  | password                               |
| database | Input  | text                                   |
+----------+--------+----------------------------------------+

TEXT;
        Assert::assertEqualsIgnoreWhitespace($expect, $actual);
    }
Esempio n. 23
0
    public function testPost()
    {
        $response = $this->sendRequest('http://127.0.0.1/backend/action', 'POST', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer da250526d583edabca8ac2f99e37ee39aa02a3c076c0edc6929095e20ca18dcf'), json_encode(['name' => 'Foo', 'class' => 'Fusio\\Adapter\\Util\\Action\\UtilStaticResponse', 'config' => ['statusCode' => '200', 'response' => '{"foo": "bar"}']]));
        $body = (string) $response->getBody();
        $expect = <<<'JSON'
{
    "success": true,
    "message": "Action successful created"
}
JSON;
        $this->assertEquals(201, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database
        $sql = Environment::getService('connection')->createQueryBuilder()->select('id', 'name', 'class', 'config')->from('fusio_action')->orderBy('id', 'DESC')->setFirstResult(0)->setMaxResults(1)->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql);
        $this->assertEquals(4, $row['id']);
        $this->assertEquals('Foo', $row['name']);
        $this->assertEquals('Fusio\\Adapter\\Util\\Action\\UtilStaticResponse', $row['class']);
        $this->assertEquals('a:2:{s:10:"statusCode";s:3:"200";s:8:"response";s:14:"{"foo": "bar"}";}', $row['config']);
    }
Esempio n. 24
0
    public function testPut()
    {
        $response = $this->sendRequest('http://127.0.0.1/backend/config/3', 'PUT', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer da250526d583edabca8ac2f99e37ee39aa02a3c076c0edc6929095e20ca18dcf'), json_encode(['value' => 'foo,bar']));
        $body = (string) $response->getBody();
        $expect = <<<'JSON'
{
    "success": true,
    "message": "Config successful updated"
}
JSON;
        $this->assertEquals(200, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database
        $sql = Environment::getService('connection')->createQueryBuilder()->select('id', 'type', 'name', 'description', 'value')->from('fusio_config')->where('id = :id')->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql, ['id' => 3]);
        $this->assertEquals(3, $row['id']);
        $this->assertEquals(1, $row['type']);
        $this->assertEquals('scopes_default', $row['name']);
        $this->assertEquals('If a user registers through the consumer API the following scopes are assigned', $row['description']);
        $this->assertEquals('foo,bar', $row['value']);
    }
Esempio n. 25
0
    public function testPut()
    {
        $response = $this->sendRequest('http://127.0.0.1/consumer/account', 'PUT', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer b8f6f61bd22b440a3e4be2b7491066682bfcde611dbefa1b15d2e7f6522d77e2'), json_encode(['name' => 'fooo', 'email' => '*****@*****.**']));
        $body = (string) $response->getBody();
        $expect = <<<JSON
{
    "success": true,
    "message": "Account update successful"
}
JSON;
        $this->assertEquals(200, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database user
        $sql = Environment::getService('connection')->createQueryBuilder()->select('provider', 'status', 'remoteId', 'name', 'email')->from('fusio_user')->where('id = :id')->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql, ['id' => 1]);
        $this->assertEquals(1, $row['provider']);
        $this->assertEquals(1, $row['status']);
        $this->assertEquals('', $row['remoteId']);
        $this->assertEquals('Administrator', $row['name']);
        $this->assertEquals('*****@*****.**', $row['email']);
    }
Esempio n. 26
0
    public function testPost()
    {
        $response = $this->sendRequest('http://127.0.0.1/consumer/app/developer', 'POST', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer b8f6f61bd22b440a3e4be2b7491066682bfcde611dbefa1b15d2e7f6522d77e2'), json_encode(['status' => 3, 'name' => 'Foo', 'url' => 'http://google.com', 'scopes' => ['foo', 'bar']]));
        $body = (string) $response->getBody();
        $expect = <<<'JSON'
{
    "success": true,
    "message": "App successful created"
}
JSON;
        $this->assertEquals(201, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database
        $sql = Environment::getService('connection')->createQueryBuilder()->select('id', 'status', 'userId', 'name', 'url')->from('fusio_app')->orderBy('id', 'DESC')->setFirstResult(0)->setMaxResults(1)->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql);
        $this->assertEquals(6, $row['id']);
        $this->assertEquals(App::STATUS_ACTIVE, $row['status']);
        $this->assertEquals(1, $row['userId']);
        $this->assertEquals('Foo', $row['name']);
        $this->assertEquals('http://google.com', $row['url']);
    }
Esempio n. 27
0
    public function testPost()
    {
        $response = $this->sendRequest('http://127.0.0.1/backend/routes', 'POST', array('User-Agent' => 'Fusio TestCase', 'Authorization' => 'Bearer da250526d583edabca8ac2f99e37ee39aa02a3c076c0edc6929095e20ca18dcf'), json_encode(['path' => '/bar', 'config' => [['version' => 1, 'status' => 4, 'methods' => ['GET' => ['active' => true, 'public' => true, 'response' => 1, 'action' => 3], 'POST' => ['active' => true, 'public' => true, 'request' => 2, 'response' => 1, 'action' => 3]]]]]));
        $body = (string) $response->getBody();
        $expect = <<<'JSON'
{
    "success": true,
    "message": "Route successful created"
}
JSON;
        $this->assertEquals(201, $response->getStatusCode(), $body);
        $this->assertJsonStringEqualsJsonString($expect, $body, $body);
        // check database
        $sql = Environment::getService('connection')->createQueryBuilder()->select('id', 'status', 'methods', 'path', 'controller')->from('fusio_routes')->orderBy('id', 'DESC')->setFirstResult(0)->setMaxResults(1)->getSQL();
        $row = Environment::getService('connection')->fetchAssoc($sql);
        $this->assertEquals(62, $row['id']);
        $this->assertEquals(1, $row['status']);
        $this->assertEquals('GET|POST|PUT|DELETE', $row['methods']);
        $this->assertEquals('/bar', $row['path']);
        $this->assertEquals('Fusio\\Impl\\Controller\\SchemaApiController', $row['controller']);
        // check methods
        $sql = Environment::getService('connection')->createQueryBuilder()->select('id', 'routeId', 'method', 'version', 'status', 'active', 'public', 'request', 'response', 'action')->from('fusio_routes_method')->where('routeId = :routeId')->orderBy('id', 'ASC')->setFirstResult(0)->getSQL();
        $result = Environment::getService('connection')->fetchAll($sql, ['routeId' => $row['id']]);
        $this->assertEquals(2, count($result));
        $this->assertEquals('GET', $result[0]['method']);
        $this->assertEquals(1, $result[0]['version']);
        $this->assertEquals(4, $result[0]['status']);
        $this->assertEquals(1, $result[0]['active']);
        $this->assertEquals(1, $result[0]['public']);
        $this->assertEquals(null, $result[0]['request']);
        $this->assertEquals(3, $result[0]['action']);
        $this->assertEquals('POST', $result[1]['method']);
        $this->assertEquals(1, $result[1]['version']);
        $this->assertEquals(4, $result[1]['status']);
        $this->assertEquals(1, $result[1]['active']);
        $this->assertEquals(1, $result[1]['public']);
        $this->assertEquals(2, $result[1]['request']);
        $this->assertEquals(3, $result[1]['action']);
    }
Esempio n. 28
0
 public function testPost()
 {
     $response = $this->sendRequest('http://127.0.0.1/consumer/login', 'POST', array('User-Agent' => 'Fusio TestCase'), json_encode(['username' => 'Consumer', 'password' => 'qf2vX10Ec3wFZHx0K1eL']));
     $body = (string) $response->getBody();
     $data = json_decode($body);
     $this->assertEquals(200, $response->getStatusCode(), $body);
     $token = JWT::decode($data->token, Environment::getConfig()->get('fusio_project_key'), ['HS256']);
     $this->assertNotEmpty($token->sub);
     $this->assertNotEmpty($token->iat);
     $this->assertNotEmpty($token->exp);
     $this->assertEquals('Consumer', $token->name);
     // check database access token
     $sql = Environment::getService('connection')->createQueryBuilder()->select('appId', 'userId', 'status', 'token', 'scope', 'ip', 'expire')->from('fusio_app_token')->where('token = :token')->getSQL();
     $row = Environment::getService('connection')->fetchAssoc($sql, ['token' => $token->sub]);
     $this->assertEquals(2, $row['appId']);
     $this->assertEquals(2, $row['userId']);
     $this->assertEquals(1, $row['status']);
     $this->assertNotEmpty($row['token']);
     $this->assertEquals($row['token'], $token->sub);
     $this->assertEquals('consumer,authorization,foo,bar', $row['scope']);
     $this->assertEquals('127.0.0.1', $row['ip']);
     $this->assertNotEmpty($row['expire']);
 }
Esempio n. 29
0
    public function testCommand()
    {
        $command = Environment::getService('console')->find('system:export');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName()]);
        $actual = $commandTester->getDisplay();
        $expect = <<<'JSON'
{
    "actionClass": [
        "Fusio\\Adapter\\Sql\\Action\\SqlTable",
        "Fusio\\Adapter\\Util\\Action\\UtilStaticResponse",
        "Fusio\\Adapter\\V8\\Action\\V8Processor"
    ],
    "connectionClass": [
        "Fusio\\Adapter\\Sql\\Connection\\DBAL",
        "Fusio\\Adapter\\Sql\\Connection\\DBALAdvanced"
    ],
    "connection": [
        {
            "name": "Native",
            "class": "Fusio\\Impl\\Tests\\Connection\\Native",
            "config": {}
        }
    ],
    "schema": [
        {
            "name": "Foo-Schema",
            "source": {
                "id": "http:\/\/phpsx.org#",
                "title": "test",
                "type": "object",
                "properties": {
                    "totalResults": {
                        "type": "integer"
                    },
                    "itemsPerPage": {
                        "type": "integer"
                    },
                    "startIndex": {
                        "type": "integer"
                    },
                    "entry": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "integer"
                                },
                                "title": {
                                    "type": "string"
                                },
                                "content": {
                                    "type": "string"
                                },
                                "date": {
                                    "type": "string",
                                    "format": "date-time"
                                }
                            }
                        }
                    }
                }
            }
        },
        {
            "name": "Passthru",
            "source": {
                "id": "http:\/\/fusio-project.org",
                "title": "passthru",
                "type": "object",
                "description": "No schema was specified all data will pass thru. Please contact the API provider for more informations about the data format.",
                "properties": []
            }
        }
    ],
    "action": [
        {
            "name": "Sql-Table",
            "class": "Fusio\\Adapter\\Sql\\Action\\SqlTable",
            "config": {
                "connection": "Native",
                "table": "app_news"
            }
        },
        {
            "name": "Util-Static-Response",
            "class": "Fusio\\Adapter\\Util\\Action\\UtilStaticResponse",
            "config": {
                "response": "{\"foo\": \"bar\"}"
            }
        },
        {
            "name": "Welcome",
            "class": "Fusio\\Adapter\\Util\\Action\\UtilStaticResponse",
            "config": {
                "response": "{\n    \"message\": \"Congratulations the installation of Fusio was successful\",\n    \"links\": [\n        {\n            \"rel\": \"about\",\n            \"name\": \"http:\\\/\\\/fusio-project.org\"\n        }\n    ]\n}"
            }
        }
    ],
    "routes": [
        {
            "path": "\/foo",
            "config": [
                {
                    "version": 1,
                    "status": 4,
                    "methods": {
                        "GET": {
                            "active": true,
                            "public": true,
                            "response": "Foo-Schema",
                            "action": "Sql-Table"
                        },
                        "POST": {
                            "active": true,
                            "public": false,
                            "request": "Passthru",
                            "response": "Passthru",
                            "action": "Sql-Table"
                        }
                    }
                }
            ]
        },
        {
            "path": "\/",
            "config": [
                {
                    "version": 1,
                    "status": 4,
                    "methods": {
                        "GET": {
                            "active": true,
                            "public": true,
                            "response": "Passthru",
                            "action": "Welcome"
                        }
                    }
                }
            ]
        }
    ]
}
JSON;
        $this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
    }
Esempio n. 30
0
 /**
  * @param \Fusio\Engine\ParametersInterface $config
  * @return \Doctrine\DBAL\Connection
  */
 public function getConnection(ParametersInterface $config)
 {
     return Environment::getService('connection');
 }