public function testName()
 {
     $sw = new Movie('Star Wars', Movie::REGULAR);
     $this->assertEquals('Star Wars', $sw->getTitle());
 }
 public function testI18nWithRelations()
 {
     MovieQuery::create()->deleteAll();
     $count = MovieQuery::create()->count();
     $this->assertEquals(0, $count, 'No movie before the test');
     ToyQuery::create()->deleteAll();
     $count = ToyQuery::create()->count();
     $this->assertEquals(0, $count, 'No toy before the test');
     MovieI18nQuery::create()->deleteAll();
     $count = MovieI18nQuery::create()->count();
     $this->assertEquals(0, $count, 'No i18n movies before the test');
     $m = new Movie();
     $m->setLocale('en');
     $m->setTitle('V For Vendetta');
     $m->setLocale('fr');
     $m->setTitle('V Pour Vendetta');
     $m->setLocale('en');
     $this->assertEquals('V For Vendetta', $m->getTitle());
     $m->setLocale('fr');
     $this->assertEquals('V Pour Vendetta', $m->getTitle());
     $t = new Toy();
     $t->setMovie($m);
     $t->save();
     $count = MovieQuery::create()->count();
     $this->assertEquals(1, $count, '1 movie');
     $count = ToyQuery::create()->count();
     $this->assertEquals(1, $count, '1 toy');
     $count = MovieI18nQuery::create()->count();
     $this->assertEquals(2, $count, '2 i18n movies');
     $count = ToyI18nQuery::create()->count();
     $this->assertEquals(0, $count, '0 i18n toys');
 }
 public function duplicateMovie($id, $idUser)
 {
     $movie = null;
     $resultats = $this->bdd->prepare("SELECT * FROM movie WHERE mov_id=?;");
     $resultats->execute(array($id));
     $resultats->setFetchMode(PDO::FETCH_OBJ);
     while ($result = $resultats->fetch()) {
         $movie = new Movie($result->mov_id, $result->mov_user, $result->mov_title, $result->mov_description_short, $result->mov_description_long, $result->mov_director, $result->mov_year, $result->mov_image, $result->mov_cat);
     }
     $movie->setUser($idUser);
     $req2 = $this->bdd->prepare("INSERT INTO movie (mov_title, mov_user,mov_description_short, mov_description_long, mov_director, mov_year, mov_image, mov_cat) VALUES (:titre, :utilisateur, :resume, :synopsis, :realisateur, :annee, :affiche, :categorie)");
     $result2 = $req2->execute(array("titre" => htmlspecialchars($movie->getTitle()), "utilisateur" => htmlspecialchars($movie->getUser()), "resume" => htmlspecialchars($movie->getDescriptionShort()), "synopsis" => htmlspecialchars($movie->getDescriptionLong()), "realisateur" => htmlspecialchars($movie->getDirector()), "annee" => htmlspecialchars($movie->getYear()), "affiche" => htmlspecialchars($movie->getImage()), "categorie" => htmlspecialchars($movie->getCategory())));
     $movie->setId($this->bdd->lastInsertId());
     return $movie;
 }
<?php

require_once 'lib/Movie.php';
describe("Customer", function () {
    beforeEach(function () {
        $this->customer = new Customer('Mehdi');
    });
    describe("->getName()", function () {
        it("returns the movie name", function () {
            $sw = new Movie('Star Wars', Movie::REGULAR);
            expect($sw->getTitle())->toBe('Star Wars');
        });
    });
    describe("->getPriceCode()", function () {
        it("returns the `Movie::REGULAR` price for regular movies", function () {
            $sw = new Movie('Star Wars', Movie::REGULAR);
            expect($sw->getPriceCode())->toBe(Movie::REGULAR);
        });
        it("returns the `Movie::CHILDREN` price for children's movies", function () {
            $toystory = new Movie('Toy Story', Movie::CHILDREN);
            expect($toystory->getPriceCode())->toBe(Movie::CHILDREN);
        });
        it("returns the `Movie::NEW_RELEASE` price for newly released movies", function () {
            $skyfall = new Movie('Skyfall', Movie::NEW_RELEASE);
            expect($skyfall->getPriceCode())->toBe(Movie::NEW_RELEASE);
        });
        it("throws an `InvalidArgumentException` when using an invalid price code", function () {
            $closure = function () {
                $killbill = new Movie('Kill Bill', 999);
            };
            expect($closure)->toThrow(new InvalidArgumentException("Incorrect Price Code"));
示例#5
0
 /**
  * Gets movie tracks list to be played.
  * Used in /movie/showSuccess
  *
  * @param Movie $movie
  * @return Array $tracks_list
  */
 public static function getMovieTrackList($movie)
 {
     $item = array();
     $item['id'] = $movie->getId();
     $item['cover'] = str_replace("'", '&#39;', $movie->getCoverShow());
     $item['title'] = str_replace("'", '&#39;', $movie->getTitle());
     foreach ($movie['AudioTracks'] as $track) {
         $item2 = array();
         $item2['code'] = $track['code'];
         $item2['codec'] = $track['codec'];
         $item2['flag'] = $track['flag'];
         $item['audio_tracks'][] = $item2;
     }
     foreach ($movie['SubTracks'] as $track) {
         $item2 = array();
         $item2['label'] = $track['label'];
         $item2['code'] = $track['code'];
         $item2['flag'] = $track['flag'];
         $item['sub_tracks'][] = $item2;
     }
     $item['file_rel'] = $movie->getFileRel();
     $tracks_list[] = $item;
     return $tracks_list;
 }
 /**
  * @test
  */
 public function shouldBeAbleToInsertDefaultDataFromExternalFile()
 {
     // given
     $movie = new Movie();
     $movie->drop()->yesImSure();
     $movie->createTable();
     // When
     $m = new Movie(1);
     // then
     $this->assertEquals('Twelve angry men', $m->getTitle());
 }
示例#7
0
 public function updateMovie(Movie $movie)
 {
     $this->connect();
     // disable auto commit, so that we can roll back bridge table deletes if
     // the transaction fails in the second portion of the query
     mysqli_autocommit($this->link, FALSE);
     // first, we delete all records in the actor bridge table for the movie
     $sqlDelete = "DELETE FROM actor WHERE movie_id = " . $movie->getId();
     try {
         if (mysqli_query($this->link, $sqlDelete)) {
             // now that the bridge table is cleared out, update the movie
             $movieId = $movie->getId();
             $directorId = $movie->getDirector()->getId();
             $title = "'" . mysqli_real_escape_string($this->link, $movie->getTitle()) . "'";
             $releaseDate = "'" . $movie->getReleaseDate() . "'";
             $synopsis = "'" . mysqli_real_escape_string($this->link, $movie->getSynopsis()) . "'";
             $sqlUpdate = "UPDATE movie " . "SET director_id = {$directorId}, " . "title = {$title}, " . "release_date = {$releaseDate}, " . "submit_date = CURDATE(), " . "synopsis = {$synopsis} " . "WHERE id = {$movieId}";
             if (mysqli_query($this->link, $sqlUpdate)) {
                 // alright, movie table is updated, now to re-enter the new
                 // actor list into the bridge table.
                 $callback = function ($person) use($movieId) {
                     if ($person instanceof Person) {
                         $personId = $person->getId();
                         return "({$movieId}, {$personId})";
                     } else {
                         return "";
                     }
                 };
                 $bridgePairs = array_map($callback, $movie->getActors());
                 $values = implode(", ", $bridgePairs);
                 $bridgeSql = "INSERT INTO actor (movie_id, people_id) VALUES {$values}";
                 $result = mysqli_query($this->link, $bridgeSql);
                 if ($result) {
                     // ok, movie is update, and bridge table too
                     // now we can safely commit
                     mysqli_commit($this->link);
                     $this->disconnect();
                     return TRUE;
                 }
             } else {
                 // uh oh, something went wrong, roll back and abort!
                 mysqli_rollback($this->link);
                 $this->disconnect();
                 return FALSE;
             }
         } else {
             return FALSE;
         }
     } catch (Exception $e) {
         mysqli_rollback($this->link);
         $this->disconnect();
         return FALSE;
     }
 }