a normal reply - too-obscure
'],
+ ],
+ 'users' => [
+ $this->normalUser(),
+ ],
+ 'groups' => [
+ $this->guestGroup(),
+ $this->memberGroup(),
+ ],
+ 'group_user' => [
+ ['user_id' => 2, 'group_id' => 3],
+ ],
+ 'group_permission' => [
+ ['permission' => 'viewDiscussions', 'group_id' => 2],
+ ['permission' => 'viewDiscussions', 'group_id' => 3],
+ ]
+ ]);
+ }
+
+ /**
+ * @test
+ */
+ public function author_can_see_discussion()
+ {
+ $this->actor = User::find(2);
+
+ $response = $this->callWith([], ['id' => 1]);
+
+ $this->assertEquals(200, $response->getStatusCode());
+ }
+
+ /**
+ * @test
+ * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
+ */
+ public function guest_cannot_see_empty_discussion()
+ {
+ $response = $this->callWith([], ['id' => 1]);
+
+ $this->assertEquals(200, $response->getStatusCode());
+ }
+
+ /**
+ * @test
+ */
+ public function guest_can_see_discussion()
+ {
+ $response = $this->callWith([], ['id' => 2]);
+
+ $this->assertEquals(200, $response->getStatusCode());
+ }
+
+ /**
+ * @test
+ * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
+ */
+ public function guests_cannot_see_private_discussion()
+ {
+ $this->callWith([], ['id' => 3]);
+ }
+}
diff --git a/framework/core/tests/Api/Controller/UpdateUserControllerTest.php b/framework/core/tests/integration/api/Controller/UpdateUserControllerTest.php
similarity index 52%
rename from framework/core/tests/Api/Controller/UpdateUserControllerTest.php
rename to framework/core/tests/integration/api/Controller/UpdateUserControllerTest.php
index 2ea9ecb3e..bceb4895f 100644
--- a/framework/core/tests/Api/Controller/UpdateUserControllerTest.php
+++ b/framework/core/tests/integration/api/Controller/UpdateUserControllerTest.php
@@ -9,9 +9,10 @@
* file that was distributed with this source code.
*/
-namespace Flarum\Tests\Api\Controller;
+namespace Flarum\Tests\integration\api\Controller;
use Flarum\Api\Controller\UpdateUserController;
+use Flarum\User\User;
class UpdateUserControllerTest extends ApiControllerTestCase
{
@@ -21,24 +22,41 @@ class UpdateUserControllerTest extends ApiControllerTestCase
'email' => 'newemail@machine.local',
];
- protected $userAttributes = [
- 'username' => 'timtom',
- 'password' => 'too-obscure',
- 'email' => 'timtom@machine.local',
- 'is_email_confirmed' => true,
- ];
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->prepareDatabase([
+ 'users' => [
+ $this->adminUser(),
+ $this->normalUser(),
+ ],
+ 'groups' => [
+ $this->adminGroup(),
+ $this->memberGroup(),
+ ],
+ 'group_user' => [
+ ['user_id' => 1, 'group_id' => 1],
+ ['user_id' => 2, 'group_id' => 3],
+ ],
+ 'group_permission' => [
+ ['permission' => 'viewUserList', 'group_id' => 3],
+ ]
+ ]);
+ }
/**
* @test
*/
public function users_can_see_their_private_information()
{
- $this->actor = $this->getNormalUser();
- $response = $this->callWith([], ['id' => $this->actor->id]);
+ $this->actor = User::find(2);
+
+ $response = $this->callWith([], ['id' => 2]);
// Test for successful response and that the email is included in the response
$this->assertEquals(200, $response->getStatusCode());
- $this->assertContains('timtom@machine.local', (string) $response->getBody());
+ $this->assertContains('normal@machine.local', (string) $response->getBody());
}
/**
@@ -46,17 +64,12 @@ class UpdateUserControllerTest extends ApiControllerTestCase
*/
public function users_can_not_see_other_users_private_information()
{
- $this->actor = $this->getNormalUser();
+ $this->actor = User::find(2);
$response = $this->callWith([], ['id' => 1]);
// Make sure sensitive information is not made public
$this->assertEquals(200, $response->getStatusCode());
- $this->assertNotContains('admin@example.com', (string) $response->getBody());
- }
-
- public function tearDown()
- {
- parent::tearDown();
+ $this->assertNotContains('admin@machine.local', (string) $response->getBody());
}
}
diff --git a/framework/core/tests/integration/setup.php b/framework/core/tests/integration/setup.php
new file mode 100644
index 000000000..590538f2b
--- /dev/null
+++ b/framework/core/tests/integration/setup.php
@@ -0,0 +1,74 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+use Flarum\Install\AdminUser;
+use Flarum\Install\DatabaseConfig;
+use Flarum\Install\Installation;
+
+require __DIR__.'/../../vendor/autoload.php';
+
+$host = env('DB_HOST', 'localhost');
+$port = intval(env('DB_PORT', 3306));
+$name = env('DB_DATABASE', 'flarum_test');
+$user = env('DB_USERNAME', 'root');
+$pass = env('DB_PASSWORD', '');
+$pref = env('DB_PREFIX', '');
+
+echo "Connecting to database $name at $host:$port.\n";
+echo "Logging in as $user with password '$pass'.\n";
+echo "Table prefix: '$pref'\n";
+
+echo "\n\nCancel now if that's not what you want...\n";
+echo "Use the following environment variables for configuration:\n";
+echo "DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_PREFIX\n";
+
+sleep(5);
+
+echo "\nOff we go...\n";
+
+/*
+ * Setup installation configuration
+ */
+
+$installation = new Installation(
+ __DIR__.'/tmp',
+ __DIR__.'/tmp/public',
+ __DIR__.'/tmp/storage'
+);
+
+$pipeline = $installation
+ ->configPath('config.php')
+ ->debugMode(true)
+ ->baseUrl('http://localhost')
+ ->databaseConfig(new DatabaseConfig(
+ 'mysql',
+ env('DB_HOST', 'localhost'),
+ intval(env('DB_PORT', 3306)),
+ env('DB_DATABASE', 'flarum_test'),
+ env('DB_USERNAME', 'root'),
+ env('DB_PASSWORD', ''),
+ env('DB_PREFIX', '')
+ ))
+ ->adminUser(new AdminUser(
+ 'admin',
+ 'secret',
+ 'admin@flarum.email'
+ ))
+ ->settings(['mail_driver' => 'log'])
+ ->build();
+
+/*
+ * Run the actual configuration
+ */
+
+$pipeline->run();
+
+echo "Installation complete\n";
diff --git a/framework/core/tests/tmp/public/assets/.gitkeep b/framework/core/tests/integration/tmp/public/assets/.gitkeep
similarity index 100%
rename from framework/core/tests/tmp/public/assets/.gitkeep
rename to framework/core/tests/integration/tmp/public/assets/.gitkeep
diff --git a/framework/core/tests/tmp/storage/.gitkeep b/framework/core/tests/integration/tmp/storage/.gitkeep
similarity index 100%
rename from framework/core/tests/tmp/storage/.gitkeep
rename to framework/core/tests/integration/tmp/storage/.gitkeep
diff --git a/framework/core/tests/tmp/storage/formatter/.gitkeep b/framework/core/tests/integration/tmp/storage/formatter/.gitkeep
similarity index 100%
rename from framework/core/tests/tmp/storage/formatter/.gitkeep
rename to framework/core/tests/integration/tmp/storage/formatter/.gitkeep
diff --git a/framework/core/tests/tmp/storage/sessions/.gitkeep b/framework/core/tests/integration/tmp/storage/sessions/.gitkeep
similarity index 100%
rename from framework/core/tests/tmp/storage/sessions/.gitkeep
rename to framework/core/tests/integration/tmp/storage/sessions/.gitkeep
diff --git a/framework/core/tests/tmp/vendor/composer/installed.json b/framework/core/tests/integration/tmp/vendor/composer/installed.json
similarity index 100%
rename from framework/core/tests/tmp/vendor/composer/installed.json
rename to framework/core/tests/integration/tmp/vendor/composer/installed.json
diff --git a/framework/core/phpunit.xml b/framework/core/tests/phpunit.integration.xml
similarity index 68%
rename from framework/core/phpunit.xml
rename to framework/core/tests/phpunit.integration.xml
index 9a6492957..2ebc8b719 100644
--- a/framework/core/phpunit.xml
+++ b/framework/core/tests/phpunit.integration.xml
@@ -11,12 +11,8 @@
syntaxCheck="false">