Beispiel #1
0
 public function testIndexAction()
 {
     $currencyListObj = new CurrencyList();
     $currencyListObj->setSourceDir(__DIR__ . '/../../Resources/public/')->loadSource('data.xml')->loadSource('data.php')->loadSource('data.json');
     // Test load data
     $this->assertContainsOnlyInstancesOf('EskyBundle\\Model\\Currency', $currencyListObj->getCurrencyCollection());
     //Clone object for next tests
     $tmpCurrencyCollection = clone $currencyListObj->getCurrencyCollection();
     //Test xml filter
     $request = new Request(array('filterSource' => 'xml'));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     $this->assertNotEmpty($currencyListObj->getCurrencyCollection());
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals('xml', $currency->getSource());
     }
     //Test php filter
     $request = new Request(array('filterSource' => 'php'));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals('php', $currency->getSource());
     }
     //Test php filter
     $request = new Request(array('filterSource' => 'json'));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals('json', $currency->getSource());
     }
     //Test europe filter
     $request = new Request(array('filterType' => 'europe'));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals('europe', $currency->getType());
     }
     //Test europe filter
     $request = new Request(array('filterType' => 'europe'));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals('europe', $currency->getType());
     }
     //Test world filter
     $request = new Request(array('filterType' => 'world'));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals('world', $currency->getType());
     }
     //Test price filter
     $price = '1';
     $request = new Request(array('filterField' => 'price', 'filterCompare' => 'ilike', 'filterValue' => $price));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals($price, $currency->getPrice());
     }
     //Test name filter
     $name = 'zloty polski';
     $request = new Request(array('filterField' => 'name', 'filterCompare' => 'ilike', 'filterValue' => $name));
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals($name, $currency->getName());
     }
     //Test code filter
     $code = 'PLN';
     $currencyListObj->setCurrencyCollection(clone $tmpCurrencyCollection);
     $currencyListObj->filterData($request);
     foreach ($currencyListObj->getCurrencyCollection() as $currency) {
         $this->assertEquals($code, $currency->getCode());
     }
 }