Skip to content

Commit

Permalink
Merge pull request #46 from jsirish/tests/psr2cleanup
Browse files Browse the repository at this point in the history
quick psr-2 cleanup
  • Loading branch information
jsirish committed Apr 12, 2016
2 parents 9a605bc + 862d4a5 commit f9b18ae
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 93 deletions.
53 changes: 26 additions & 27 deletions code/FlexSliderExtension.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<?php

class FlexSliderExtension extends Extension {
class FlexSliderExtension extends Extension
{
public function onAfterInit()
{

public function onAfterInit() {

// Flexslider options
$animate = ($this->owner->Animate) ? 'true' : 'false';
$loop = ($this->owner->Loop) ? 'true' : 'false';
$sync = ($this->owner->ThumbnailNav==true) ? "sync: '#carousel'," : "";
$before = (method_exists($this->owner->ClassName, 'flexSliderBeforeAction'))
? $this->owner->flexSliderBeforeAction()
: "function(){}";
$after = (method_exists($this->owner->ClassName, 'flexSliderAfterAction'))
? $this->owner->flexSliderAfterAction()
: "function(){}";
$speed = (method_exists($this->owner->ClassName, 'setFlexSliderSpeed'))
? $this->owner->setFlexSliderSpeed()
: 7000;
// Flexslider options
$animate = ($this->owner->Animate) ? 'true' : 'false';
$loop = ($this->owner->Loop) ? 'true' : 'false';
$sync = ($this->owner->ThumbnailNav == true) ? "sync: '#carousel'," : '';
$before = (method_exists($this->owner->ClassName, 'flexSliderBeforeAction'))
? $this->owner->flexSliderBeforeAction()
: 'function(){}';
$after = (method_exists($this->owner->ClassName, 'flexSliderAfterAction'))
? $this->owner->flexSliderAfterAction()
: 'function(){}';
$speed = (method_exists($this->owner->ClassName, 'setFlexSliderSpeed'))
? $this->owner->setFlexSliderSpeed()
: 7000;

// only call custom script if page has Slides and DataExtension
if (Object::has_extension($this->owner->data()->ClassName, 'FlexSlider')) {
if($this->owner->data()->Slides()->exists()){
if ($this->owner->data()->Slides()->exists()) {
Requirements::customScript("
(function($) {
$(document).ready(function(){
$('.flexslider').flexslider({
slideshow: " . $animate . ",
animation: '" . $this->owner->Animation . "',
animationLoop: " . $loop . ",
slideshow: ".$animate.",
animation: '".$this->owner->Animation."',
animationLoop: ".$loop.",
controlNav: true,
directionNav: true,
prevText: '',
Expand All @@ -38,15 +39,13 @@ public function onAfterInit() {
start: function(slider){
$('body').removeClass('loading');
},
before: ".$before.",
after: ".$after.",
slideshowSpeed: " . $speed . "
before: ".$before.',
after: '.$after.',
slideshowSpeed: '.$speed.'
});
});
}(jQuery));");
}(jQuery));');
}
}

}

}
}
37 changes: 20 additions & 17 deletions tests/FlexSliderTest.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<?php

class FlexSliderTest extends FunctionalTest{
class FlexSliderTest extends FunctionalTest
{
protected static $fixture_file = 'flexslider/tests/FlexSliderTest.yml';
protected static $disable_themes = true;
protected static $use_draft_site = false;

protected static $fixture_file = 'flexslider/tests/FlexSliderTest.yml';
protected static $disable_themes = true;
protected static $use_draft_site = false;
public function setUp()
{
parent::setUp();

public function setUp(){
parent::setUp();
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
}

ini_set('display_errors', 1);
ini_set("log_errors", 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
}

public function logOut(){
$this->session()->clear('loggedInAs');
$this->session()->clear('logInWithPermission');
}

public function testFlexSlider(){}
public function logOut()
{
$this->session()->clear('loggedInAs');
$this->session()->clear('logInWithPermission');
}

public function testFlexSlider()
{
}
}
94 changes: 45 additions & 49 deletions tests/SlideImageTest.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,64 @@
<?php

class SlideImageTest extends FlexSliderTest{
class SlideImageTest extends FlexSliderTest
{
protected static $use_draft_site = true;

protected static $use_draft_site = true;
public function setUp()
{
parent::setUp();
}

function setUp(){
parent::setUp();
}
public function testSlideImageCreation()
{
$this->logInWithPermission('Slide_CREATE');
$slide = $this->objFromFixture('SlideImage', 'slide1');

function testSlideImageCreation(){
$this->assertTrue($slide->canCreate());

$this->logInWithPermission('Slide_CREATE');
$slide = $this->objFromFixture('SlideImage', 'slide1');
$slideID = $slide->ID;

$this->assertTrue($slide->canCreate());
$this->assertTrue($slideID > 0);

$slideID = $slide->ID;
$getSlide = SlideImage::get()->byID($slideID);
$this->assertTrue($getSlide->ID == $slideID);
}

$this->assertTrue($slideID > 0);
public function testSlideUpdate()
{
$this->logInWithPermission('ADMIN');
$slide = $this->objFromFixture('SlideImage', 'slide1');
$slideID = $slide->ID;

$getSlide = SlideImage::get()->byID($slideID);
$this->assertTrue($getSlide->ID == $slideID);
$image = $this->objFromFixture('Image', 'image1');
$imageID = $image->ID;

}
$this->logOut();

function testSlideUpdate(){
$this->logInWithPermission('Slide_EDIT');

$this->logInWithPermission('ADMIN');
$slide = $this->objFromFixture('SlideImage', 'slide1');
$slideID = $slide->ID;
$this->assertTrue($slide->canEdit());
$slide = SlideImage::get()->byID($slideID);
$newTitle = 'Updated Name for Slide';
$slide->Name = $newTitle;
$slide->ImageID = $imageID;
$slide->write();

$image = $this->objFromFixture('Image', 'image1');
$imageID = $image->ID;
$slide = SlideImage::get()->byiD($slideID);

$this->logOut();
$this->assertTrue($slide->Name == $newTitle);
}

$this->logInWithPermission('Slide_EDIT');

$this->assertTrue($slide->canEdit());
$slide = SlideImage::get()->byID($slideID);
$newTitle = "Updated Name for Slide";
$slide->Name = $newTitle;
$slide->ImageID = $imageID;
$slide->write();

$slide = SlideImage::get()->byiD($slideID);

$this->assertTrue($slide->Name == $newTitle);

}

function testSlideImageDeletion(){

$this->logInWithPermission('Slide_DELETE');
$slide = $this->objFromFixture('SlideImage', 'slide2');
$slideID = $slide->ID;

$this->assertTrue($slide->canDelete());
$slide->delete();

$slides = SlideImage::get()->column('ID');
$this->assertFalse(in_array($slideID, $slides));

}
public function testSlideImageDeletion()
{
$this->logInWithPermission('Slide_DELETE');
$slide = $this->objFromFixture('SlideImage', 'slide2');
$slideID = $slide->ID;

$this->assertTrue($slide->canDelete());
$slide->delete();

$slides = SlideImage::get()->column('ID');
$this->assertFalse(in_array($slideID, $slides));
}
}

0 comments on commit f9b18ae

Please sign in to comment.