Ver código fonte

Merge pull request #608 from pixelfed/frontend-ui-refactor

Add more tests
daniel 6 anos atrás
pai
commit
e2518a2034

+ 55 - 0
.env.testing

@@ -0,0 +1,55 @@
+APP_NAME="PixelFed Test"
+APP_ENV=local
+APP_KEY=base64:lwX95GbNWX3XsucdMe0XwtOKECta3h/B+p9NbH2jd0E=
+APP_DEBUG=true
+APP_URL=https://pixelfed.dev
+
+ADMIN_DOMAIN="pixelfed.dev"
+APP_DOMAIN="pixelfed.dev"
+
+LOG_CHANNEL=stack
+
+DB_CONNECTION=mysql
+DB_HOST=127.0.0.1
+DB_PORT=3306
+DB_DATABASE=
+DB_USERNAME=
+DB_PASSWORD=
+
+BROADCAST_DRIVER=log
+CACHE_DRIVER=redis
+SESSION_DRIVER=redis
+SESSION_LIFETIME=120
+QUEUE_DRIVER=redis
+
+REDIS_HOST=127.0.0.1
+REDIS_PASSWORD=null
+REDIS_PORT=6379
+
+MAIL_DRIVER=log
+MAIL_HOST=smtp.mailtrap.io
+MAIL_PORT=2525
+MAIL_USERNAME=null
+MAIL_PASSWORD=null
+MAIL_ENCRYPTION=null
+MAIL_FROM_ADDRESS="pixelfed@example.com"
+MAIL_FROM_NAME="Pixelfed"
+
+SESSION_DOMAIN="${APP_DOMAIN}"
+SESSION_SECURE_COOKIE=true
+API_BASE="/api/1/"
+API_SEARCH="/api/search"
+
+OPEN_REGISTRATION=true
+RECAPTCHA_ENABLED=false
+ENFORCE_EMAIL_VERIFICATION=true
+
+MAX_PHOTO_SIZE=15000
+MAX_CAPTION_LENGTH=150
+MAX_ALBUM_LENGTH=4
+
+MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
+MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
+MIX_APP_URL="${APP_URL}"
+MIX_API_BASE="${API_BASE}"
+MIX_API_SEARCH="${API_SEARCH}"

+ 4 - 1
tests/Feature/LoginTest.php

@@ -25,7 +25,10 @@ class LoginTest extends TestCase
             $response->assertSuccessful()
                      ->assertSee('Register a new account');
         } else {
-            $this->assertTrue(true);
+            $response = $this->get('register');
+
+            $response->assertSuccessful()
+                    ->assertSee('Registration is closed');
         }
     }
 }

+ 86 - 0
tests/Unit/ActivityPub/AudienceScopeTest.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace Tests\Unit\ActivityPub;
+
+use Tests\TestCase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use App\Util\ActivityPub\Helpers;
+
+class AudienceScopeTest extends TestCase
+{
+	public function setUp()
+	{
+		parent::setUp();
+
+		$this->invalid = [
+			'id' => 'test',
+			'type' => 'Announce',
+			'actor' => null,
+			'published' => '',
+			'to' => ['test'],
+			'cc' => 'test',
+			'object' => 'test'
+		];
+
+		$this->mastodon = json_decode('{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":{"@id":"as:movedTo","@type":"@id"},"Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"featured":{"@id":"toot:featured","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}],"id":"https://mastodon.social/users/dansup/statuses/100784657480587830/activity","type":"Announce","actor":"https://mastodon.social/users/dansup","published":"2018-09-25T05:03:49Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://pleroma.site/users/pixeldev","https://mastodon.social/users/dansup/followers"],"object":"https://pleroma.site/objects/68b5c876-f52b-4819-8d81-de6839d73fbc","atomUri":"https://mastodon.social/users/dansup/statuses/100784657480587830/activity"}', true);
+
+		$this->pleroma = json_decode('{"@context":"https://www.w3.org/ns/activitystreams","actor":"https://pleroma.site/users/pixeldev","cc":["https://www.w3.org/ns/activitystreams#Public"],"context":"tag:mastodon.social,2018-10-14:objectId=59146153:objectType=Conversation","context_id":12325955,"id":"https://pleroma.site/activities/db2273eb-d504-4e3a-8f74-c343d069755a","object":"https://mastodon.social/users/dansup/statuses/100891324792793720","published":"2018-10-14T01:22:18.554227Z","to":["https://pleroma.site/users/pixeldev/followers","https://mastodon.social/users/dansup"],"type":"Announce"}', true);
+	}
+
+	public function testBasicValidation()
+	{
+		$this->assertFalse(Helpers::validateObject($this->invalid));
+	}
+
+	public function testMastodonValidation()
+	{
+		$this->assertTrue(Helpers::validateObject($this->mastodon));
+	}
+
+	public function testPleromaValidation()
+	{
+		$this->assertTrue(Helpers::validateObject($this->pleroma));
+	}
+
+	public function testMastodonAudienceScope()
+	{
+		$scope = Helpers::normalizeAudience($this->mastodon, false);
+		$actual = [
+		     "to" => [],
+		     "cc" => [
+		       "https://pleroma.site/users/pixeldev",
+		       "https://mastodon.social/users/dansup/followers",
+		     ],
+		     "scope" => "public",
+		 ];
+
+		 $this->assertEquals($scope, $actual);
+	}
+
+	public function testPleromaAudienceScope()
+	{
+		$scope = Helpers::normalizeAudience($this->pleroma, false);
+		$actual = [
+			"to" => [
+				"https://pleroma.site/users/pixeldev/followers",
+				"https://mastodon.social/users/dansup",
+			],
+			"cc" => [],
+			"scope" => "unlisted",
+		];
+
+		 $this->assertEquals($scope, $actual);
+	}
+
+	public function testInvalidAudienceScope()
+	{
+		$scope = Helpers::normalizeAudience($this->invalid, false);
+		$actual = [
+			'to' => [],
+			'cc' => [],
+			'scope' => 'private'
+		];
+		$this->assertEquals($scope, $actual);
+	}
+}

Diferenças do arquivo suprimidas por serem muito extensas
+ 15 - 0
tests/Unit/ActivityPub/NoteAttachmentTest.php


+ 66 - 0
tests/Unit/Lexer/StatusLexerTest.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace Tests\Unit\Lexer;
+
+use Tests\TestCase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use App\Util\Lexer\Autolink;
+use App\Util\Lexer\Extractor;
+
+class StatusLexerTest extends TestCase
+{
+    public $status;
+    public $entities;
+	public $autolink;
+
+    public function setUp()
+    {
+        parent::setUp();
+    	$this->status = "@pixelfed hi, really like the website! #píxelfed";
+    	$this->entities = Extractor::create()->extract($this->status);
+    	$this->autolink = Autolink::create()->autolink($this->status);
+    }
+
+    public function testLexerExtractor()
+    {
+        $expected = [
+            "hashtags" => [
+                 "píxelfed",
+             ],
+             "urls" => [],
+             "mentions" => [
+                 "pixelfed",
+             ],
+             "replyto" => "pixelfed",
+             "hashtags_with_indices" => [
+                 [
+                   "hashtag" => "píxelfed",
+                   "indices" => [
+                         39,
+                         48,
+                     ],
+                 ],
+             ],
+             "urls_with_indices" => [],
+             "mentions_with_indices" => [
+                 [
+                   "screen_name" => "pixelfed",
+                   "indices" => [
+                         0,
+                         9,
+                    ],
+                 ]
+             ]
+        ];
+
+        $this->assertEquals($this->entities, $expected);
+    }
+
+    public function testAutolink()
+    {
+        $expected = '@<a class="u-url mention" href="https://pixelfed.dev/pixelfed" rel="external nofollow noopener" target="_blank">pixelfed</a> hi, really like the website! <a href="https://pixelfed.dev/discover/tags/píxelfed?src=hash" title="#píxelfed" class="u-url hashtag" rel="external nofollow noopener">#píxelfed</a>';
+
+        $this->assertEquals($this->autolink, $expected);
+    }
+}

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff