create(); $portfolio = Portfolio::factory()->create(['user_id' => $user->id]); $this->assertInstanceOf(User::class, $portfolio->user); $this->assertEquals($user->id, $portfolio->user->id); } /** * Test portfolio has required attributes. */ public function test_portfolio_has_required_attributes() { $portfolio = Portfolio::factory()->create([ 'name' => 'Test Portfolio', 'domain' => 'test.com', 'path' => 'portfolios/test/1', 'active' => true, 'deployed' => false, ]); $this->assertEquals('Test Portfolio', $portfolio->name); $this->assertEquals('test.com', $portfolio->domain); $this->assertEquals('portfolios/test/1', $portfolio->path); $this->assertTrue($portfolio->active); $this->assertFalse($portfolio->deployed); } /** * Test getPortfolioName method. */ public function test_get_portfolio_name() { $portfolio = Portfolio::factory()->create(['name' => 'My Portfolio']); $this->assertEquals('My Portfolio', $portfolio->getPortfolioName()); } /** * Test getPortfolioDomain method. */ public function test_get_portfolio_domain() { $portfolio = Portfolio::factory()->create(['domain' => 'myportfolio.com']); $this->assertEquals('myportfolio.com', $portfolio->getPortfolioDomain()); } /** * Test getStoragePath method returns correct path format. */ public function test_get_storage_path() { $portfolio = Portfolio::factory()->create([ 'id' => 5, 'name' => 'Test Portfolio', ]); $expectedPath = "portfolios/Test Portfolio/5"; $this->assertEquals($expectedPath, $portfolio->getStoragePath()); } /** * Test getStoragePath includes portfolio ID. */ public function test_get_storage_path_includes_id() { $portfolio = Portfolio::factory()->create(); $storagePath = $portfolio->getStoragePath(); $this->assertStringContainsString((string)$portfolio->id, $storagePath); } /** * Test getStoragePath includes portfolio name. */ public function test_get_storage_path_includes_name() { $portfolio = Portfolio::factory()->create(['name' => 'Unique Name']); $storagePath = $portfolio->getStoragePath(); $this->assertStringContainsString('Unique Name', $storagePath); } /** * Test portfolio fillable attributes. */ public function test_portfolio_fillable_attributes() { $data = [ 'name' => 'Test Portfolio', 'domain' => 'test.com', 'path' => 'portfolios/test/1', 'deployed' => true, ]; $portfolio = Portfolio::factory()->create($data); foreach ($data as $key => $value) { $this->assertEquals($value, $portfolio->$key); } } /** * Test portfolio can be marked as active. */ public function test_portfolio_can_be_marked_active() { $portfolio = Portfolio::factory()->create(['active' => false]); $this->assertEquals(0, $portfolio->active); $portfolio->update(['active' => true]); $portfolio->refresh(); $this->assertEquals(1, $portfolio->active); } /** * Test portfolio can be marked as deployed. */ public function test_portfolio_can_be_marked_deployed() { $portfolio = Portfolio::factory()->create(['deployed' => false]); $this->assertEquals(0, $portfolio->deployed); $portfolio->update(['deployed' => true]); $portfolio->refresh(); $this->assertEquals(1, $portfolio->deployed); } /** * Test user can have many portfolios. */ public function test_user_can_have_many_portfolios() { $user = User::factory()->create(); Portfolio::factory(5)->create(['user_id' => $user->id]); $this->assertCount(5, $user->portfolios); } /** * Test portfolio timestamps are set. */ public function test_portfolio_has_timestamps() { $portfolio = Portfolio::factory()->create(); $this->assertNotNull($portfolio->created_at); $this->assertNotNull($portfolio->updated_at); } }