Пример #1
0
 /**
  * Build a collection manager with collections
  * loaded from config array.
  *
  * Config array structure:
  * .Array
  * (
  *   [collection_name_1] => Array
  *        (
  *            [attribute_1] => 'value'
  *        )
  *
  *   [collection_name_2] => Array
  *        (
  *        )
  * )
  *
  * @param array $config Configuration array with data about collections.
  *
  * @return \Yosymfony\Spress\Core\ContentManager\Collection\CollectionManager
  */
 public function buildFromConfigArray(array $config)
 {
     $cm = new CollectionManager();
     foreach ($config as $collectionName => $attributes) {
         $path = $collectionName;
         if (is_array($attributes) === false) {
             throw new \RuntimeException(sprintf('Expected array at the collection: "%s".', $collectionName));
         }
         $cm->addCollection(new Collection($collectionName, $path, $attributes));
     }
     return $cm;
 }
Пример #2
0
 /**
  * Crea un post;
  * Crea una collezione con il post nel contenuto;
  * Associa alla collezione un voto (lo crea);
  * Carica il voto dal database e lo confronta con quello salvato in memoria;
  */
 function testSaveVoteOnCollection()
 {
     require_once "post/PostManager.php";
     $data = $this->post_data_all;
     $p = PostManager::createPost($data);
     $data1 = $this->collection_data_all;
     $p2 = CollectionManager::addCollection($data1);
     $p1 = CollectionManager::voteCollection($this->author_id, $p2, $this->vote_value);
     if (count($p1->getVotes()) == 0) {
         return "<br />Vote saving test NOT PASSED: not added";
     }
     $votes = $p1->getVotes();
     $vote = PostManager::loadVote($votes[0]->getAuthor(), $votes[0]->getPost());
     $post = CollectionManager::loadCollection($p1->getId());
     if (count($post->getVotes()) == 0) {
         return "<br />Vote saving test NOT PASSED: not added";
     }
     //echo $votes[0] . "<br />" . $vote; //DEBUG
     //echo "<br />" . $p1 . "<br />" . $post; //DEBUG
     if ($vote === false) {
         return "<br />Vote saving test NOT PASSED: not created";
     }
     if ($votes[0]->getAuthor() != $vote->getAuthor()) {
         return "<br />Vote saving test NOT PASSED: author";
     }
     if ($votes[0]->getVote() != $vote->getVote()) {
         return "<br />Vote saving test NOT PASSED: comment";
     }
     if ($votes[0]->getPost() != $vote->getPost()) {
         return "<br />Vote saving test NOT PASSED: post";
     }
     if ($votes[0]->getCreationDate() != $vote->getCreationDate()) {
         return "<br />Vote saving test NOT PASSED: creationDate";
     }
     return "<br />Vote saving test passed";
 }