| 
									
										
										
										
											2017-02-04 19:58:42 +08:00
										 |  |  | <?php namespace Tests; | 
					
						
							| 
									
										
										
										
											2016-03-30 03:13:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 03:35:40 +08:00
										 |  |  | class MarkdownTest extends BrowserKitTest | 
					
						
							| 
									
										
										
										
											2016-03-30 03:13:23 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     protected $page; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function setUp() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::setUp(); | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  |         $this->page = \BookStack\Entities\Page::first(); | 
					
						
							| 
									
										
										
										
											2016-03-30 03:13:23 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function setMarkdownEditor() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->setSettings(['app-editor' => 'markdown']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_default_editor_is_wysiwyg() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->assertEquals(setting('app-editor'), 'wysiwyg'); | 
					
						
							|  |  |  |         $this->asAdmin()->visit($this->page->getUrl() . '/edit') | 
					
						
							|  |  |  |             ->pageHasElement('#html-editor'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     public function test_markdown_setting_shows_markdown_editor() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->setMarkdownEditor(); | 
					
						
							|  |  |  |         $this->asAdmin()->visit($this->page->getUrl() . '/edit') | 
					
						
							|  |  |  |             ->pageNotHasElement('#html-editor') | 
					
						
							|  |  |  |             ->pageHasElement('#markdown-editor'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_markdown_content_given_to_editor() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->setMarkdownEditor(); | 
					
						
							|  |  |  |         $mdContent = '# hello. This is a test'; | 
					
						
							|  |  |  |         $this->page->markdown = $mdContent; | 
					
						
							|  |  |  |         $this->page->save(); | 
					
						
							|  |  |  |         $this->asAdmin()->visit($this->page->getUrl() . '/edit') | 
					
						
							|  |  |  |             ->seeInField('markdown', $mdContent); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_html_content_given_to_editor_if_no_markdown() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->setMarkdownEditor(); | 
					
						
							|  |  |  |         $this->asAdmin()->visit($this->page->getUrl() . '/edit') | 
					
						
							|  |  |  |             ->seeInField('markdown', $this->page->html); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |