@@ -50,6 +50,135 @@ public function test_get_certificates_will_return_with_multi_segment_tld()
5050 }
5151
5252
53+ public function test_get_sites_will_return_if_secured ()
54+ {
55+ $ files = Mockery::mock (Filesystem::class);
56+ $ dirPath = '/Users/usertest/parkedpath ' ;
57+ $ files ->shouldReceive ('scandir ' )
58+ ->once ()
59+ ->with ($ dirPath )
60+ ->andReturn (['sitetwo ' , 'sitethree ' ]);
61+ $ files ->shouldReceive ('isLink ' )
62+ ->andReturn (false );
63+ $ files ->shouldReceive ('realpath ' )
64+ ->twice ()
65+ ->andReturn ($ dirPath . '/sitetwo ' , $ dirPath . '/sitethree ' );
66+
67+ $ config = Mockery::mock (Configuration::class);
68+ $ config ->shouldReceive ('read ' )
69+ ->once ()
70+ ->andReturn (['tld ' => 'local ' ]);
71+
72+ swap (Filesystem::class, $ files );
73+ swap (Configuration::class, $ config );
74+
75+ /** @var Site $site */
76+ $ site = resolve (Site::class);
77+
78+ $ certs = Mockery::mock (\Illuminate \Support \Collection::class);
79+ $ certs ->shouldReceive ('has ' )
80+ ->twice ()
81+ ->with (Mockery::on (function ($ arg ) {
82+ return $ arg === 'sitetwo ' || $ arg === 'sitethree ' ;
83+ }))
84+ ->andReturn (false , true );
85+
86+ $ sites = $ site ->getSites ($ dirPath , $ certs );
87+
88+ $ this ->assertCount (2 , $ sites );
89+ $ this ->assertSame ([
90+ 'site ' => 'sitetwo ' ,
91+ 'secured ' => '' ,
92+ 'url ' => 'http://sitetwo.local ' ,
93+ 'path ' => $ dirPath . '/sitetwo ' ,
94+ ], $ sites ->first ());
95+ $ this ->assertSame ([
96+ 'site ' => 'sitethree ' ,
97+ 'secured ' => ' X ' ,
98+ 'url ' => 'https://sitethree.local ' ,
99+ 'path ' => $ dirPath . '/sitethree ' ,
100+ ], $ sites ->last ());
101+ }
102+
103+
104+ public function test_get_sites_will_work_with_non_symlinked_path ()
105+ {
106+ $ files = Mockery::mock (Filesystem::class);
107+ $ dirPath = '/Users/usertest/parkedpath ' ;
108+ $ files ->shouldReceive ('scandir ' )
109+ ->once ()
110+ ->with ($ dirPath )
111+ ->andReturn (['sitetwo ' ]);
112+ $ files ->shouldReceive ('isLink ' )
113+ ->once ()
114+ ->with ($ dirPath . '/sitetwo ' )
115+ ->andReturn (false );
116+ $ files ->shouldReceive ('realpath ' )
117+ ->once ()
118+ ->with ($ dirPath . '/sitetwo ' )
119+ ->andReturn ($ dirPath . '/sitetwo ' );
120+
121+ $ config = Mockery::mock (Configuration::class);
122+ $ config ->shouldReceive ('read ' )
123+ ->once ()
124+ ->andReturn (['tld ' => 'local ' ]);
125+
126+ swap (Filesystem::class, $ files );
127+ swap (Configuration::class, $ config );
128+
129+ /** @var Site $site */
130+ $ site = resolve (Site::class);
131+
132+ $ sites = $ site ->getSites ($ dirPath , collect ());
133+ $ this ->assertCount (1 , $ sites );
134+ $ this ->assertSame ([
135+ 'site ' => 'sitetwo ' ,
136+ 'secured ' => '' ,
137+ 'url ' => 'http://sitetwo.local ' ,
138+ 'path ' => $ dirPath . '/sitetwo ' ,
139+ ], $ sites ->first ());
140+ }
141+
142+
143+ public function test_get_sites_will_work_with_symlinked_path ()
144+ {
145+ $ files = Mockery::mock (Filesystem::class);
146+ $ dirPath = '/Users/usertest/apath ' ;
147+ $ files ->shouldReceive ('scandir ' )
148+ ->once ()
149+ ->with ($ dirPath )
150+ ->andReturn (['siteone ' ]);
151+ $ files ->shouldReceive ('isLink ' )
152+ ->once ()
153+ ->with ($ dirPath . '/siteone ' )
154+ ->andReturn (true );
155+ $ files ->shouldReceive ('readLink ' )
156+ ->once ()
157+ ->with ($ dirPath . '/siteone ' )
158+ ->andReturn ($ linkedPath = '/Users/usertest/linkedpath/siteone ' );
159+
160+ $ config = Mockery::mock (Configuration::class);
161+ $ config ->shouldReceive ('read ' )
162+ ->once ()
163+ ->andReturn (['tld ' => 'local ' ]);
164+
165+ swap (Filesystem::class, $ files );
166+ swap (Configuration::class, $ config );
167+
168+ /** @var Site $site */
169+ $ site = resolve (Site::class);
170+
171+ $ sites = $ site ->getSites ($ dirPath , collect ());
172+ $ this ->assertCount (1 , $ sites );
173+ $ this ->assertSame ([
174+ 'site ' => 'siteone ' ,
175+ 'secured ' => '' ,
176+ 'url ' => 'http://siteone.local ' ,
177+ 'path ' => $ linkedPath ,
178+ ], $ sites ->first ());
179+ }
180+
181+
53182 public function test_symlink_creates_symlink_to_given_path ()
54183 {
55184 $ files = Mockery::mock (Filesystem::class);
0 commit comments