Example #1
0
 public function testTargetCmsPageRedirect()
 {
     $page = Page::load(Theme::getActiveTheme(), 'adrenth-redirect-testpage');
     if ($page === null) {
         $page = new Page();
         $page->title = 'Testpage';
         $page->url = '/adrenth/redirect/testpage';
         $page->setFileNameAttribute('adrenth-redirect-testpage');
         $page->save();
     }
     $redirect = new Redirect(['match_type' => Redirect::TYPE_EXACT, 'target_type' => Redirect::TARGET_TYPE_CMS_PAGE, 'from_url' => '/this-should-be-source', 'cms_page' => 'adrenth-redirect-testpage', 'requirements' => null, 'status_code' => 302, 'from_date' => Carbon::now(), 'to_date' => Carbon::now()->addWeek()]);
     self::assertTrue($redirect->save());
     $rule = RedirectRule::createWithModel($redirect);
     self::assertInstanceOf(RedirectRule::class, $rule);
     $manager = RedirectManager::createWithRule($rule);
     self::assertInstanceOf(RedirectManager::class, $manager);
     $result = $manager->match('/this-should-be-source');
     self::assertInstanceOf(RedirectRule::class, $result);
     self::assertEquals('http://localhost/adrenth/redirect/testpage', $manager->getLocation($result));
     self::assertTrue($page->delete());
 }
Example #2
0
 /**
  * Creates a page using the contents of a specified file.
  * @param  string $filePath  File containing page contents
  * @param  string $name      New Page name
  * @param  string $settings  Page settings
  * @param  string $themeCode Theme to create the page
  * @return void
  */
 protected function createPageFromFile($filePath, $name, $settings, $themeCode)
 {
     if (!File::exists($filePath)) {
         return false;
     }
     $page = new Page($themeCode);
     $page->fill(['fileName' => $name, 'markup' => File::get($filePath), 'settings' => $settings]);
     $page->save();
     return true;
 }