我正在为Magento模块编写一些测试,使用Ivan Chepurnyi的扩展,我在使用模拟对象时遇到了麻烦.
这是班级:
<?php
class Namespace_Module_Block_Class extends Mage_Core_Block_Template
{
private $_salesCollection;
public function __construct()
{
$this->_salesCollection = Mage::getModel('module/classA')->getCollection()
->addFieldToFilter('id', $this->_getId());
}
public function _getId()
{
return Mage::getModel('module/classB')->getId();//session params
}
public function getSalesTotalNumber()
{
return $this->_salesCollection->count();
}
}
Run Code Online (Sandbox Code Playgroud)
我试图测试的方法是getSalesTotalNumber().
以下是测试:
<?php
class Namespace_Module_Test_Block_Class extends EcomDev_PHPUnit_Test_Case
{
private $_mock;
public function setUp()
{
$this->_mock = $this->getMock('Namespace_Module_Block_Class',
array('_getId')
);
$this->_mock->expects($this->any())
->method('_getId')
->will($this->returnValue(1024));
parent::setUp();
}
/**
* @test
* @loadFixture
* @loadExpectation
*/
public function testSalesTotalNumber()
{
$actual = $this->_mock->getSalesTotalValue(); …
Run Code Online (Sandbox Code Playgroud) 在我的数据库中,我有一个"销售"表和一个"sales_item".有时,出现问题并且销售被记录但不是销售项目.
所以我试图从我的表"sales"中获取sales_item表中没有任何行的salesID.
这是我认为可以工作的mysql查询,但它没有:
SELECT s.*
FROM sales s NATURAL JOIN sales_item si
WHERE s.date like '" . ((isset($_GET['date'])) ? $_GET['date'] : date("Y-m-d")) . "%'
AND s.sales_id like '" . ((isset($_GET['shop'])) ? $_GET['shop'] : substr($_COOKIE['shop'], 0, 3)) ."%'
HAVING count(si.sales_item_id) = 0;
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我是Magento的新手,我正在尝试为我构建的模块制作布局.我有一个简单的模块和一个输出'Hello World'的IndexController(我已经使用了本教程).
现在我想为该模块制作一个布局,我已经使用了本教程,但它不起作用.有人能指点我一个教程或者可以解释一下Magento中的布局是如何工作的吗?
谢谢 :)
这是我到目前为止所做的:我有一个名为'Andrei'的包和一个'Hello World'模块.
这是我的模块的config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Andrei_Helloworld>
<version>0.1.0</version>
</Andrei_Helloworld>
</modules>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>Andrei_Helloworld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
</frontend>
</config>
Run Code Online (Sandbox Code Playgroud)
这是Andrei_Helloworld模块:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Andrei_Helloworld>
<active>true</active>
<codePool>local</codePool>
</Andrei_Helloworld>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
class Andrei_Helloworld_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo 'Hello world';
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我到目前为止所做的一切.该模块正常工作.我想要一个我的IndexController的布局.谢谢 :)
我想+
在一个巨大的文件中出现所有图像名称之前添加一个(加号),使用sed
.
这是一行的示例:
DAUSSI-H22-14K White Gold-Princess-1.00ct-G-SI1orH-VS2-EGL-mm-3.5,,H22,,7050,5720,3/5/2012 7:34,,,1,,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5.html,Henri Daussi H22 Diamond Halo Engagement Ring-14K White Gold-Style:Princess-1.00ct-G-SI1 or H-VS2-EGL-Width: mm-Size:3.5,"Henri Daussi engagement ring with hand-matched side diamonds in a beautiful halo setting, totaling 1.40 carats. The image at left displays this ring with a 1.00 carat princess cut diamond. This setting can accommodate a variety of shapes and sizes. Please contact us on the range of possibilities of any ring.","Henri Daussi engagement ring with hand-matched side diamonds in a …
Run Code Online (Sandbox Code Playgroud) 我必须通过php中的cURL发送data-binary参数.
这是命令:curl -D - -u user:password -X PUT -H "Content-Type: text/plain" --data-binary "data-id=2010-10-01_15-15-53" https://someurl
.在控制台这工作,现在我必须在PHP中.
这是我的代码:
$this->_curl = curl_init();
curl_setopt($this->_curl, CURLOPT_USERPWD, $this->_loginUser . ":" . $this->_loginPassword);
curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->_curl, CURLOPT_HEADER, 1);
curl_setopt($this->_curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->_curl, CURLOPT_TIMEOUT, 30);
curl_setopt($this->_curl, CURLOPT_URL, $this->_serviceUrl);//https://someurl
curl_setopt($this->_curl, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
curl_setopt($this->_curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($this->_curl, CURLOPT_POSTFIELDS, array('data-id' => $dataId));//d'2010-10-01_15-15-53'
$response = curl_exec($this->_curl);
//$response = HTTP/1.1 201 Created
curl_close($this->_curl);
Run Code Online (Sandbox Code Playgroud)
该调用被服务器接受,但它无法识别data-id参数:
触发器2010-10-01_15-15-53中未定义data-id属性
知道我错过了什么吗?
我想在Magento系统配置中添加WYSIWYG编辑器.
并且还可以从中获取值来执行此操作.
干杯.
我正在为使用Zend Framework制作的当前项目编写测试.一切都很好,但我在测试已记录的用户操作/控制器时遇到问题:我需要登录才能执行操作/控制器.
如何登录PHPUnit?
我正在研究magento 1.3.2.3版的第一个模块.我创建了一个简单的表(不是EAV,只是一个主键和2列)和一些访问它的类,遵循Alan Storm的文章对我有很多帮助,但我无法弄清楚如何进行简单的选择:Alan解释了如何使用主键加载,但不选择与某个值匹配的行.
在正常的MySQL我写道:
SELECT *
FROM my_table
WHERE some_field = '" . $someValue . "'
Run Code Online (Sandbox Code Playgroud)
我找到了一个片段,它给了我想要的结果:
$resource = new Mage_Core_Model_Resource();
$read = $resource->getConnection('core_read');
$select = $read->select()
->from('my_table')
->where('some_field = ?', $someValue);
return $read->fetchAll($select);
Run Code Online (Sandbox Code Playgroud)
但是必须有一个更简单/更漂亮的解决方案,使用我创建的模型类.结果将是单行,而不是集合.
我已经尝试了我能想到的一切,比如:
return Mage::getModel('modulename/classname')->select()->where('some_field = ?', $comeValue);
return Mage::getModel('modulename/classname')->load()->where('some_field = ?', $comeValue);
return Mage::getModel('modulename/classname')->load(array('some_field = ?', $comeValue));
Run Code Online (Sandbox Code Playgroud)
还有更多的东西,但到目前为止没有运气:我错过了什么?
我正在开发自定义忠诚度积分模块.在结账时,客户可以选择兑换积分.
在模块设置中,我创建了一个redeem_points eav_attribute(它出现在eav_attribute表中),我已经将这个属性添加到了引用中,好吧,有点......
我是这样做的:
在Namespace_Module_Model_Resource_Eav_Mysql4_Setup(扩展Mage_Eav_Model_Entity_Setup)中,只有一个方法公共函数getDefaultEntities()只返回一个包含(除其他外)的数组:
'quote' => array(
'entity_model' => 'sales/quote',
'table' => 'sales/quote',
'attributes' => array(
'redeemed_points' => array('type' => 'static')
),
),
Run Code Online (Sandbox Code Playgroud)再次在mysql4-install-0.1.0.php中我在sales_flat_quote表中创建了这个列,就像这样
//add redeemed_points to quote table
$installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'redeemed_points', 'bigint(20)');
$installer->addAttribute('quote', 'redeemed_points', array('type'=>'static'));
Run Code Online (Sandbox Code Playgroud)在结帐时,当我兑换积分时,我的类中扩展Mage_Checkout_Model_Type_Onepage的方法savePoints($ data)被调用:
public function savePoints($data)
{
//save data
if ($data == 1) {
$redeemedPoints = Mage::helper('points')->getRedeemablePoints();
$this->getQuote()->setRedeemedPoints($redeemedPoints['points']);
} else {
$this->getQuote()->setRedeemedPoints(0);
}
$this->getQuote()->collectTotals()->save();
$this->getCheckout()
->setStepData('points', 'complete', true);
if ($this->getQuote()->isVirtual()) {
$this->getCheckout()->setStepData('payment', 'allow', true);
} else {
$this->getCheckout()->setStepData('shipping_method', 'allow', …
Run Code Online (Sandbox Code Playgroud) 我是PHP的新手; 今天我在Magento中看到了一些代码如下top.phtml
.
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<!--NEW HOME LINK -->
<li class="home"><a href="<?php echo $this->getUrl('') ?>"><?php echo $this->__('Home') ?></a>"</li>
<!--NEW HOME LINK -->
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Run Code Online (Sandbox Code Playgroud)
我知道$this
是自己的class
,它只在类中用来引用方法或属性,在上面的代码中,没有定义类,为什么它可以直接使用$ this关键字?什么$this->__('Home')
代表什么?
magento ×6
php ×4
mysql ×2
attributes ×1
binary-data ×1
curl ×1
layout ×1
logging ×1
magento-1.7 ×1
mocking ×1
oop ×1
phpunit ×1
quote ×1
regex ×1
sed ×1
substitution ×1
unit-testing ×1
wysiwyg ×1